kookaburra 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.travis.yml +1 -3
- data/README.markdown +259 -181
- data/Rakefile +11 -2
- data/kookaburra.gemspec +1 -0
- data/lib/kookaburra.rb +24 -9
- data/lib/kookaburra/api_client.rb +1 -1
- data/lib/kookaburra/api_driver.rb +1 -1
- data/lib/kookaburra/assertion.rb +1 -1
- data/lib/kookaburra/configuration.rb +25 -9
- data/lib/kookaburra/configuration/proxy.rb +55 -0
- data/lib/kookaburra/dependency_accessor.rb +7 -0
- data/lib/kookaburra/exceptions.rb +11 -3
- data/lib/kookaburra/mental_model.rb +5 -5
- data/lib/kookaburra/rack_app_server.rb +3 -12
- data/lib/kookaburra/test_helpers.rb +53 -12
- data/lib/kookaburra/ui_driver/ui_component.rb +9 -2
- data/lib/kookaburra/version.rb +1 -1
- data/spec/integration/test_a_rack_application_spec.rb +3 -2
- data/spec/integration/test_multiple_applications_spec.rb +96 -0
- data/spec/kookaburra/api_client_spec.rb +6 -5
- data/spec/kookaburra/api_driver_spec.rb +18 -0
- data/spec/kookaburra/configuration/proxy_spec.rb +39 -0
- data/spec/kookaburra/configuration_spec.rb +54 -2
- data/spec/kookaburra/mental_model_spec.rb +22 -20
- data/spec/kookaburra/test_helpers_spec.rb +60 -24
- data/spec/kookaburra/ui_driver/scoped_browser_spec.rb +3 -2
- data/spec/kookaburra/ui_driver/ui_component/address_bar_spec.rb +2 -1
- data/spec/kookaburra/ui_driver/ui_component_spec.rb +48 -14
- data/spec/kookaburra/ui_driver_spec.rb +4 -3
- data/spec/kookaburra_spec.rb +19 -14
- data/spec/spec_helper.rb +79 -0
- data/spec/support/shared_examples/it_can_have_ui_components.rb +2 -2
- data/spec/support/shared_examples/it_can_make_assertions.rb +3 -3
- data/spec/support/shared_examples/it_has_a_dependency_accessor.rb +3 -4
- metadata +25 -2
data/lib/kookaburra/version.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require 'kookaburra/test_helpers'
|
2
3
|
require 'kookaburra/api_client'
|
3
4
|
require 'kookaburra/rack_app_server'
|
@@ -7,7 +8,7 @@ require 'uuid'
|
|
7
8
|
|
8
9
|
require 'support/json_api_app_and_kookaburra_drivers'
|
9
10
|
|
10
|
-
describe "testing a Rack application with Kookaburra" do
|
11
|
+
describe "testing a Rack application with Kookaburra", :slow do
|
11
12
|
include Kookaburra::TestHelpers
|
12
13
|
|
13
14
|
describe "with an HTML interface" do
|
@@ -40,7 +41,7 @@ describe "testing a Rack application with Kookaburra" do
|
|
40
41
|
api.create_widget(:widget_b, :name => 'Widget B')
|
41
42
|
end
|
42
43
|
|
43
|
-
define_method(:widgets) {
|
44
|
+
define_method(:widgets) { get_data(:widgets) }
|
44
45
|
|
45
46
|
it "runs the tests against the application's UI" do
|
46
47
|
ui.sign_in(:bob)
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kookaburra/test_helpers'
|
3
|
+
require 'kookaburra/rack_app_server'
|
4
|
+
require 'capybara'
|
5
|
+
require 'capybara/webkit'
|
6
|
+
require 'uuid'
|
7
|
+
|
8
|
+
require 'support/json_api_app_and_kookaburra_drivers'
|
9
|
+
|
10
|
+
describe 'testing multiple applications', :slow do
|
11
|
+
include Kookaburra::TestHelpers
|
12
|
+
|
13
|
+
OtherJsonApiApp = Class.new(JsonApiApp)
|
14
|
+
MyOtherUIDriver = Class.new(MyUIDriver)
|
15
|
+
MyOtherAPIDriver = Class.new(MyAPIDriver)
|
16
|
+
|
17
|
+
app_server_1 = Kookaburra::RackAppServer.new do
|
18
|
+
JsonApiApp.new
|
19
|
+
end
|
20
|
+
|
21
|
+
app_server_2 = Kookaburra::RackAppServer.new do
|
22
|
+
OtherJsonApiApp.new
|
23
|
+
end
|
24
|
+
|
25
|
+
before(:all) do
|
26
|
+
app_server_1.boot
|
27
|
+
app_server_2.boot
|
28
|
+
|
29
|
+
Kookaburra.configure do |c|
|
30
|
+
c.application(:app_1) do |a|
|
31
|
+
a.ui_driver_class = MyUIDriver
|
32
|
+
a.api_driver_class = MyAPIDriver
|
33
|
+
a.app_host = 'http://127.0.0.1:%d' % app_server_1.port
|
34
|
+
end
|
35
|
+
c.application(:app_2) do |a|
|
36
|
+
a.ui_driver_class = MyOtherUIDriver
|
37
|
+
a.api_driver_class = MyOtherAPIDriver
|
38
|
+
a.app_host = 'http://127.0.0.1:%d' % app_server_2.port
|
39
|
+
end
|
40
|
+
c.browser = Capybara::Session.new(:webkit)
|
41
|
+
c.server_error_detection do |browser|
|
42
|
+
browser.has_css?('head title', :text => 'Internal Server Error', :visible => false)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
after(:all) do
|
48
|
+
app_server_1.shutdown
|
49
|
+
app_server_2.shutdown
|
50
|
+
end
|
51
|
+
|
52
|
+
specify 'once you have defined multiple apps, the top-level #api and #ui methods raise errors' do
|
53
|
+
expect { api } .to raise_error( Kookaburra::AmbiguousDriverError )
|
54
|
+
expect { ui } .to raise_error( Kookaburra::AmbiguousDriverError )
|
55
|
+
end
|
56
|
+
|
57
|
+
context "with different data in each app" do
|
58
|
+
before(:each) do
|
59
|
+
app_1.api.create_user(:bob)
|
60
|
+
app_2.api.create_user(:sue)
|
61
|
+
app_1.api.create_widget(:widget_a)
|
62
|
+
app_2.api.create_widget(:widget_b)
|
63
|
+
end
|
64
|
+
|
65
|
+
let(:widgets) { get_data(:widgets) }
|
66
|
+
|
67
|
+
it 'can speak to both application APIs' do
|
68
|
+
expect(app_1.api.widgets).to include widgets[:widget_a]
|
69
|
+
expect(app_1.api.widgets).not_to include widgets[:widget_b]
|
70
|
+
|
71
|
+
expect(app_2.api.widgets).not_to include widgets[:widget_a]
|
72
|
+
expect(app_2.api.widgets).to include widgets[:widget_b]
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'can speak to both application UIs' do
|
76
|
+
app_1.ui.sign_in(:bob)
|
77
|
+
app_1.ui.view_widget_list
|
78
|
+
expect(app_1.ui.widget_list.widgets).to include widgets[:widget_a]
|
79
|
+
expect(app_1.ui.widget_list.widgets).to_not include widgets[:widget_b]
|
80
|
+
|
81
|
+
app_2.ui.sign_in(:sue)
|
82
|
+
app_2.ui.view_widget_list
|
83
|
+
expect(app_2.ui.widget_list.widgets).to_not include widgets[:widget_a]
|
84
|
+
expect(app_2.ui.widget_list.widgets).to include widgets[:widget_b]
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'shares a single browser session' do
|
88
|
+
app_1.ui.sign_in(:bob)
|
89
|
+
app_1.ui.view_widget_list
|
90
|
+
app_2.ui.sign_in(:sue)
|
91
|
+
expect(app_1.ui.widget_list).to be_not_visible
|
92
|
+
app_1.ui.view_widget_list
|
93
|
+
expect(app_1.ui.widget_list).to be_visible
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require 'kookaburra/api_client'
|
2
3
|
|
3
4
|
describe Kookaburra::APIClient do
|
@@ -16,7 +17,7 @@ describe Kookaburra::APIClient do
|
|
16
17
|
shared_examples_for 'any type of HTTP request' do |http_verb|
|
17
18
|
context "(#{http_verb})" do
|
18
19
|
before(:each) do
|
19
|
-
client.
|
20
|
+
allow(client).to receive(http_verb).and_return(response)
|
20
21
|
end
|
21
22
|
|
22
23
|
it 'returns the response body' do
|
@@ -24,8 +25,8 @@ describe Kookaburra::APIClient do
|
|
24
25
|
end
|
25
26
|
|
26
27
|
it 'raises an UnexpectedResponse if the request is not successful' do
|
27
|
-
response.
|
28
|
-
client.
|
28
|
+
allow(response).to receive(:code) { 500 }
|
29
|
+
allow(client).to receive(http_verb).and_raise(RestClient::Exception.new(response))
|
29
30
|
expect{ api.send(http_verb, '/foo') } \
|
30
31
|
.to raise_error(Kookaburra::UnexpectedResponse)
|
31
32
|
end
|
@@ -116,7 +117,7 @@ describe Kookaburra::APIClient do
|
|
116
117
|
shared_examples_for 'it encodes request data' do |http_verb|
|
117
118
|
context "(#{http_verb})" do
|
118
119
|
before(:each) do
|
119
|
-
client.
|
120
|
+
allow(client).to receive(http_verb) { response }
|
120
121
|
end
|
121
122
|
|
122
123
|
context 'when a custom encoder is specified' do
|
@@ -132,7 +133,7 @@ describe Kookaburra::APIClient do
|
|
132
133
|
|
133
134
|
it "encodes input to requests" do
|
134
135
|
expect(client).to receive(http_verb) do |_, data, _|
|
135
|
-
data.
|
136
|
+
expect(data).to eq :some_encoded_data
|
136
137
|
response
|
137
138
|
end
|
138
139
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kookaburra::APIDriver do
|
4
|
+
subject {
|
5
|
+
klass = Class.new(described_class) do
|
6
|
+
def do_something
|
7
|
+
api
|
8
|
+
end
|
9
|
+
end
|
10
|
+
klass.new(configuration)
|
11
|
+
}
|
12
|
+
|
13
|
+
let(:configuration) { double(:configuration) }
|
14
|
+
|
15
|
+
it 'requires subclasses to implement their #api method' do
|
16
|
+
expect{ subject.do_something }.to raise_error(Kookaburra::ConfigurationError)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kookaburra::Configuration::Proxy do
|
4
|
+
subject { described_class.new(name: :foobar, basis: basis) }
|
5
|
+
|
6
|
+
let(:basis) {
|
7
|
+
Kookaburra::Configuration.new.tap do |c|
|
8
|
+
c.ui_driver_class = default_ui_driver_class
|
9
|
+
end
|
10
|
+
}
|
11
|
+
|
12
|
+
let(:default_ui_driver_class) { double(:default_ui_driver_class) }
|
13
|
+
|
14
|
+
it 'it knows the name with which it was created' do
|
15
|
+
expect(subject.name).to eq :foobar
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'delegates to its basis by default' do
|
19
|
+
expect(subject.ui_driver_class).to equal default_ui_driver_class
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'does not delegate attributes that are set explicitly to a value' do
|
23
|
+
ui_driver_class_override = double(:ui_driver_class_override)
|
24
|
+
subject.ui_driver_class = ui_driver_class_override
|
25
|
+
expect(basis.ui_driver_class).to equal default_ui_driver_class
|
26
|
+
expect(subject.ui_driver_class).to equal ui_driver_class_override
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'does not delegate attributes that are set explicitly to nil' do
|
30
|
+
subject.ui_driver_class = nil
|
31
|
+
expect(basis.ui_driver_class).to equal default_ui_driver_class
|
32
|
+
expect(subject.ui_driver_class).to be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'responds only to methods to which its basis also responds' do
|
36
|
+
expect{ subject.not_a_defined_method }.to raise_error(NameError)
|
37
|
+
expect{ subject.not_a_defined_method = :something }.to raise_error(NameError)
|
38
|
+
end
|
39
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require 'kookaburra/configuration'
|
2
3
|
require 'support/shared_examples/it_has_a_dependency_accessor'
|
3
4
|
|
@@ -6,7 +7,6 @@ describe Kookaburra::Configuration do
|
|
6
7
|
it_behaves_like :it_has_a_dependency_accessor, :ui_driver_class
|
7
8
|
it_behaves_like :it_has_a_dependency_accessor, :browser
|
8
9
|
it_behaves_like :it_has_a_dependency_accessor, :app_host
|
9
|
-
it_behaves_like :it_has_a_dependency_accessor, :mental_model
|
10
10
|
it_behaves_like :it_has_a_dependency_accessor, :logger
|
11
11
|
|
12
12
|
describe '#server_error_detection' do
|
@@ -23,7 +23,7 @@ describe Kookaburra::Configuration do
|
|
23
23
|
.with('http://example.com') \
|
24
24
|
.and_return(:a_parsed_uri)
|
25
25
|
subject.app_host = 'http://example.com'
|
26
|
-
subject.app_host_uri.
|
26
|
+
expect(subject.app_host_uri).to eq :a_parsed_uri
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'changes if #app_host changes' do
|
@@ -36,4 +36,56 @@ describe Kookaburra::Configuration do
|
|
36
36
|
expect(subject.app_host_uri).to eq 'http://foo.example.com'.to_sym
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
40
|
+
describe '#mental_model' do
|
41
|
+
it 'returns an instance of MentalModel' do
|
42
|
+
expect(subject.mental_model).to be_kind_of Kookaburra::MentalModel
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'always returns the same instance' do
|
46
|
+
expect(subject.mental_model.__id__).to eq subject.mental_model.__id__
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#application' do
|
51
|
+
let(:proxy) { double(:proxy) }
|
52
|
+
let(:app_kookaburra) { double(:app_kookaburra) }
|
53
|
+
|
54
|
+
before(:each) do
|
55
|
+
allow(Kookaburra::Configuration::Proxy).to receive(:new) { proxy }
|
56
|
+
allow(Kookaburra).to receive(:new) { app_kookaburra }
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'builds a proxy configuration based on this one' do
|
60
|
+
expect(Kookaburra::Configuration::Proxy).to receive(:new) \
|
61
|
+
.with(name: :foo, basis: subject)
|
62
|
+
subject.application(:foo)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'yields the proxy configuration' do
|
66
|
+
expect{ |b| subject.application(:foo, &b) }.to yield_with_args(proxy)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'builds a new Kookaburra instance with the proxy configuration' do
|
70
|
+
expect(Kookaburra).to receive(:new).with(proxy)
|
71
|
+
subject.application(:foo)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'stores the new Kookaburra instance by name' do
|
75
|
+
expect(subject.applications.keys).to_not include(:foo)
|
76
|
+
subject.application(:foo)
|
77
|
+
expect(subject.applications[:foo]).to equal app_kookaburra
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#has_named_applications?' do
|
82
|
+
it 'is true when a named application is configured' do
|
83
|
+
subject.application(:foo)
|
84
|
+
expect(subject).to have_named_applications
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'is false when no named applications are configured' do
|
88
|
+
expect(subject).to_not have_named_applications
|
89
|
+
end
|
90
|
+
end
|
39
91
|
end
|
@@ -1,13 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require 'kookaburra/mental_model'
|
2
3
|
|
3
4
|
describe Kookaburra::MentalModel do
|
4
5
|
describe '#method_missing' do
|
5
6
|
it 'returns a Collection' do
|
6
|
-
subject.foo.
|
7
|
+
expect(subject.foo).to be_kind_of(Kookaburra::MentalModel::Collection)
|
7
8
|
end
|
8
9
|
|
9
10
|
it 'returns different Collections for different messages' do
|
10
|
-
subject.foo.
|
11
|
+
expect(subject.foo).to_not equal subject.bar
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
@@ -19,7 +20,7 @@ describe Kookaburra::MentalModel do
|
|
19
20
|
collection[:foo] = 'foo'
|
20
21
|
collection[:bar] = 'bar'
|
21
22
|
collection[:baz] = 'baz'
|
22
|
-
collection.values_at(:foo, :baz).
|
23
|
+
expect(collection.values_at(:foo, :baz)).to eq %w(foo baz)
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
@@ -28,7 +29,7 @@ describe Kookaburra::MentalModel do
|
|
28
29
|
collection[:foo] = 'foo'
|
29
30
|
collection[:bar] = 'bar'
|
30
31
|
collection[:baz] = 'baz'
|
31
|
-
collection.slice(:foo, :baz).
|
32
|
+
expect(collection.slice(:foo, :baz)).to eq({:foo => 'foo', :baz => 'baz'})
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
@@ -38,25 +39,25 @@ describe Kookaburra::MentalModel do
|
|
38
39
|
collection[:bar] = 'bar'
|
39
40
|
collection[:baz] = 'baz'
|
40
41
|
collection[:yak] = 'yak'
|
41
|
-
collection.except(:foo, :baz).
|
42
|
+
expect(collection.except(:foo, :baz)).to eq({:bar => 'bar', :yak => 'yak'})
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
45
46
|
describe '#delete' do
|
46
47
|
it 'deletes and returns the item matching the specified key' do
|
47
48
|
collection[:baz] = 'baz'
|
48
|
-
collection.delete(:baz).
|
49
|
-
|
49
|
+
expect(collection.delete(:baz)).to eq 'baz'
|
50
|
+
expect{ collection[:baz] }.to raise_error(Kookaburra::UnknownKeyError)
|
50
51
|
end
|
51
52
|
|
52
53
|
it 'persists the deleted key/value pair to the #deleted subcollection' do
|
53
54
|
collection[:baz] = 'baz'
|
54
55
|
collection.delete(:baz)
|
55
|
-
collection.deleted[:baz].
|
56
|
+
expect(collection.deleted[:baz]).to eq 'baz'
|
56
57
|
end
|
57
58
|
|
58
59
|
it 'raises a Kookaburra::UnknownKeyError exception if trying to delete a missing key' do
|
59
|
-
|
60
|
+
expect{ collection.delete(:snerf) }.to \
|
60
61
|
raise_error(Kookaburra::UnknownKeyError, "Can't find mental_model.widgets[:snerf]. Did you forget to set it?")
|
61
62
|
end
|
62
63
|
end
|
@@ -70,57 +71,58 @@ describe Kookaburra::MentalModel do
|
|
70
71
|
|
71
72
|
it 'deletes all members of collection for whom given block evaluates to false' do
|
72
73
|
collection.delete_if { |k,v| k.to_s != v }
|
73
|
-
collection.keys.
|
74
|
+
expect(collection.keys).to match_array [:foo, :baz]
|
74
75
|
end
|
75
76
|
|
76
77
|
it 'adds deleted members of collection to #deleted subcollection' do
|
77
78
|
collection.delete_if { |k,v| k.to_s != v }
|
78
|
-
collection.deleted.keys.
|
79
|
+
expect(collection.deleted.keys).to eq [:bar]
|
79
80
|
end
|
80
81
|
|
81
82
|
it 'returns hash of items not deleted' do
|
82
|
-
collection.delete_if { |k,v| k.to_s != v }.
|
83
|
+
expect(collection.delete_if { |k,v| k.to_s != v }).to \
|
84
|
+
eq({:foo => 'foo', :baz => 'baz'})
|
83
85
|
end
|
84
86
|
end
|
85
87
|
|
86
88
|
describe '#deleted' do
|
87
89
|
it 'generates a new subcollection if none exists' do
|
88
90
|
initialized_collection = collection
|
89
|
-
Kookaburra::MentalModel::Collection.
|
91
|
+
expect(Kookaburra::MentalModel::Collection).to receive(:new) \
|
90
92
|
.with("#{initialized_collection.name}.deleted")
|
91
93
|
initialized_collection.deleted
|
92
94
|
end
|
93
95
|
|
94
96
|
it 'returns the deleted subcollection if already initialized' do
|
95
97
|
deleted_collection = collection.deleted
|
96
|
-
collection.deleted.
|
98
|
+
expect(collection.deleted).to equal deleted_collection
|
97
99
|
end
|
98
100
|
end
|
99
101
|
|
100
102
|
it 'raises a Kookaburra::UnknownKeyError exception for #[] with a missing key' do
|
101
|
-
|
103
|
+
expect{ collection[:foo] }.to \
|
102
104
|
raise_error(Kookaburra::UnknownKeyError, "Can't find mental_model.widgets[:foo]. Did you forget to set it?")
|
103
105
|
end
|
104
106
|
|
105
107
|
describe '#dup' do
|
106
108
|
it 'returns a different object' do
|
107
109
|
new_collection = collection.dup
|
108
|
-
new_collection.
|
110
|
+
expect(new_collection).to_not equal collection
|
109
111
|
end
|
110
112
|
|
111
113
|
it 'returns an object with equal values to the original' do
|
112
114
|
collection[:foo] = :bar
|
113
115
|
collection[:baz] = :bam
|
114
116
|
new_collection = collection.dup
|
115
|
-
new_collection[:foo].
|
116
|
-
new_collection[:baz].
|
117
|
+
expect(new_collection[:foo]).to eq :bar
|
118
|
+
expect(new_collection[:baz]).to eq :bam
|
117
119
|
end
|
118
120
|
|
119
121
|
it 'is a deep copy' do
|
120
122
|
collection[:foo] = {:bar => 'baz'}
|
121
123
|
new_collection = collection.dup
|
122
|
-
new_collection[:foo][:bar].
|
123
|
-
new_collection[:foo][:bar].
|
124
|
+
expect(new_collection[:foo][:bar]).to eq 'baz'
|
125
|
+
expect(new_collection[:foo][:bar]).to_not equal collection[:foo][:bar]
|
124
126
|
end
|
125
127
|
|
126
128
|
context 'when there are deleted items present' do
|
@@ -1,42 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require 'kookaburra/test_helpers'
|
2
3
|
|
3
4
|
describe Kookaburra::TestHelpers do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Kookaburra.configure do |c|
|
8
|
-
c.api_driver_class = Kookaburra::APIDriver
|
9
|
-
c.ui_driver_class = Kookaburra::UIDriver
|
5
|
+
subject {
|
6
|
+
Object.new.tap do |o|
|
7
|
+
o.extend Kookaburra::TestHelpers
|
10
8
|
end
|
9
|
+
}
|
10
|
+
|
11
|
+
let(:k_kookaburra) {
|
12
|
+
double(:k_kookaburra, api: k_api, ui: k_ui, get_data: k_data)
|
13
|
+
}
|
14
|
+
let(:k_api) { double(:k_api) }
|
15
|
+
let(:k_ui) { double(:k_ui) }
|
16
|
+
let(:k_data) { double(:k_data) }
|
17
|
+
|
18
|
+
before(:each) do
|
19
|
+
allow(Kookaburra).to receive(:new) { k_kookaburra }
|
11
20
|
end
|
12
21
|
|
13
|
-
|
14
|
-
Kookaburra
|
15
|
-
|
16
|
-
c.ui_driver_class = nil
|
22
|
+
shared_examples_for 'it has no individual applications configured' do
|
23
|
+
it 'forwards #api to the main Kookaburra instance' do
|
24
|
+
expect(subject.api).to equal k_api
|
17
25
|
end
|
18
|
-
end
|
19
26
|
|
20
|
-
|
21
|
-
|
22
|
-
k.should be_kind_of(Kookaburra)
|
27
|
+
it 'forwards #ui to the main Kookaburra instance' do
|
28
|
+
expect(subject.ui).to equal k_ui
|
23
29
|
end
|
24
30
|
|
25
|
-
it
|
26
|
-
|
27
|
-
a.should equal(b)
|
31
|
+
it 'forwards #get_data to the main Kookaburra instance' do
|
32
|
+
expect(subject.get_data).to equal k_data
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
31
|
-
|
32
|
-
it
|
33
|
-
|
34
|
-
|
36
|
+
context "when no individual applications are configured" do
|
37
|
+
it_behaves_like 'it has no individual applications configured'
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when individual applications are configured" do
|
41
|
+
before(:each) do
|
42
|
+
Kookaburra.configure do |c|
|
43
|
+
c.application(:foo)
|
44
|
+
c.application(:bar)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
specify '#api raises an AmbiguousDriverError' do
|
49
|
+
expect{ subject.api }.to raise_error Kookaburra::AmbiguousDriverError
|
35
50
|
end
|
36
51
|
|
37
|
-
|
38
|
-
|
39
|
-
|
52
|
+
specify '#ui raises an AmbiguousDriverError' do
|
53
|
+
expect{ subject.api }.to raise_error Kookaburra::AmbiguousDriverError
|
54
|
+
end
|
55
|
+
|
56
|
+
specify '#get_data is forwarded to the main Kookaburra instance' do
|
57
|
+
expect(subject.get_data).to equal k_data
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'has a helper method for each configured application' do
|
61
|
+
expect(subject.foo).to equal Kookaburra.configuration.applications[:foo]
|
62
|
+
expect(subject.bar).to equal Kookaburra.configuration.applications[:bar]
|
63
|
+
end
|
64
|
+
|
65
|
+
context "and then Kookaburra is reconfigured" do
|
66
|
+
before(:each) do
|
67
|
+
Kookaburra.configure {}
|
68
|
+
end
|
69
|
+
|
70
|
+
it_behaves_like 'it has no individual applications configured'
|
71
|
+
|
72
|
+
it 'does not have helper methods for the previously configured applications' do
|
73
|
+
expect{ subject.foo }.to raise_error(NameError)
|
74
|
+
expect{ subject.bar }.to raise_error(NameError)
|
75
|
+
end
|
40
76
|
end
|
41
77
|
end
|
42
78
|
end
|