This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
forked from sambroad/jasmine-gem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication_spec.rb
49 lines (45 loc) · 1.73 KB
/
application_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'spec_helper'
describe 'Jasmine::Application' do
it 'should map paths provided by the config' do
handler1 = double(:handler1)
handler2 = double(:handler2)
app1 = double(:app1)
app2 = double(:app2)
rack_path_map = {'/foo' => lambda { handler1 }, '/bar' => lambda { handler2 }}
config = double(:config, :rack_path_map => rack_path_map, :rack_apps => [])
builder = double('Rack::Builder.new')
#Rack::Builder instance evals, so builder.run is invalid syntax,
#this is the only way to stub out the 'run' dsl it gives to the block.
Jasmine::Application.stub(:run).with(handler1).and_return(app1)
Jasmine::Application.stub(:run).with(handler2).and_return(app2)
builder.should_receive(:map).twice do |path, &app|
if path == '/foo'
app.call.should == app1
elsif path == '/bar'
app.call.should == app2
else
raise 'Unexpected path passed'
end
end
Jasmine::Application.app(config, builder).should == builder
end
it 'should run rack apps provided by the config' do
app1 = double(:app1)
app2 = double(:app2)
app3 = double(:app3)
app4 = double(:app4)
block = lambda { 'foo' }
config = double(:config, :rack_path_map => [], :rack_apps => [
{ :app => app1 },
{ :app => app2, :block => block },
{ :app => app3, :args => [:foo], :block => block },
{ :app => app4, :args => [:bar] }
])
builder = double('Rack::Builder.new')
builder.should_receive(:use).with(app1)
builder.should_receive(:use).with(app2, &block)
builder.should_receive(:use).with(app3, :foo, &block)
builder.should_receive(:use).with(app4, :bar)
Jasmine::Application.app(config, builder).should == builder
end
end