kookaburra 0.14.4 → 0.15.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.rspec +1 -0
  2. data/Gemfile +3 -2
  3. data/Gemfile.lock +49 -9
  4. data/LICENSE.txt +1 -1
  5. data/README.markdown +142 -188
  6. data/Rakefile +12 -16
  7. data/VERSION +1 -1
  8. data/kookaburra.gemspec +29 -22
  9. data/lib/kookaburra/api_driver.rb +8 -48
  10. data/lib/kookaburra/dependency_accessor.rb +24 -0
  11. data/lib/kookaburra/exceptions.rb +12 -0
  12. data/lib/kookaburra/given_driver.rb +55 -8
  13. data/lib/kookaburra/json_api_driver.rb +76 -0
  14. data/lib/kookaburra/rack_driver.rb +65 -0
  15. data/lib/kookaburra/test_data.rb +70 -46
  16. data/lib/kookaburra/test_helpers.rb +101 -0
  17. data/lib/kookaburra/ui_driver/ui_component.rb +173 -90
  18. data/lib/kookaburra/ui_driver.rb +69 -17
  19. data/lib/kookaburra.rb +70 -151
  20. data/spec/kookaburra/json_api_driver_spec.rb +34 -0
  21. data/spec/kookaburra/rack_driver_spec.rb +36 -0
  22. data/spec/kookaburra/test_data_spec.rb +31 -0
  23. data/spec/kookaburra/test_helpers_spec.rb +48 -0
  24. data/spec/kookaburra/ui_driver/ui_component_spec.rb +178 -0
  25. data/spec/kookaburra/ui_driver_spec.rb +27 -0
  26. data/spec/kookaburra_integration_spec.rb +312 -0
  27. data/spec/kookaburra_spec.rb +64 -0
  28. data/spec/support/shared_examples/it_has_a_dependency_accessor.rb +26 -0
  29. metadata +49 -30
  30. data/lib/kookaburra/assertion.rb +0 -32
  31. data/lib/kookaburra/ui_driver/mixins/has_browser.rb +0 -30
  32. data/lib/kookaburra/ui_driver/mixins/has_strategies.rb +0 -52
  33. data/lib/kookaburra/ui_driver/mixins/has_ui_component.rb +0 -45
  34. data/test/helper.rb +0 -30
  35. data/test/kookaburra/assertion_test.rb +0 -68
  36. data/test/kookaburra/test_data_test.rb +0 -28
  37. data/test/kookaburra/ui_driver/mixins/has_browser_test.rb +0 -38
  38. data/test/kookaburra/ui_driver/ui_component_test.rb +0 -101
  39. data/test/kookaburra/ui_driver_test.rb +0 -54
  40. data/test/kookaburra_test.rb +0 -188
