kookaburra 0.15.1 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/kookaburra.gemspec +1 -1
- data/lib/kookaburra/ui_driver/ui_component.rb +14 -34
- data/spec/kookaburra/ui_driver/ui_component_spec.rb +64 -80
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.16.0
|
data/kookaburra.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "kookaburra"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.16.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["John Wilger", "Sam Livingston-Gray"]
|
@@ -58,12 +58,9 @@ class Kookaburra
|
|
58
58
|
# end
|
59
59
|
#
|
60
60
|
# Note that the "browser operation" methods such as `#fill_in` and
|
61
|
-
# `#click_button` are forwarded to the {#
|
62
|
-
# {#method_missing}) and are
|
63
|
-
#
|
64
|
-
# scope by calling methods on {#browser} (e.g. `browser.click_on "Foo"`),
|
65
|
-
# this should be avoided, because you'll end up with a tangled mess of
|
66
|
-
# UIComponents without clear responsibilities.
|
61
|
+
# `#click_button` are forwarded to the {#browser} object (see
|
62
|
+
# {#method_missing}) and are automatically scoped to the component's DOM
|
63
|
+
# element.
|
67
64
|
#
|
68
65
|
# @abstract Subclass and implement (at least) {#component_locator}. Unless
|
69
66
|
# you override the default implementation of {#show}, you must also
|
@@ -85,14 +82,14 @@ class Kookaburra
|
|
85
82
|
end
|
86
83
|
|
87
84
|
# If the UIComponent is sent a message it does not understand, it will
|
88
|
-
# forward that message on to its {#
|
85
|
+
# forward that message on to its {#browser}. This provides convenient
|
89
86
|
# access to the browser driver's DSL, automatically scoped to this
|
90
87
|
# component.
|
91
|
-
#
|
92
|
-
# @raise [Kookaburra::ComponentNotFound] raised from {#element}
|
93
88
|
def method_missing(name, *args, &block)
|
94
|
-
if
|
95
|
-
|
89
|
+
if respond_to?(name)
|
90
|
+
browser.within(component_locator) do
|
91
|
+
browser.send(name, *args, &block)
|
92
|
+
end
|
96
93
|
else
|
97
94
|
super
|
98
95
|
end
|
@@ -101,7 +98,7 @@ class Kookaburra
|
|
101
98
|
# @private
|
102
99
|
# Behaves as you might expect given #method_missing
|
103
100
|
def respond_to?(name)
|
104
|
-
super ||
|
101
|
+
super || browser.respond_to?(name)
|
105
102
|
end
|
106
103
|
|
107
104
|
# Causes the UIComponent to be visible.
|
@@ -128,18 +125,17 @@ class Kookaburra
|
|
128
125
|
# Is the component's element found on the page and is it considered
|
129
126
|
# "visible" by the browser driver.
|
130
127
|
def visible?
|
131
|
-
|
132
|
-
|
133
|
-
|
128
|
+
visible = browser.has_css?(component_locator, :visible)
|
129
|
+
unless visible
|
130
|
+
detect_server_error!
|
131
|
+
end
|
132
|
+
visible
|
134
133
|
end
|
135
134
|
|
136
135
|
protected
|
137
136
|
|
138
137
|
# This is the browser driver with which the UIComponent was initialized.
|
139
138
|
#
|
140
|
-
# You almost certainly want to reference {#element} instead, as it is
|
141
|
-
# scoped to this component's DOM element, whereas #browser is not scoped.
|
142
|
-
#
|
143
139
|
# @attribute [r] browser
|
144
140
|
#
|
145
141
|
# @raise [RuntimeError] if no browser was specified in call to {#initialize}
|
@@ -183,22 +179,6 @@ class Kookaburra
|
|
183
179
|
raise UnexpectedResponse, "Your server error detection function detected a server error. Looks like your applications is busted. :-("
|
184
180
|
end
|
185
181
|
end
|
186
|
-
|
187
|
-
# Provides access to the element found by the browser driver at
|
188
|
-
# {#component_locator}. If your browser driver is a `Capybara::Session`,
|
189
|
-
# then this will be a `Capybara::Node::Element`.
|
190
|
-
#
|
191
|
-
# @raise [UnexpectedResponse] from {#detect_server_error!}
|
192
|
-
# @raise [ComponentNotFound] if the {#component_locator} is not found in
|
193
|
-
# the DOM
|
194
|
-
def element
|
195
|
-
detect_server_error!
|
196
|
-
begin
|
197
|
-
browser.find(component_locator)
|
198
|
-
rescue StandardError => e
|
199
|
-
raise ComponentNotFound, e.message
|
200
|
-
end
|
201
|
-
end
|
202
182
|
end
|
203
183
|
end
|
204
184
|
end
|
@@ -46,36 +46,82 @@ describe Kookaburra::UIDriver::UIComponent do
|
|
46
46
|
component.respond_to?(:foo).should == true
|
47
47
|
end
|
48
48
|
|
49
|
-
it 'returns true if the #
|
50
|
-
|
49
|
+
it 'returns true if the #browser defines the specified method' do
|
50
|
+
browser = stub('Browser Driver', :respond_to? => true)
|
51
51
|
component = component_class.new
|
52
|
-
component.stub!(:
|
52
|
+
component.stub!(:browser => browser)
|
53
53
|
component.respond_to?(:a_very_unlikely_method_name).should == true
|
54
54
|
end
|
55
55
|
|
56
|
-
it 'returns false if neither the UIComponent nor the #
|
57
|
-
|
56
|
+
it 'returns false if neither the UIComponent nor the #browser define the specified method' do
|
57
|
+
browser = stub('Browser Driver', :respond_to? => false)
|
58
58
|
component = component_class.new
|
59
|
-
component.stub!(:
|
59
|
+
component.stub!(:browser => browser)
|
60
60
|
component.respond_to?(:a_very_unlikely_method_name).should == false
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
describe '#method_missing' do
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
:
|
65
|
+
context 'the component says it responds to the method' do
|
66
|
+
it 'scopes the method call within the component_locator and forwards to #browser' do
|
67
|
+
browser = mock('Browser Driver')
|
68
|
+
browser.should_receive(:some_browser_method) \
|
69
|
+
.with(:arguments) \
|
70
|
+
.and_return(:answer_from_browser)
|
71
|
+
browser.should_receive(:within) do |scope, &block|
|
72
|
+
scope.should == '#my_component'
|
73
|
+
block.call(browser)
|
74
|
+
end
|
75
|
+
component = Kookaburra::UIDriver::UIComponent.new(:browser => browser)
|
76
|
+
component.stub!(:component_locator => '#my_component')
|
77
|
+
component.some_browser_method(:arguments).should == :answer_from_browser
|
72
78
|
end
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'the component says it does not respond to the method' do
|
82
|
+
it 'raises a NoMethodError' do
|
83
|
+
component = Kookaburra::UIDriver::UIComponent.new
|
84
|
+
component.stub!(:respond_to? => false)
|
85
|
+
lambda { component.no_such_method } \
|
86
|
+
.should raise_error(NoMethodError)
|
77
87
|
end
|
78
|
-
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#visible?' do
|
92
|
+
it 'returns true if the component_locator is found in the DOM and is visible' do
|
93
|
+
browser = mock('Browser Driver')
|
94
|
+
browser.should_receive(:has_css?) \
|
95
|
+
.with('#my_component', :visible) \
|
96
|
+
.and_return(true)
|
97
|
+
component = Kookaburra::UIDriver::UIComponent.new(:browser => browser)
|
98
|
+
component.stub!(:component_locator => '#my_component')
|
99
|
+
component.visible?.should == true
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'returns false if the component_locator id not found in the DOM' do
|
103
|
+
browser = stub('Browser Driver', :has_css? => false)
|
104
|
+
component = Kookaburra::UIDriver::UIComponent.new(
|
105
|
+
:browser => browser,
|
106
|
+
:server_error_detection => lambda { |browser|
|
107
|
+
false
|
108
|
+
}
|
109
|
+
)
|
110
|
+
component.stub!(:component_locator => '#my_component')
|
111
|
+
component.visible?.should == false
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'raises UnexpectedResponse if the component_locator is not found and a server error is detected' do
|
115
|
+
browser = stub('Browser Driver', :has_css? => false)
|
116
|
+
component = Kookaburra::UIDriver::UIComponent.new(
|
117
|
+
:browser => browser,
|
118
|
+
:server_error_detection => lambda { |browser|
|
119
|
+
true
|
120
|
+
}
|
121
|
+
)
|
122
|
+
component.stub!(:component_locator => '#my_component')
|
123
|
+
lambda { component.visible? } \
|
124
|
+
.should raise_error(Kookaburra::UnexpectedResponse)
|
79
125
|
end
|
80
126
|
end
|
81
127
|
|
@@ -112,67 +158,5 @@ describe Kookaburra::UIDriver::UIComponent do
|
|
112
158
|
it_behaves_like :it_has_a_dependency_accessor, :browser do
|
113
159
|
let(:subject_class) { Kookaburra::UIDriver::UIComponent }
|
114
160
|
end
|
115
|
-
|
116
|
-
describe '#element' do
|
117
|
-
it 'passes the browser object to the server error detection function' do
|
118
|
-
browser = stub('Browser', :find => :an_element)
|
119
|
-
server_error_detection = lambda { |b|
|
120
|
-
b.should === browser
|
121
|
-
false
|
122
|
-
}
|
123
|
-
component = Kookaburra::UIDriver::UIComponent.new(:browser => browser,
|
124
|
-
:server_error_detection => server_error_detection)
|
125
|
-
component.stub!(:component_locator => '#my_component')
|
126
|
-
component.send(:element)
|
127
|
-
end
|
128
|
-
|
129
|
-
shared_examples_for :server_error_detection_passed do
|
130
|
-
it 'returns the element node if the component_locator is found on the page' do
|
131
|
-
browser = mock('Browser')
|
132
|
-
browser.should_receive(:find).with('#my_component').and_return(:the_element_node)
|
133
|
-
component = Kookaburra::UIDriver::UIComponent.new(
|
134
|
-
:browser => browser,
|
135
|
-
:server_error_detection => server_error_detection)
|
136
|
-
component.stub!(:component_locator => '#my_component')
|
137
|
-
component.send(:element).should == :the_element_node
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'raises Kookaburra::ComponentNotFound if the component_locator is not found on the page' do
|
141
|
-
browser = mock('Browser')
|
142
|
-
browser.should_receive(:find).with('#my_component').and_raise(StandardError)
|
143
|
-
component = Kookaburra::UIDriver::UIComponent.new(
|
144
|
-
:browser => browser,
|
145
|
-
:server_error_detection => server_error_detection)
|
146
|
-
component.stub!(:component_locator => '#my_component')
|
147
|
-
lambda { component.send(:element) } \
|
148
|
-
.should raise_error(Kookaburra::ComponentNotFound)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context 'no server error detection function is specified' do
|
153
|
-
let(:server_error_detection) { nil }
|
154
|
-
it_behaves_like :server_error_detection_passed
|
155
|
-
end
|
156
|
-
|
157
|
-
context 'no server error is detected' do
|
158
|
-
let(:server_error_detection) do
|
159
|
-
lambda { |b| false }
|
160
|
-
end
|
161
|
-
|
162
|
-
it_behaves_like :server_error_detection_passed
|
163
|
-
end
|
164
|
-
|
165
|
-
context 'a server error is detected' do
|
166
|
-
it 'raises a Kookaburra::UnexpectedResponse exception' do
|
167
|
-
server_error_detection = lambda { |b| true }
|
168
|
-
browser = stub('Browser')
|
169
|
-
component = Kookaburra::UIDriver::UIComponent.new(
|
170
|
-
:browser => browser,
|
171
|
-
:server_error_detection => server_error_detection)
|
172
|
-
lambda { component.send(:element) } \
|
173
|
-
.should raise_error(Kookaburra::UnexpectedResponse, "Your server error detection function detected a server error. Looks like your applications is busted. :-(")
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
161
|
end
|
178
162
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kookaburra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 95
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 16
|
9
|
+
- 0
|
10
|
+
version: 0.16.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Wilger
|