@@ -1,45 +0,0 @@
1
- require 'active_support/core_ext/string/inflections'
2
- require 'active_support/core_ext/class/attribute'
3
-
4
- module Kookaburra
5
- class UIDriver
6
- module HasUIComponent
7
- UIComponentNotFound = Class.new(StandardError)
8
-
9
- module ClassMethods
10
- def ui_component(component_name)
11
- self.ui_component_names << component_name
12
-
13
- define_method(component_name) do
14
- options = { :browser => browser }
15
- # TODO: memoize the following line?
16
- component_class(component_name).new(options)
17
- end
18
- private component_name
19
-
20
- define_method("has_#{component_name}?") do
21
- send(component_name).visible?
22
- end
23
- end
24
- end
25
-
26
- module InstanceMethods
27
- def ui_components
28
- ui_component_names.map { |name| self.send(name) }
29
- end
30
-
31
- def component_class(component_name)
32
- self.class.const_get(component_name.to_s.camelize)
33
- end
34
- end
35
-
36
- def self.included(receiver)
37
- receiver.class_attribute :ui_component_names
38
- receiver.ui_component_names = []
39
-
40
- receiver.extend ClassMethods
41
- receiver.send :include, InstanceMethods
42
- end
43
- end
44
- end
45
- end
data/test/helper.rb DELETED
@@ -1,30 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'minitest/unit'
11
- require 'minitest/autorun'
12
-
13
- $LOAD_PATH.unshift(File.dirname(__FILE__))
14
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
- require 'kookaburra'
16
-
17
- class MiniTest::Unit::TestCase
18
- # TODO: make this better, so that there is only one failure message
19
- def assert_raises_with_message(expected_exception, expected_message, &block)
20
- begin
21
- yield
22
- flunk "Expected to raise a #{expected_exception}"
23
- rescue => e
24
- assert_kind_of expected_exception, e
25
- assert_match expected_message, e.message
26
- end
27
- end
28
- end
29
-
30
- MiniTest::Unit.autorun
@@ -1,68 +0,0 @@
1
- require 'helper'
2
-
3
- describe Kookaburra::Assertion do
4
- let(:api) { Class.new(Kookaburra::APIDriver).new({:app => nil}) }
5
- let(:given) { Class.new(Kookaburra::GivenDriver).new({:api_driver => api, :test_data => nil}) }
6
- let(:ui_component) { Class.new(Kookaburra::UIDriver::UIComponent).new(:test_data => nil) }
7
- let(:ui) { ui_class.new }
8
- let(:ui_class) do
9
- Class.new(Kookaburra::UIDriver) do
10
- def positive_assertion
11
- assert true
12
- end
13
-
14
- def negative_assertion
15
- assert false
16
- end
17
-
18
- def negative_assertion_with_message
19
- assert false, "Hello, world!"
20
- end
21
- end
22
- end
23
-
24
- it 'should be included in Kookaburra::APIDriver' do
25
- assert_kind_of Kookaburra::Assertion, api
26
- end
27
- it 'should be included in Kookaburra::GivenDriver' do
28
- assert_kind_of Kookaburra::Assertion, given
29
- end
30
- it 'should be included in Kookaburra::UIDriver' do
31
- assert_kind_of Kookaburra::Assertion, ui
32
- end
33
- it 'should be included in Kookaburra::UIDriver::UIComponent' do
34
- assert_kind_of Kookaburra::Assertion, ui_component
35
- end
36
-
37
- it 'should be able to make a positive assertion' do
38
- ui.positive_assertion
39
- end
40
-
41
- it 'should be able to make a negative assertion' do
42
- assert_raises(Kookaburra::Assertion::Failure) do
43
- ui.negative_assertion
44
- end
45
- end
46
-
47
- it 'should be able to make a negative assertion with a custom failure message' do
48
- begin
49
- ui.negative_assertion_with_message
50
- rescue Kookaburra::Assertion::Failure => e
51
- assert_equal 'Hello, world!', e.message
52
- end
53
- end
54
-
55
- describe Kookaburra::Assertion::Failure do
56
- let(:base_path) { File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. lib kookaburra])) }
57
-
58
- it 'removes lines including assertion.rb from the top of its backtrace' do
59
- begin
60
- ui.negative_assertion
61
- rescue Kookaburra::Assertion::Failure => e
62
- assert e.backtrace.none? { |line| line.include?('lib/kookaburra/assertion.rb') },
63
- '"assertion.rb" should be cleaned from backtrace'
64
- end
65
- end
66
- end
67
-
68
- end
@@ -1,28 +0,0 @@
1
- require 'helper'
2
-
3
- describe Kookaburra::TestData do
4
- describe '.set_default' do
5
- it 'stores data that can be used as defaults for tests' do
6
- Kookaburra::TestData.set_default(:foo, 'bar')
7
- td = Kookaburra::TestData.new
8
- assert_equal 'bar', Kookaburra::TestData.default(:foo)
9
- end
10
- end
11
-
12
- describe '#default' do
13
- it 'does not allow default to change between instances' do
14
- Kookaburra::TestData.set_default(:foo, 'bar' => 'baz')
15
- td1 = Kookaburra::TestData.new
16
- td1.default(:foo)['bar'] = 'spam'
17
- td2 = Kookaburra::TestData.new
18
- assert_equal 'baz', td2.default(:foo)['bar']
19
- end
20
-
21
- it 'raises an ArgumentError if the requested default has not been defined' do
22
- td = Kookaburra::TestData.new
23
- assert_raises ArgumentError do
24
- td.default(:foobar)
25
- end
26
- end
27
- end
28
- end
@@ -1,38 +0,0 @@
1
- require 'helper'
2
-
3
- describe Kookaburra::UIDriver::HasBrowser do
4
- describe '#no_500_error!' do
5
- let(:klass) do
6
- Class.new do
7
- include Kookaburra::UIDriver::HasBrowser
8
-
9
- def run_test
10
- no_500_error!
11
- end
12
- end
13
- end
14
-
15
- let(:browser) do
16
- b = MiniTest::Mock.new
17
- def b.body; 'Hello'; end
18
- b
19
- end
20
-
21
- let(:obj) { klass.new(:browser => browser) }
22
-
23
- it 'raises Unexpected500 if the page title is "Internal Server Error"' do
24
- browser.expect(:all, [:not_empty],
25
- [:css, 'head title', {:text => 'Internal Server Error'}])
26
-
27
- assert_raises Kookaburra::UIDriver::HasBrowser::Unexpected500 do
28
- obj.run_test
29
- end
30
- end
31
-
32
- it 'returns true if the page title is not "Internal Server Error"' do
33
- browser.expect(:all, [],
34
- [:css, 'head title', {:text => 'Internal Server Error'}])
35
- assert_equal true, obj.run_test
36
- end
37
- end
38
- end
@@ -1,101 +0,0 @@
1
- require 'helper'
2
- require 'minitest/mock'
3
-
4
- describe Kookaburra::UIDriver::UIComponent do
5
- it 'can have nested UIComponents' do
6
- InnerComponentA = Class.new(Kookaburra::UIDriver::UIComponent) do
7
- def visible?
8
- true
9
- end
10
- end
11
-
12
- InnerComponentB = Class.new(Kookaburra::UIDriver::UIComponent) do
13
- def visible?
14
- false
15
- end
16
- end
17
-
18
- OuterComponent = Class.new(Kookaburra::UIDriver::UIComponent) do
19
- ui_component :inner_component_a
20
- ui_component :inner_component_b
21
- end
22
-
23
- component = OuterComponent.new(:browser => Object.new)
24
- assert_equal true, component.has_inner_component_a?
25
- assert_equal false, component.has_inner_component_b?
26
- end
27
-
28
- let(:component_class) do
29
- Class.new(Kookaburra::UIDriver::UIComponent) do
30
- component_locator '#my_component'
31
- public :count
32
- end
33
- end
34
-
35
- describe '#count' do
36
- it 'returns the number of elements found within the component' do
37
- browser = Object.new.tap do |b|
38
- def b.within(*args)
39
- @context_set = true
40
- yield self
41
- end
42
-
43
- def b.all(*args)
44
- return unless @context_set
45
- Array.new(3)
46
- end
47
- end
48
- component = component_class.new(:browser => browser)
49
- assert_equal 3, component.count('.element')
50
- end
51
- end
52
-
53
- describe '#show' do
54
- let(:browser) { MiniTest::Mock.new }
55
- let(:component) do
56
- c = Kookaburra::UIDriver::UIComponent.new(:browser => browser)
57
- def c.no_500_error!; true; end
58
- c
59
- end
60
-
61
- it 'raises a NoMethodError if #component_path is not defined' do
62
- assert_raises_with_message(NoMethodError, /set component_path/) do
63
- component.show
64
- end
65
- end
66
-
67
- describe "when the component is not already visible" do
68
- before(:each) do
69
- def component.visible?; false; end
70
- end
71
-
72
- it 'visits the path returned by #component_path' do
73
- def component.component_path; '/my/path'; end
74
- browser.expect(:visit, nil, ['/my/path'])
75
- component.show
76
- end
77
-
78
- it 'passes any arguments through to #component_path' do
79
- def browser.visit(*args); nil; end
80
-
81
- def component.component_path(*args)
82
- unless args == %w[one two three]
83
- raise "Expected #component_path('one', 'two', 'three') but called with #{args.inspect}"
84
- end
85
- end
86
-
87
- component.show('one', 'two', 'three')
88
- end
89
- end
90
-
91
- describe "when the component is already visible" do
92
- it 'does not visit the component path' do
93
- def component.component_path; '/my/path'; end
94
- def component.visible?; true; end
95
-
96
- def browser.visit(*args); raise "Shouldn't get called"; end
97
- component.show
98
- end
99
- end
100
- end
101
- end
@@ -1,54 +0,0 @@
1
- require 'helper'
2
-
3
- describe Kookaburra::UIDriver do
4
- describe '#navigate_to' do
5
- it 'raises a UIComponentNotFound if the specified UIComponent is not registered' do
6
- ui = Kookaburra::UIDriver.new
7
- assert_raises Kookaburra::UIDriver::UIComponentNotFound do
8
- ui.navigate_to(:nonexistent_component)
9
- end
10
- end
11
-
12
- Foo = Class.new do
13
- @@last_instance = nil
14
-
15
- def self.was_shown
16
- @@last_instance.was_shown
17
- end
18
-
19
- def self.params
20
- @@last_instance.params
21
- end
22
-
23
- def initialize(options)
24
- @@last_instance = self
25
- end
26
-
27
- def show!(params = {})
28
- @was_shown = true
29
- @params = params
30
- end
31
- attr_reader :was_shown, :params
32
- end
33
-
34
- let(:ui) { ui_class.new }
35
- let(:ui_class) do
36
- Class.new(Kookaburra::UIDriver) do
37
- def browser; end
38
- def test_data; end
39
-
40
- ui_component :foo
41
- end
42
- end
43
-
44
- it 'delegates to the UIComponent#show! method' do
45
- ui.navigate_to :foo
46
- assert Foo.was_shown, "#show! was never called on the Foo component"
47
- end
48
-
49
- it 'passed any additional options to the UIComponent#show! method' do
50
- ui.navigate_to :foo, :bar => :baz
51
- assert_equal({:bar => :baz}, Foo.params)
52
- end
53
- end
54
- end
@@ -1,188 +0,0 @@
1
- require 'helper'
2
-
3
- describe Kookaburra do
4
- before(:each) do
5
- Kookaburra.api_driver = Kookaburra::APIDriver
6
- Kookaburra.given_driver = Kookaburra::GivenDriver
7
- Kookaburra.ui_driver = Kookaburra::UIDriver
8
- end
9
-
10
- describe 'as a mixin' do
11
- let(:mixer_class) do
12
- Class.new do
13
- include Kookaburra
14
- end
15
- end
16
-
17
- let(:mixer) do
18
- mixer_class.new.tap do |m|
19
- m.kookaburra_adapter = adapter
20
- end
21
- end
22
-
23
- let(:mixer2) do
24
- mixer_class.new.tap do |m|
25
- m.kookaburra_adapter = adapter
26
- end
27
- end
28
-
29
- let(:adapter) do
30
- capybara_like_thing = Class.new do
31
- def app
32
- :an_application
33
- end
34
-
35
- def current_session
36
- :a_current_session
37
- end
38
- end
39
-
40
- capybara_like_thing.new
41
- end
42
-
43
- describe '#kookaburra_adapter' do
44
- it 'is a read/write attribute' do
45
- mixer.kookaburra_adapter = :probably_Capybara
46
- assert_equal :probably_Capybara, mixer.kookaburra_adapter
47
- end
48
-
49
- it 'defaults to the value of Kookaburra.adapter' do
50
- begin
51
- old_adapter = Kookaburra.adapter rescue nil
52
- Kookaburra.adapter = :global_adapter
53
- mixer = mixer_class.new
54
- assert_equal :global_adapter, mixer.kookaburra_adapter
55
- ensure
56
- Kookaburra.adapter = old_adapter
57
- end
58
- end
59
- end
60
-
61
- describe '#api' do
62
- it 'is an instance of Kookaburra.api_driver' do
63
- klass = Class.new(Kookaburra::APIDriver)
64
- Kookaburra.api_driver = klass
65
- assert_kind_of(klass, mixer.api)
66
- end
67
-
68
- it 'only creates a new one once for an instance of the including class' do
69
- assert_same(mixer.api, mixer.api)
70
- end
71
-
72
- it 'is a different instance of APIDriver for each instance of the including class' do
73
- refute_same mixer.api, mixer2.api
74
- end
75
- end
76
-
77
- describe '#given' do
78
- it 'is an instance of Kookaburra.given_driver' do
79
- klass = Class.new(Kookaburra::GivenDriver)
80
- Kookaburra.given_driver = klass
81
- assert_kind_of(klass, mixer.given)
82
- end
83
-
84
- it 'only creates a new one once for an instance of the including class' do
85
- assert_same(mixer.given, mixer.given)
86
- end
87
-
88
- it 'is a different instance of GivenDriver for each instance of the including class' do
89
- refute_same mixer.given, mixer2.given
90
- end
91
- end
92
-
93
- describe '#ui' do
94
- it 'is an instance of Kookaburra.ui_driver' do
95
- klass = Class.new(Kookaburra::UIDriver)
96
- Kookaburra.ui_driver = klass
97
- assert_kind_of(klass, mixer.ui)
98
- end
99
-
100
- it 'only creates a new one once for an instance of the including class' do
101
- assert_same(mixer.ui, mixer.ui)
102
- end
103
-
104
- it 'is a different instance of UIDriver for each instance of the including class' do
105
- refute_same mixer.ui, mixer2.ui
106
- end
107
- end
108
-
109
- describe '#kookaburra_reset!' do
110
- it 'resets the api driver' do
111
- api = mixer.api
112
- mixer.kookaburra_reset!
113
- api2 = mixer.api
114
- refute_same api, api2
115
- end
116
-
117
- it 'resets the given driver' do
118
- given = mixer.given
119
- mixer.kookaburra_reset!
120
- given2 = mixer.given
121
- refute_same given, given2
122
- end
123
-
124
- it 'resets the ui driver' do
125
- ui = mixer.ui
126
- mixer.kookaburra_reset!
127
- ui2 = mixer.ui
128
- refute_same ui, ui2
129
- end
130
- end
131
- end
132
-
133
- describe 'methods on the Kookaburra object' do
134
- describe '#adapter' do
135
- it 'is a read/write attribute' do
136
- Kookaburra.adapter = :probably_Capybara
137
- assert_equal :probably_Capybara, Kookaburra.adapter
138
- end
139
-
140
- it 'raises an exception when it is read while nil' do
141
- assert_raises Kookaburra::ConfigurationError do
142
- Kookaburra.adapter = nil
143
- Kookaburra.adapter
144
- end
145
- end
146
- end
147
-
148
- describe '#api_driver' do
149
- it 'is a read/write attribute' do
150
- Kookaburra.api_driver = :an_api_driver
151
- assert_equal :an_api_driver, Kookaburra.api_driver
152
- end
153
-
154
- it 'raises an exception when it is read while nil' do
155
- assert_raises Kookaburra::ConfigurationError do
156
- Kookaburra.api_driver = nil
157
- Kookaburra.api_driver
158
- end
159
- end
160
- end
161
-
162
- describe '#given_driver' do
163
- it 'is a read/write attribute' do
164
- Kookaburra.given_driver = :a_given_driver
165
- assert_equal :a_given_driver, Kookaburra.given_driver
166
- end
167
- end
168
-
169
- describe '#ui_driver' do
170
- it 'is a read/write attribute' do
171
- Kookaburra.ui_driver = :a_ui_driver
172
- assert_equal :a_ui_driver, Kookaburra.ui_driver
173
- end
174
- end
175
-
176
- describe '.test_data_setup' do
177
- it 'evaluates the block in the context of the TestData class' do
178
- Kookaburra.test_data_setup do
179
- def added_by_a_test
180
- :added_by_a_test
181
- end
182
- end
183
- td = Kookaburra::TestData.new
184
- assert_equal :added_by_a_test, td.added_by_a_test
185
- end
186
- end
187
- end
188
- end