polonium 0.1.1 → 0.2.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.
Files changed (38) hide show
  1. data/CHANGES +7 -0
  2. data/README +27 -12
  3. data/Rakefile +2 -2
  4. data/init.rb +9 -0
  5. data/lib/polonium/adapters/rspec.rb +19 -13
  6. data/lib/polonium/adapters/test_unit.rb +1 -1
  7. data/lib/polonium/configuration.rb +32 -97
  8. data/lib/polonium/driver.rb +25 -28
  9. data/lib/polonium/dsl/selenium_dsl.rb +67 -8
  10. data/lib/polonium/element.rb +60 -30
  11. data/lib/polonium/page.rb +13 -2
  12. data/lib/polonium/server_runners/external_server_runner.rb +20 -0
  13. data/lib/polonium/server_runners/mongrel_server_runner.rb +63 -0
  14. data/lib/polonium/server_runners/server_runner.rb +36 -0
  15. data/lib/polonium/server_runners/webrick_server_runner.rb +49 -0
  16. data/lib/polonium/test_case.rb +1 -19
  17. data/lib/polonium/wait_for.rb +4 -1
  18. data/lib/polonium.rb +6 -4
  19. data/spec/polonium/configuration_spec.rb +41 -99
  20. data/spec/polonium/driver_spec.rb +112 -62
  21. data/spec/polonium/element_spec.rb +69 -24
  22. data/spec/polonium/server_runners/external_server_runner_spec.rb +33 -0
  23. data/spec/polonium/server_runners/mongrel_server_runner_spec.rb +69 -0
  24. data/spec/polonium/server_runners/server_runner_spec.rb +36 -0
  25. data/spec/polonium/server_runners/webrick_server_runner_spec.rb +121 -0
  26. data/spec/polonium/test_case_spec.rb +538 -649
  27. data/spec/rspec/options_spec.rb +23 -22
  28. data/spec/spec_helper.rb +0 -18
  29. data/spec/spec_suite.rb +1 -1
  30. data/spec/test_unit/testrunnermediator_spec.rb +2 -2
  31. metadata +50 -41
  32. data/lib/polonium/dsl/test_unit_dsl.rb +0 -61
  33. data/lib/polonium/mongrel_selenium_server_runner.rb +0 -37
  34. data/lib/polonium/server_runner.rb +0 -33
  35. data/lib/polonium/webrick_selenium_server_runner.rb +0 -33
  36. data/spec/polonium/mongrel_selenium_server_runner_spec.rb +0 -35
  37. data/spec/polonium/server_runner_spec.rb +0 -42
  38. data/spec/polonium/webrick_selenium_server_runner_spec.rb +0 -117
@@ -1,12 +1,13 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  module Polonium
4
- describe TestCase, :shared => true do
4
+ describe TestCase do
5
5
  it_should_behave_like "Selenium"
6
6
  include TestCaseSpecHelper
7
7
  attr_reader :driver, :test_case, :configuration
8
8
 
9
9
  before(:each) do
10
+ @original_configuration = Configuration.instance
10
11
  stub_selenium_configuration
11
12
  @test_case = TestCaseSpecHelper::MySeleniumTestCase.new
12
13
  @driver = ::Polonium::Driver.new('http://test.host', 4000, "*firefox", 'http://test.host')
@@ -16,6 +17,10 @@ module Polonium
16
17
  end
17
18
  end
18
19
 
20
+ after(:each) do
21
+ Configuration.instance = @original_configuration
22
+ end
23
+
19
24
  def sample_locator
20
25
  "sample_locator"
21
26
  end
@@ -30,850 +35,734 @@ module Polonium
30
35
  configuration.external_app_server_port = 80
31
36
 
32
37
  stub(Configuration.instance) {configuration}
33
- end
34
- end
35
-
36
- describe TestCase, "#setup" do
37
- it_should_behave_like "Polonium::TestCase"
38
-
39
- it "should not allow transactional fixtures" do
40
- test_case.class.use_transactional_fixtures = true
41
-
42
- expected_message = "Cannot use transactional fixtures if ActiveRecord concurrency is turned on (which is required for Selenium tests to work)."
43
- proc do
44
- test_case.setup
45
- end.should raise_error(RuntimeError, expected_message)
46
- end
47
- end
38
+ end
48
39
 
49
- describe TestCase, "#wait_for" do
50
- it_should_behave_like "Polonium::TestCase"
40
+ describe "#setup" do
41
+ it "should not allow transactional fixtures" do
42
+ test_case.class.use_transactional_fixtures = true
51
43
 
52
- it "should pass when the block returns true within time limit" do
53
- test_case.wait_for(:timeout => 2) do
54
- true
44
+ expected_message = "Cannot use transactional fixtures if ActiveRecord concurrency is turned on (which is required for Selenium tests to work)."
45
+ proc do
46
+ test_case.setup
47
+ end.should raise_error(RuntimeError, expected_message)
55
48
  end
56
49
  end
57
50
 
58
- it "should raise a AssertionFailedError when block times out" do
59
- proc do
60
- test_case.wait_for(:timeout => 2) {false}
61
- end.should raise_error(Test::Unit::AssertionFailedError, "Timeout exceeded (after 2 sec)")
62
- end
63
- end
51
+ describe "#wait_for" do
52
+ describe "when the block returns true within time limit" do
53
+ it "does not raise an error" do
54
+ test_case.wait_for(:timeout => 2) do
55
+ true
56
+ end
57
+ end
64
58
 
65
- describe TestCase, "#default_timeout" do
66
- it_should_behave_like "Polonium::TestCase"
59
+ it "returns the value of the evaluated block" do
60
+ test_case.wait_for(:timeout => 2) do
61
+ 99
62
+ end.should == 99
63
+ end
64
+ end
67
65
 
68
- it "default_timeout should be 20 seconds" do
69
- test_case.default_timeout.should == 20000
66
+ describe "when block times out" do
67
+ it "raises a AssertionFailedError" do
68
+ proc do
69
+ test_case.wait_for(:timeout => 2) {false}
70
+ end.should raise_error(Test::Unit::AssertionFailedError, "Timeout exceeded (after 2 sec)")
71
+ end
72
+ end
70
73
  end
71
- end
72
74
 
73
- describe TestCase, "#open_home_page" do
74
- it_should_behave_like "Polonium::TestCase"
75
-
76
- it "opens home page" do
77
- mock(driver).open("http://localhost:4000")
78
- test_case.open_home_page
75
+ describe "#default_timeout" do
76
+ it "default_timeout should be 20 seconds" do
77
+ test_case.default_timeout.should == 20000
78
+ end
79
79
  end
80
- end
81
80
 
82
- describe TestCase, "#assert_title" do
83
- it_should_behave_like "Polonium::TestCase"
84
-
85
- it "when title is expected, passes" do
86
- mock(driver).do_command("getTitle", []) {result("my page")}
87
- test_case.assert_title("my page")
81
+ describe "#open_home_page" do
82
+ it "opens home page" do
83
+ mock(driver).open("http://localhost:4000")
84
+ test_case.open_home_page
85
+ end
88
86
  end
89
87
 
90
- it "when title is not expected, fails" do
91
- stub(driver).do_command("getTitle", []) {result("no page")}
92
- proc do
88
+ describe "#assert_title" do
89
+ it "when title is expected, passes" do
90
+ mock(driver).do_command("getTitle", []) {result("my page")}
93
91
  test_case.assert_title("my page")
94
- end.should raise_error(Test::Unit::AssertionFailedError)
95
- end
96
- end
97
-
98
- describe TestCase, "#assert_text_present" do
99
- it_should_behave_like "Polonium::TestCase"
92
+ end
100
93
 
101
- before do
102
- mock.proxy(Page).new(driver) do |page|
103
- mock.proxy(page).assert_text_present("my page", {})
104
- page
94
+ it "when title is not expected, fails" do
95
+ stub(driver).do_command("getTitle", []) {result("no page")}
96
+ proc do
97
+ test_case.assert_title("my page")
98
+ end.should raise_error(Test::Unit::AssertionFailedError)
105
99
  end
106
100
  end
107
101
 
108
- it "passes when text is in page" do
109
- ticks = [false, false, false, true]
110
- mock(driver).is_text_present("my page") do
111
- ticks.shift
112
- end.times(4)
113
- test_case.assert_text_present("my page")
114
- end
102
+ describe "#assert_text_present" do
103
+ before do
104
+ mock.proxy(Page).new(driver) do |page|
105
+ mock.proxy(page).assert_text_present("my page", {})
106
+ page
107
+ end
108
+ end
115
109
 
116
- it "fails when text is not in page" do
117
- stub(driver).is_text_present("my page") {false}
118
- proc do
110
+ it "passes when text is in page" do
111
+ ticks = [false, false, false, true]
112
+ mock(driver).is_text_present("my page") do
113
+ ticks.shift
114
+ end.times(4)
119
115
  test_case.assert_text_present("my page")
120
- end.should raise_error(Test::Unit::AssertionFailedError)
121
- end
122
- end
123
-
124
- describe TestCase, "#assert_text_not_present" do
125
- it_should_behave_like "Polonium::TestCase"
116
+ end
126
117
 
127
- before do
128
- mock.proxy(Page).new(driver) do |page|
129
- mock.proxy(page).assert_text_not_present("my page", {})
130
- page
118
+ it "fails when text is not in page" do
119
+ stub(driver).is_text_present("my page") {false}
120
+ proc do
121
+ test_case.assert_text_present("my page")
122
+ end.should raise_error(Test::Unit::AssertionFailedError)
131
123
  end
132
124
  end
133
125
 
134
- it "passes when text is not in page" do
135
- ticks = [true, true, true, false]
136
- mock(driver).is_text_present("my page") do
137
- ticks.shift
138
- end.times(4)
139
- test_case.assert_text_not_present("my page")
140
- end
126
+ describe "#assert_text_not_present" do
127
+ before do
128
+ mock.proxy(Page).new(driver) do |page|
129
+ mock.proxy(page).assert_text_not_present("my page", {})
130
+ page
131
+ end
132
+ end
141
133
 
142
- it "fails when text is in page" do
143
- stub(driver).is_text_present("my page") {true}
144
- proc do
134
+ it "passes when text is not in page" do
135
+ ticks = [true, true, true, false]
136
+ mock(driver).is_text_present("my page") do
137
+ ticks.shift
138
+ end.times(4)
145
139
  test_case.assert_text_not_present("my page")
146
- end.should raise_error(Test::Unit::AssertionFailedError)
147
- end
148
- end
149
-
150
- describe TestCase, "#assert_location_ends_with" do
151
- it_should_behave_like "Polonium::TestCase"
140
+ end
152
141
 
153
- before do
154
- @ends_with = "foobar.com?arg1=2"
155
- mock.proxy(Page).new(driver) do |page|
156
- mock.proxy(page).assert_location_ends_with(@ends_with, {})
157
- page
142
+ it "fails when text is in page" do
143
+ stub(driver).is_text_present("my page") {true}
144
+ proc do
145
+ test_case.assert_text_not_present("my page")
146
+ end.should raise_error(Test::Unit::AssertionFailedError)
158
147
  end
159
148
  end
160
149
 
161
- it "passes when the url ends with the passed in value" do
162
- ticks = [
163
- "http://no.com",
164
- "http://no.com",
165
- "http://no.com",
166
- "http://foobar.com?arg1=2"
167
- ]
168
- mock(driver).get_location do
169
- ticks.shift
170
- end.times(4)
171
- test_case.assert_location_ends_with(@ends_with)
172
- end
150
+ describe "#assert_location_ends_with" do
151
+ before do
152
+ @ends_with = "foobar.com?arg1=2"
153
+ mock.proxy(Page).new(driver) do |page|
154
+ mock.proxy(page).assert_location_ends_with(@ends_with, {})
155
+ page
156
+ end
157
+ end
173
158
 
174
- it "fails when the url does not end with the passed in value" do
175
- stub(driver).get_location {"http://no.com"}
176
- proc do
159
+ it "passes when the url ends with the passed in value" do
160
+ ticks = [
161
+ "http://no.com",
162
+ "http://no.com",
163
+ "http://no.com",
164
+ "http://foobar.com?arg1=2"
165
+ ]
166
+ mock(driver).get_location do
167
+ ticks.shift
168
+ end.times(4)
177
169
  test_case.assert_location_ends_with(@ends_with)
178
- end.should raise_error(Test::Unit::AssertionFailedError)
179
- end
180
- end
181
-
182
- describe TestCase, "#assert_element_present" do
183
- it_should_behave_like "Polonium::TestCase"
184
-
185
- before do
186
- mock.proxy(Element).new(driver, sample_locator) do |element|
187
- mock.proxy(element).assert_element_present
188
- element
189
170
  end
190
- end
191
171
 
192
- it "passes when element is present" do
193
- ticks = [false, false, false, true]
194
- mock(driver).do_command("isElementPresent", [sample_locator]).times(4) do
195
- result(ticks.shift)
172
+ it "fails when the url does not end with the passed in value" do
173
+ stub(driver).get_location {"http://no.com"}
174
+ proc do
175
+ test_case.assert_location_ends_with(@ends_with)
176
+ end.should raise_error(Test::Unit::AssertionFailedError)
196
177
  end
197
- test_case.assert_element_present(sample_locator)
198
178
  end
199
179
 
200
- it "fails when element is not present" do
201
- stub(driver).do_command("isElementPresent", [sample_locator]) do
202
- result(false)
180
+ describe "#assert_element_present" do
181
+ before do
182
+ mock.proxy(Element).new(driver, sample_locator) do |element|
183
+ mock.proxy(element).assert_element_present
184
+ element
185
+ end
203
186
  end
204
- proc do
205
- test_case.assert_element_present(sample_locator)
206
- end.should raise_error(Test::Unit::AssertionFailedError)
207
- end
208
- end
209
187
 
210
- describe TestCase, "#assert_element_not_present" do
211
- it_should_behave_like "Polonium::TestCase"
212
-
213
- before do
214
- mock.proxy(Element).new(driver, sample_locator) do |element|
215
- mock.proxy(element).assert_element_not_present
216
- element
188
+ it "passes when element is present" do
189
+ ticks = [false, false, false, true]
190
+ mock(driver).do_command("isElementPresent", [sample_locator]).times(4) do
191
+ result(ticks.shift)
192
+ end
193
+ test_case.assert_element_present(sample_locator)
217
194
  end
218
- end
219
195
 
220
- it "passes when element is not present" do
221
- ticks = [true, true, true, false]
222
- mock(driver) do |o|
223
- o.is_element_present(sample_locator) do
224
- ticks.shift
225
- end.times(4)
196
+ it "fails when element is not present" do
197
+ stub(driver).do_command("isElementPresent", [sample_locator]) do
198
+ result(false)
199
+ end
200
+ proc do
201
+ test_case.assert_element_present(sample_locator)
202
+ end.should raise_error(Test::Unit::AssertionFailedError)
226
203
  end
227
- test_case.assert_element_not_present(sample_locator)
228
204
  end
229
205
 
230
- it "fails when element is present" do
231
- stub(driver) do |o|
232
- o.is_element_present(sample_locator) {true}
206
+ describe "#assert_element_not_present" do
207
+ before do
208
+ mock.proxy(Element).new(driver, sample_locator) do |element|
209
+ mock.proxy(element).assert_element_not_present
210
+ element
211
+ end
233
212
  end
234
- proc do
235
- test_case.assert_element_not_present(sample_locator)
236
- end.should raise_error(Test::Unit::AssertionFailedError)
237
- end
238
- end
239
213
 
240
- describe TestCase, "#assert_value" do
241
- it_should_behave_like "Polonium::TestCase"
242
-
243
- before do
244
- mock.proxy(Element).new(driver, sample_locator) do |element|
245
- mock.proxy(element).assert_value("passed in value")
246
- element
214
+ it "passes when element is not present" do
215
+ ticks = [true, true, true, false]
216
+ mock(driver) do |o|
217
+ o.is_element_present(sample_locator) do
218
+ ticks.shift
219
+ end.times(4)
220
+ end
221
+ test_case.assert_element_not_present(sample_locator)
247
222
  end
248
- end
249
223
 
250
- it "passes when value is expected" do
251
- mock(driver) do |o|
252
- o.is_element_present(sample_locator) {true}
253
- o.get_value(sample_locator) {"passed in value"}
224
+ it "fails when element is present" do
225
+ stub(driver) do |o|
226
+ o.is_element_present(sample_locator) {true}
227
+ end
228
+ proc do
229
+ test_case.assert_element_not_present(sample_locator)
230
+ end.should raise_error(Test::Unit::AssertionFailedError)
254
231
  end
255
- test_case.assert_value(sample_locator, "passed in value")
256
232
  end
257
233
 
258
- it "fails when value is not expected" do
259
- stub(driver) do |o|
260
- o.is_element_present(sample_locator) {true}
261
- o.get_value(sample_locator) {"another value"}
234
+ describe "#assert_value" do
235
+ before do
236
+ mock.proxy(Element).new(driver, sample_locator) do |element|
237
+ mock.proxy(element).assert_value("passed in value")
238
+ element
239
+ end
262
240
  end
263
- proc do
264
- test_case.assert_value(sample_locator, "passed in value")
265
- end.should raise_error(Test::Unit::AssertionFailedError)
266
- end
267
- end
268
-
269
- describe TestCase, "#assert_element_contains" do
270
- it_should_behave_like "Polonium::TestCase"
271
241
 
272
- before do
273
- mock.proxy(Element).new(driver, sample_locator) do |element|
274
- mock.proxy(element).assert_contains("passed in value", {})
275
- element
242
+ it "passes when value is expected" do
243
+ mock(driver) do |o|
244
+ o.is_element_present(sample_locator) {true}
245
+ o.get_value(sample_locator) {"passed in value"}
246
+ end
247
+ test_case.assert_value(sample_locator, "passed in value")
276
248
  end
277
- @evaled_js = "this.page().findElement(\"#{sample_locator}\").innerHTML"
278
- end
279
249
 
280
- it "passes when text is in the element's inner_html" do
281
- mock(driver) do |o|
282
- o.is_element_present(sample_locator) {true}
283
- o.get_eval(@evaled_js) do
284
- "html passed in value html"
250
+ it "fails when value is not expected" do
251
+ stub(driver) do |o|
252
+ o.is_element_present(sample_locator) {true}
253
+ o.get_value(sample_locator) {"another value"}
285
254
  end
255
+ proc do
256
+ test_case.assert_value(sample_locator, "passed in value")
257
+ end.should raise_error(Test::Unit::AssertionFailedError)
286
258
  end
287
- test_case.assert_element_contains(sample_locator, "passed in value")
288
259
  end
289
260
 
290
- it "fails when text is not in the element's inner_html" do
291
- stub(driver) do |o|
292
- o.is_element_present(sample_locator) {true}
293
- o.get_eval(@evaled_js) {"another value"}
261
+ describe "#assert_element_contains" do
262
+ before do
263
+ mock.proxy(Element).new(driver, sample_locator) do |element|
264
+ mock.proxy(element).assert_contains("passed in value", {})
265
+ element
266
+ end
267
+ @evaled_js = "this.page().findElement(\"#{sample_locator}\").innerHTML"
294
268
  end
295
- proc do
296
- test_case.assert_element_contains(sample_locator, "passed in value")
297
- end.should raise_error(Test::Unit::AssertionFailedError)
298
- end
299
- end
300
269
 
301
- describe TestCase, "#element_does_not_contain_text" do
302
- it_should_behave_like "Polonium::TestCase"
303
-
304
- it "when element is not on the page, returns true" do
305
- locator = "id=element_id"
306
- expected_text = "foobar"
307
- mock(driver).is_element_present(locator) {false}
270
+ it "passes when text is in the element's inner_html" do
271
+ mock(driver) do |o|
272
+ o.is_element_present(sample_locator) {true}
273
+ o.get_eval(@evaled_js) do
274
+ "html passed in value html"
275
+ end
276
+ end
277
+ test_case.assert_element_contains(sample_locator, "passed in value")
278
+ end
308
279
 
309
- test_case.element_does_not_contain_text(locator, expected_text).should == true
280
+ it "fails when text is not in the element's inner_html" do
281
+ stub(driver) do |o|
282
+ o.is_element_present(sample_locator) {true}
283
+ o.get_eval(@evaled_js) {"another value"}
284
+ end
285
+ proc do
286
+ test_case.assert_element_contains(sample_locator, "passed in value")
287
+ end.should raise_error(Test::Unit::AssertionFailedError)
288
+ end
310
289
  end
311
290
 
312
- it "when element is on page and inner_html does not contain text, returns true" do
313
- locator = "id=element_id"
314
- inner_html = "Some text that does not contain the expected_text"
315
- expected_text = "foobar"
316
- mock(driver).do_command("isElementPresent", [locator]) do
317
- result(true)
318
- end
319
- mock(driver).do_command("getEval", [driver.inner_html_js(locator)]) do
320
- inner_html
291
+ describe "#element_does_not_contain_text" do
292
+ it "when element is not on the page, returns true" do
293
+ locator = "id=element_id"
294
+ expected_text = "foobar"
295
+ mock(driver).is_element_present(locator) {false}
296
+
297
+ test_case.element_does_not_contain_text(locator, expected_text).should == true
321
298
  end
322
299
 
323
- test_case.element_does_not_contain_text(locator, expected_text).should == true
324
- end
300
+ it "when element is on page and inner_html does not contain text, returns true" do
301
+ locator = "id=element_id"
302
+ inner_html = "Some text that does not contain the expected_text"
303
+ expected_text = "foobar"
304
+ mock(driver).do_command("isElementPresent", [locator]) do
305
+ result(true)
306
+ end
307
+ mock(driver).do_command("getEval", [driver.inner_html_js(locator)]) do
308
+ inner_html
309
+ end
325
310
 
326
- it "when element is on page and inner_html does contain text, returns false" do
327
- locator = "id=element_id"
328
- inner_html = "foobar foobar foobar"
329
- expected_text = "foobar"
330
- mock(driver).do_command("isElementPresent", [locator]) do
331
- result(true)
332
- end
333
- mock(driver).do_command("getEval", [driver.inner_html_js(locator)]) do
334
- inner_html
311
+ test_case.element_does_not_contain_text(locator, expected_text).should == true
335
312
  end
336
313
 
337
- test_case.element_does_not_contain_text(locator, expected_text).should == false
338
- end
339
- end
340
-
341
- describe TestCase, "#assert_element_does_not_contain" do
342
- it_should_behave_like "Polonium::TestCase"
314
+ it "when element is on page and inner_html does contain text, returns false" do
315
+ locator = "id=element_id"
316
+ inner_html = "foobar foobar foobar"
317
+ expected_text = "foobar"
318
+ mock(driver).do_command("isElementPresent", [locator]) do
319
+ result(true)
320
+ end
321
+ mock(driver).do_command("getEval", [driver.inner_html_js(locator)]) do
322
+ inner_html
323
+ end
343
324
 
344
- before do
345
- mock.proxy(Element).new(driver, sample_locator) do |element|
346
- mock.proxy(element).assert_does_not_contain("passed in value", {})
347
- element
325
+ test_case.element_does_not_contain_text(locator, expected_text).should == false
348
326
  end
349
- @evaled_js = "this.page().findElement(\"#{sample_locator}\").innerHTML"
350
327
  end
351
328
 
352
- it "passes when text is not in the element's inner_html" do
353
- mock(driver) do |o|
354
- o.is_element_present(sample_locator) {true}
355
- o.get_eval(@evaled_js) do
356
- "another value"
329
+ describe "#assert_element_does_not_contain" do
330
+ before do
331
+ mock.proxy(Element).new(driver, sample_locator) do |element|
332
+ mock.proxy(element).assert_does_not_contain("passed in value", {})
333
+ element
357
334
  end
335
+ @evaled_js = "this.page().findElement(\"#{sample_locator}\").innerHTML"
358
336
  end
359
- test_case.assert_element_does_not_contain(sample_locator, "passed in value")
360
- end
361
337
 
362
- it "fails when text is in the element's inner_html" do
363
- stub(driver) do |o|
364
- o.is_element_present(sample_locator) {true}
365
- o.get_eval(@evaled_js) {"html passed in value html"}
366
- end
367
- proc do
338
+ it "passes when text is not in the element's inner_html" do
339
+ mock(driver) do |o|
340
+ o.is_element_present(sample_locator) {true}
341
+ o.get_eval(@evaled_js) do
342
+ "another value"
343
+ end
344
+ end
368
345
  test_case.assert_element_does_not_contain(sample_locator, "passed in value")
369
- end.should raise_error(Test::Unit::AssertionFailedError)
370
- end
371
- end
372
-
373
- describe TestCase, "#assert_contains_in_order" do
374
- it_should_behave_like "Polonium::TestCase"
375
-
376
- it "when text is in order, it succeeds" do
377
- mock.proxy(Element).new(driver, sample_locator) do |element|
378
- mock.proxy(element).assert_contains_in_order("one", "two", "three")
379
- element
380
346
  end
381
- stub(@driver).get_text(sample_locator).returns("one\ntwo\nthree\n")
382
- stub(@driver).is_element_present(sample_locator) {true}
383
347
 
384
- test_case.assert_contains_in_order sample_locator, "one", "two", "three"
348
+ it "fails when text is in the element's inner_html" do
349
+ stub(driver) do |o|
350
+ o.is_element_present(sample_locator) {true}
351
+ o.get_eval(@evaled_js) {"html passed in value html"}
352
+ end
353
+ proc do
354
+ test_case.assert_element_does_not_contain(sample_locator, "passed in value")
355
+ end.should raise_error(Test::Unit::AssertionFailedError)
356
+ end
385
357
  end
386
- end
387
358
 
388
- describe TestCase, "#assert_attribute" do
389
- it_should_behave_like "Polonium::TestCase"
359
+ describe "#assert_contains_in_order" do
360
+ it "when text is in order, it succeeds" do
361
+ mock.proxy(Element).new(driver, sample_locator) do |element|
362
+ mock.proxy(element).assert_contains_in_order("one", "two", "three")
363
+ element
364
+ end
365
+ stub(@driver).get_text(sample_locator).returns("one\ntwo\nthree\n")
366
+ stub(@driver).is_element_present(sample_locator) {true}
390
367
 
391
- before do
392
- mock.proxy(Element).new(driver, sample_locator) do |element|
393
- mock.proxy(element).assert_attribute('id', "passed in value")
394
- element
368
+ test_case.assert_contains_in_order sample_locator, "one", "two", "three"
395
369
  end
396
370
  end
397
371
 
398
- it "passes when attribute is expected" do
399
- mock(driver) do |o|
400
- o.is_element_present(sample_locator) {true}
401
- o.get_attribute("#{sample_locator}@id") {"passed in value"}
372
+ describe "#assert_attribute" do
373
+ before do
374
+ mock.proxy(Element).new(driver, sample_locator) do |element|
375
+ mock.proxy(element).assert_attribute('id', "passed in value")
376
+ element
377
+ end
402
378
  end
403
- test_case.assert_attribute(sample_locator, 'id', "passed in value")
404
- end
405
379
 
406
- it "fails when attribute is not expected" do
407
- stub(driver) do |o|
408
- o.is_element_present(sample_locator) {true}
409
- o.get_attribute("#{sample_locator}@id") {"another value"}
410
- end
411
- proc do
380
+ it "passes when attribute is expected" do
381
+ mock(driver) do |o|
382
+ o.is_element_present(sample_locator) {true}
383
+ o.get_attribute("#{sample_locator}@id") {"passed in value"}
384
+ end
412
385
  test_case.assert_attribute(sample_locator, 'id', "passed in value")
413
- end.should raise_error(Test::Unit::AssertionFailedError)
414
- end
415
- end
416
-
417
- describe TestCase, "#assert_selected" do
418
- it_should_behave_like "Polonium::TestCase"
419
-
420
- before do
421
- mock.proxy(Element).new(driver, sample_locator) do |element|
422
- mock.proxy(element).assert_selected("passed_in_element")
423
- element
424
386
  end
425
- end
426
387
 
427
- it "passes when selected is expected" do
428
- mock(driver) do |o|
429
- o.is_element_present(sample_locator) {true}
430
- o.get_selected_label(sample_locator) {"passed_in_element"}
388
+ it "fails when attribute is not expected" do
389
+ stub(driver) do |o|
390
+ o.is_element_present(sample_locator) {true}
391
+ o.get_attribute("#{sample_locator}@id") {"another value"}
392
+ end
393
+ proc do
394
+ test_case.assert_attribute(sample_locator, 'id', "passed in value")
395
+ end.should raise_error(Test::Unit::AssertionFailedError)
431
396
  end
432
- test_case.assert_selected(sample_locator, "passed_in_element")
433
397
  end
434
398
 
435
- it "fails when selected is not expected" do
436
- stub(driver) do |o|
437
- o.is_element_present(sample_locator) {true}
438
- o.get_selected_label(sample_locator) {"another_element"}
399
+ describe "#assert_selected" do
400
+ before do
401
+ mock.proxy(Element).new(driver, sample_locator) do |element|
402
+ mock.proxy(element).assert_selected("passed_in_element")
403
+ element
404
+ end
439
405
  end
440
- proc do
441
- test_case.assert_selected(sample_locator, "passed_in_element")
442
- end.should raise_error(Test::Unit::AssertionFailedError)
443
- end
444
- end
445
406
 
446
- describe TestCase, "#assert_checked" do
447
- it_should_behave_like "Polonium::TestCase"
448
-
449
- before do
450
- mock.proxy(Element).new(driver, sample_locator) do |element|
451
- mock.proxy(element).assert_checked
452
- element
407
+ it "passes when selected is expected" do
408
+ mock(driver) do |o|
409
+ o.is_element_present(sample_locator) {true}
410
+ o.get_selected_label(sample_locator) {"passed_in_element"}
411
+ end
412
+ test_case.assert_selected(sample_locator, "passed_in_element")
453
413
  end
454
- end
455
414
 
456
- it "passes when checked" do
457
- mock(driver) do |o|
458
- o.is_element_present(sample_locator) {true}
459
- o.is_checked(sample_locator) {true}
415
+ it "fails when selected is not expected" do
416
+ stub(driver) do |o|
417
+ o.is_element_present(sample_locator) {true}
418
+ o.get_selected_label(sample_locator) {"another_element"}
419
+ end
420
+ proc do
421
+ test_case.assert_selected(sample_locator, "passed_in_element")
422
+ end.should raise_error(Test::Unit::AssertionFailedError)
460
423
  end
461
- test_case.assert_checked(sample_locator)
462
424
  end
463
425
 
464
- it "fails when not checked" do
465
- stub(driver) do |driver|
466
- driver.is_element_present(sample_locator) {true}
467
- driver.is_checked(sample_locator) {false}
426
+ describe "#assert_checked" do
427
+ before do
428
+ mock.proxy(Element).new(driver, sample_locator) do |element|
429
+ mock.proxy(element).assert_checked
430
+ element
431
+ end
468
432
  end
469
- proc do
470
- test_case.assert_checked(sample_locator)
471
- end.should raise_error(Test::Unit::AssertionFailedError)
472
- end
473
- end
474
433
 
475
- describe TestCase, "#assert_not_checked" do
476
- it_should_behave_like "Polonium::TestCase"
477
-
478
- before do
479
- mock.proxy(Element).new(driver, sample_locator) do |element|
480
- mock.proxy(element).assert_not_checked
481
- element
434
+ it "passes when checked" do
435
+ mock(driver) do |o|
436
+ o.is_element_present(sample_locator) {true}
437
+ o.is_checked(sample_locator) {true}
438
+ end
439
+ test_case.assert_checked(sample_locator)
482
440
  end
483
- end
484
441
 
485
- it "passes when not checked" do
486
- mock(driver) do |driver|
487
- driver.is_element_present(sample_locator) {true}
488
- driver.is_checked(sample_locator) {false}
442
+ it "fails when not checked" do
443
+ stub(driver) do |driver|
444
+ driver.is_element_present(sample_locator) {true}
445
+ driver.is_checked(sample_locator) {false}
446
+ end
447
+ proc do
448
+ test_case.assert_checked(sample_locator)
449
+ end.should raise_error(Test::Unit::AssertionFailedError)
489
450
  end
490
- test_case.assert_not_checked(sample_locator)
491
451
  end
492
452
 
493
- it "fails when checked" do
494
- stub(driver) do |driver|
495
- driver.is_element_present(sample_locator) {true}
496
- driver.is_checked(sample_locator) {true}
453
+ describe "#assert_not_checked" do
454
+ before do
455
+ mock.proxy(Element).new(driver, sample_locator) do |element|
456
+ mock.proxy(element).assert_not_checked
457
+ element
458
+ end
497
459
  end
498
- proc do
499
- test_case.assert_not_checked(sample_locator)
500
- end.should raise_error(Test::Unit::AssertionFailedError)
501
- end
502
- end
503
-
504
- describe TestCase, "#assert_text" do
505
- it_should_behave_like "Polonium::TestCase"
506
460
 
507
- before do
508
- mock.proxy(Element).new(driver, sample_locator) do |element|
509
- mock.proxy(element).assert_text("expected text")
510
- element
461
+ it "passes when not checked" do
462
+ mock(driver) do |driver|
463
+ driver.is_element_present(sample_locator) {true}
464
+ driver.is_checked(sample_locator) {false}
465
+ end
466
+ test_case.assert_not_checked(sample_locator)
511
467
  end
512
- end
513
468
 
514
- it "passes when text is expected" do
515
- mock(driver) do |o|
516
- o.is_element_present(sample_locator) {true}
517
- o.get_text(sample_locator) {"expected text"}
469
+ it "fails when checked" do
470
+ stub(driver) do |driver|
471
+ driver.is_element_present(sample_locator) {true}
472
+ driver.is_checked(sample_locator) {true}
473
+ end
474
+ proc do
475
+ test_case.assert_not_checked(sample_locator)
476
+ end.should raise_error(Test::Unit::AssertionFailedError)
518
477
  end
519
- test_case.assert_text(sample_locator, "expected text")
520
478
  end
521
479
 
522
- it "fails when text is not expected" do
523
- stub(driver) do |o|
524
- o.is_element_present(sample_locator) {true}
525
- o.get_text(sample_locator) {"unexpected text"}
480
+ describe "#assert_text" do
481
+ before do
482
+ mock.proxy(Element).new(driver, sample_locator) do |element|
483
+ mock.proxy(element).assert_text("expected text")
484
+ element
485
+ end
526
486
  end
527
- proc do
528
- test_case.assert_text(sample_locator, "expected text")
529
- end.should raise_error(Test::Unit::AssertionFailedError)
530
- end
531
- end
532
487
 
533
- describe TestCase, "#assert_visible" do
534
- it_should_behave_like "Polonium::TestCase"
488
+ it "passes when text is expected" do
489
+ mock(driver) do |o|
490
+ o.is_element_present(sample_locator) {true}
491
+ o.get_text(sample_locator) {"expected text"}
492
+ end
493
+ test_case.assert_text(sample_locator, "expected text")
494
+ end
535
495
 
536
- before do
537
- mock.proxy(Element).new(driver, sample_locator) do |element|
538
- mock.proxy(element).assert_visible
539
- element
496
+ it "fails when text is not expected" do
497
+ stub(driver) do |o|
498
+ o.is_element_present(sample_locator) {true}
499
+ o.get_text(sample_locator) {"unexpected text"}
500
+ end
501
+ proc do
502
+ test_case.assert_text(sample_locator, "expected text")
503
+ end.should raise_error(Test::Unit::AssertionFailedError)
540
504
  end
541
505
  end
542
506
 
543
- it "passes when element is visible" do
544
- mock(driver).is_element_present(sample_locator) {true}
545
- mock(driver).is_visible(sample_locator) {true}
546
-
547
- test_case.assert_visible(sample_locator)
548
- end
507
+ describe "#assert_visible" do
508
+ before do
509
+ mock.proxy(Element).new(driver, sample_locator) do |element|
510
+ mock.proxy(element).assert_visible
511
+ element
512
+ end
513
+ end
549
514
 
550
- it "fails when element is not visible" do
551
- mock(driver).is_element_present(sample_locator) {true}
552
- stub(driver).is_visible.returns {false}
515
+ it "passes when element is visible" do
516
+ mock(driver).is_element_present(sample_locator) {true}
517
+ mock(driver).is_visible(sample_locator) {true}
553
518
 
554
- proc {
555
519
  test_case.assert_visible(sample_locator)
556
- }.should raise_error(Test::Unit::AssertionFailedError)
557
- end
558
- end
520
+ end
559
521
 
560
- describe TestCase, "#assert_not_visible" do
561
- it_should_behave_like "Polonium::TestCase"
522
+ it "fails when element is not visible" do
523
+ stub(driver).is_element_present(sample_locator) {true}
524
+ stub(driver).is_visible.returns {false}
562
525
 
563
- before do
564
- mock.proxy(Element).new(driver, sample_locator) do |element|
565
- mock.proxy(element).assert_not_visible
566
- element
526
+ proc {
527
+ test_case.assert_visible(sample_locator)
528
+ }.should raise_error(Test::Unit::AssertionFailedError)
567
529
  end
568
530
  end
569
531
 
570
- it "passes when element is present and is not visible" do
571
- mock(driver).is_element_present(sample_locator) {true}
572
- mock(driver).is_visible(sample_locator) {false}
573
-
574
- test_case.assert_not_visible(sample_locator)
575
- end
532
+ describe "#assert_not_visible" do
533
+ before do
534
+ mock.proxy(Element).new(driver, sample_locator) do |element|
535
+ mock.proxy(element).assert_not_visible
536
+ element
537
+ end
538
+ end
576
539
 
577
- it "fails when element is visible" do
578
- mock(driver).is_element_present(sample_locator) {true}
579
- stub(driver).is_visible(sample_locator) {true}
540
+ it "passes when element is present and is not visible" do
541
+ mock(driver).is_element_present(sample_locator) {true}
542
+ mock(driver).is_visible(sample_locator) {false}
580
543
 
581
- proc {
582
544
  test_case.assert_not_visible(sample_locator)
583
- }.should raise_error(Test::Unit::AssertionFailedError)
584
- end
585
- end
586
-
587
- describe TestCase, "#assert_next_sibling" do
588
- it_should_behave_like "Polonium::TestCase"
589
-
590
- before do
591
- mock.proxy(Element).new(driver, sample_locator) do |element|
592
- mock.proxy(element).assert_next_sibling("next_sibling")
593
- element
594
545
  end
595
- @evaled_js = "this.page().findElement('#{sample_locator}').nextSibling.id"
596
- end
597
546
 
598
- it "passes when passed next sibling id" do
599
- mock(driver) do |o|
600
- o.is_element_present(sample_locator) {true}
601
- o.get_eval(@evaled_js) {"next_sibling"}
602
- end
603
- test_case.assert_next_sibling(sample_locator, "next_sibling")
604
- end
547
+ it "fails when element is visible" do
548
+ stub(driver).is_element_present(sample_locator) {true}
549
+ stub(driver).is_visible(sample_locator) {true}
605
550
 
606
- it "fails when not passed next sibling id" do
607
- stub(driver) do |o|
608
- o.is_element_present(sample_locator) {true}
609
- o.get_eval(@evaled_js) {"wrong_sibling"}
551
+ proc {
552
+ test_case.assert_not_visible(sample_locator)
553
+ }.should raise_error(Test::Unit::AssertionFailedError)
610
554
  end
611
- proc do
612
- test_case.assert_next_sibling(sample_locator, "next_sibling")
613
- end.should raise_error(Test::Unit::AssertionFailedError)
614
555
  end
615
- end
616
556
 
617
- describe TestCase, "#assert_contains_in_order" do
618
- it_should_behave_like "Polonium::TestCase"
619
-
620
- before do
621
- mock.proxy(Element).new(driver, sample_locator)
622
- @evaled_js = "this.page().findElement('#{sample_locator}').nextSibling.id"
623
- end
624
-
625
- it "passes when text is in order" do
626
- mock(driver) do |o|
627
- o.is_element_present(sample_locator) {true}
628
- o.get_text(sample_locator) {"one\ntwo\nthree\n"}
557
+ describe "#assert_next_sibling" do
558
+ before do
559
+ mock.proxy(Element).new(driver, sample_locator) do |element|
560
+ mock.proxy(element).assert_next_sibling("next_sibling")
561
+ element
562
+ end
563
+ @evaled_js = "this.page().findElement('#{sample_locator}').nextSibling.id"
629
564
  end
630
- test_case.assert_contains_in_order sample_locator, "one", "two", "three"
631
- end
632
565
 
633
- it "fails when element is present and text is not in order" do
634
- stub(driver) do |o|
635
- o.is_element_present(sample_locator) {true}
636
- o.get_text(sample_locator) {"<html>one\ntext not in order\n</html>"}
566
+ it "passes when passed next sibling id" do
567
+ mock(driver) do |o|
568
+ o.is_element_present(sample_locator) {true}
569
+ o.get_eval(@evaled_js) {"next_sibling"}
570
+ end
571
+ test_case.assert_next_sibling(sample_locator, "next_sibling")
637
572
  end
638
- proc do
639
- test_case.assert_contains_in_order sample_locator, "one", "two", "three"
640
- end.should raise_error(Test::Unit::AssertionFailedError)
641
- end
642
- end
643
573
 
644
- describe TestCase, "#type" do
645
- it_should_behave_like "Polonium::TestCase"
646
-
647
- it "types when element is present and types" do
648
- is_element_present_results = [false, true]
649
- mock(driver).do_command("isElementPresent", ["id=foobar"]).twice do
650
- result(is_element_present_results.shift)
651
- end
652
- mock(driver).do_command("type", ["id=foobar", "The Text"]) do
653
- result()
574
+ it "fails when not passed next sibling id" do
575
+ stub(driver) do |o|
576
+ o.is_element_present(sample_locator) {true}
577
+ o.get_eval(@evaled_js) {"wrong_sibling"}
578
+ end
579
+ proc do
580
+ test_case.assert_next_sibling(sample_locator, "next_sibling")
581
+ end.should raise_error(Test::Unit::AssertionFailedError)
654
582
  end
655
-
656
- test_case.type "id=foobar", "The Text"
657
583
  end
658
584
 
659
- it "fails when element is not present" do
660
- mock(driver).do_command("isElementPresent", ["id=foobar"]).times(4) do
661
- result(false)
585
+ describe "#assert_contains_in_order" do
586
+ before do
587
+ mock.proxy(Element).new(driver, sample_locator)
588
+ @evaled_js = "this.page().findElement('#{sample_locator}').nextSibling.id"
662
589
  end
663
- dont_allow(driver).do_command("type", ["id=foobar", "The Text"])
664
590
 
665
- proc {
666
- test_case.type "id=foobar", "The Text"
667
- }.should raise_error(Test::Unit::AssertionFailedError)
668
- end
669
- end
670
-
671
- describe TestCase, "#click" do
672
- it_should_behave_like "Polonium::TestCase"
673
-
674
- it "click when element is present and types" do
675
- is_element_present_results = [false, true]
676
- mock(driver).do_command("isElementPresent", ["id=foobar"]).twice do
677
- result(is_element_present_results.shift)
591
+ it "passes when text is in order" do
592
+ mock(driver) do |o|
593
+ o.is_element_present(sample_locator) {true}
594
+ o.get_text(sample_locator) {"one\ntwo\nthree\n"}
595
+ end
596
+ test_case.assert_contains_in_order sample_locator, "one", "two", "three"
678
597
  end
679
- mock(driver).do_command("click", ["id=foobar"]) {result}
680
598
 
681
- test_case.click "id=foobar"
682
- end
683
-
684
- it "fails when element is not present" do
685
- is_element_present_results = [false, false, false, false]
686
- mock(driver).do_command("isElementPresent", ["id=foobar"]).times(4) do
687
- result(is_element_present_results.shift)
599
+ it "fails when element is present and text is not in order" do
600
+ stub(driver) do |o|
601
+ o.is_element_present(sample_locator) {true}
602
+ o.get_text(sample_locator) {"<html>one\ntext not in order\n</html>"}
603
+ end
604
+ proc do
605
+ test_case.assert_contains_in_order sample_locator, "one", "two", "three"
606
+ end.should raise_error(Test::Unit::AssertionFailedError)
688
607
  end
689
- dont_allow(driver).do_command("click", [])
690
-
691
- proc {
692
- test_case.click "id=foobar"
693
- }.should raise_error(Test::Unit::AssertionFailedError)
694
608
  end
695
- end
696
609
 
697
- describe TestCase, "#select" do
698
- it_should_behave_like "Polonium::TestCase"
699
-
700
- it "types when element is present and types" do
701
- is_element_present_results = [false, true]
702
- mock(driver).do_command("isElementPresent", ["id=foobar"]).twice do
703
- result is_element_present_results.shift
610
+ describe "#page" do
611
+ it "returns page" do
612
+ test_case.page.should == Page.new(driver)
704
613
  end
705
- mock(driver).do_command("select", ["id=foobar", "value=3"]) {result}
706
-
707
- test_case.select "id=foobar", "value=3"
708
614
  end
709
615
 
710
- it "fails when element is not present" do
711
- mock(driver).do_command("isElementPresent", ["id=foobar"]).times(4) do
712
- result false
616
+ describe "#get_eval" do
617
+ it "delegates to Driver" do
618
+ mock(driver).get_eval "foobar"
619
+ test_case.get_eval "foobar"
713
620
  end
714
- dont_allow(driver).do_command("select", ["id=foobar", "value=3"])
715
-
716
- proc {
717
- test_case.select "id=foobar", "value=3"
718
- }.should raise_error(Test::Unit::AssertionFailedError)
719
621
  end
720
- end
721
622
 
722
- describe TestCase, "#wait_for_and_click" do
723
- it_should_behave_like "Polonium::TestCase"
623
+ describe "#assert_element_contains" do
624
+ it "when finding text within time limit, passes" do
625
+ is_element_present_results = [false, true]
626
+ mock(driver).do_command('isElementPresent', [sample_locator]).times(2) do
627
+ result(is_element_present_results.shift)
628
+ end
629
+ mock(driver).do_command('getEval', [driver.inner_html_js(sample_locator)]) do
630
+ result(sample_text)
631
+ end
724
632
 
725
- it "click when element is present and types" do
726
- is_element_present_results = [false, true]
727
- mock(driver).do_command("isElementPresent", ["id=foobar"]).twice do
728
- result is_element_present_results.shift
633
+ test_case.assert_element_contains(sample_locator, sample_text)
729
634
  end
730
- mock(driver).do_command("click", ["id=foobar"]) {result}
731
635
 
732
- test_case.wait_for_and_click "id=foobar"
733
- end
636
+ it "when element not found in time, fails" do
637
+ mock(driver).do_command('isElementPresent', [sample_locator]).times(4) do
638
+ result(false)
639
+ end
734
640
 
735
- it "fails when element is not present" do
736
- is_element_present_results = [false, false, false, false]
737
- mock(driver).is_element_present("id=foobar").times(4) do
738
- is_element_present_results.shift
641
+ proc do
642
+ test_case.assert_element_contains(sample_locator, "")
643
+ end.should raise_error(Test::Unit::AssertionFailedError, "Expected element 'sample_locator' to be present, but it was not (after 5 sec)")
739
644
  end
740
- dont_allow(driver).click
741
645
 
742
- proc {
743
- test_case.wait_for_and_click "id=foobar"
744
- }.should raise_error(Test::Unit::AssertionFailedError)
745
- end
746
- end
747
-
748
- describe TestCase, "#page" do
749
- it_should_behave_like "Polonium::TestCase"
750
-
751
- it "returns page" do
752
- test_case.page.should == Page.new(driver)
753
- end
754
- end
755
-
756
- describe TestCase, "#get_eval" do
757
- it_should_behave_like "Polonium::TestCase"
646
+ it "when text does not match in time, fails" do
647
+ is_element_present_results = [false, true, true, true]
648
+ stub(driver).do_command('isElementPresent', [sample_locator]) do
649
+ result(is_element_present_results.shift)
650
+ end
651
+ stub(driver).do_command('getEval', [driver.inner_html_js(sample_locator)]) do
652
+ result(sample_text)
653
+ end
758
654
 
759
- it "delegates to Driver" do
760
- mock(driver).get_eval "foobar"
761
- test_case.get_eval "foobar"
655
+ proc do
656
+ test_case.assert_element_contains(sample_locator, "wrong text")
657
+ end.should raise_error(Test::Unit::AssertionFailedError, "sample_locator should contain wrong text (after 5 sec)")
658
+ end
762
659
  end
763
- end
764
-
765
- describe "TestCase in test browser mode and test fails" do
766
- it_should_behave_like "Polonium::TestCase"
767
660
 
768
- it "should stop driver when configuration says to stop test" do
769
- test_case.configuration = configuration = Polonium::Configuration.new
770
- configuration.test_browser_mode
661
+ describe "#method_missing" do
662
+ describe "when the #selenium_driver responds to the method" do
663
+ before do
664
+ driver.respond_to?(:assert_element_present).should be_true
665
+ end
771
666
 
772
- stub(test_case).passed? {false}
773
- configuration.keep_browser_open_on_failure = false
667
+ it "delegates the invocation to the selenium_driver" do
668
+ mock(driver).assert_element_present("id=element", {})
669
+ test_case.assert_element_present("id=element", {})
670
+ end
671
+ end
774
672
 
775
- mock(driver).stop.once
776
- test_case.selenium_driver = driver
673
+ describe "when the #selenium_driver does not respond to the method" do
674
+ before do
675
+ driver.respond_to?(:another_method).should_not be_true
676
+ end
777
677
 
778
- test_case.teardown
678
+ it "handles invokes the superclass method_missing" do
679
+ lambda do
680
+ test_case.another_method
681
+ end.should raise_error(NoMethodError, /TestCaseSpecHelper::MySeleniumTestCase/)
682
+ end
683
+ end
779
684
  end
780
685
 
781
- it "should not stop driver when configuration says not to stop test" do
782
- test_case.configuration = "Polonium::Configuration"
783
- mock(test_case.configuration).test_browser_mode?.returns(true)
686
+ describe "when in test browser mode" do
687
+ describe "and test fails" do
688
+ it "should stop driver when configuration says to stop test" do
689
+ Configuration.instance = configuration = Polonium::Configuration.new
690
+ configuration.test_browser_mode
784
691
 
785
- stub(test_case).passed? {false}
786
- mock(test_case.configuration).stop_driver?(false) {false}
692
+ stub(test_case).passed? {false}
693
+ configuration.keep_browser_open_on_failure = false
787
694
 
788
- test_case.selenium_driver = driver
695
+ mock(driver).stop.once
696
+ test_case.selenium_driver = driver
789
697
 
790
- test_case.teardown
791
- end
792
- end
698
+ test_case.teardown
699
+ end
793
700
 
794
- describe "TestCase in test browser mode and test pass" do
795
- it_should_behave_like "Polonium::TestCase"
701
+ it "should not stop driver when configuration says not to stop test" do
702
+ Configuration.instance = "Polonium::Configuration"
703
+ mock(Configuration.instance).test_browser_mode?.returns(true)
796
704
 
797
- it "should stop driver when configuration says to stop test" do
798
- test_case.configuration = "Polonium::Configuration"
799
- mock(test_case.configuration).test_browser_mode?.returns(true)
705
+ stub(test_case).passed? {false}
706
+ mock(Configuration.instance).stop_driver?(false) {false}
800
707
 
801
- stub(test_case).passed?.returns(true)
802
- mock(test_case.configuration).stop_driver?(true) {true}
708
+ test_case.selenium_driver = driver
803
709
 
804
- mock(driver).stop.once
805
- test_case.selenium_driver = driver
710
+ test_case.teardown
711
+ end
712
+ end
806
713
 
807
- test_case.teardown
808
- end
714
+ describe "and test passes" do
715
+ it "should stop driver when configuration says to stop test" do
716
+ Configuration.instance = "Polonium::Configuration"
717
+ mock(Configuration.instance).test_browser_mode?.returns(true)
809
718
 
810
- it "should not stop driver when configuration says not to stop test" do
811
- test_case.configuration = "Polonium::Configuration"
812
- mock(test_case.configuration).test_browser_mode?.returns(true)
719
+ stub(test_case).passed?.returns(true)
720
+ mock(Configuration.instance).stop_driver?(true) {true}
813
721
 
814
- stub(test_case).passed?.returns(true)
815
- mock(test_case.configuration).stop_driver?(true) {false}
722
+ mock(driver).stop.once
723
+ test_case.selenium_driver = driver
816
724
 
817
- test_case.selenium_driver = driver
725
+ test_case.teardown
726
+ end
818
727
 
819
- test_case.teardown
820
- end
821
- end
728
+ it "should not stop driver when configuration says not to stop test" do
729
+ Configuration.instance = "Polonium::Configuration"
730
+ mock(Configuration.instance).test_browser_mode?.returns(true)
822
731
 
823
- describe "TestCase not in suite browser mode" do
824
- it_should_behave_like "Polonium::TestCase"
732
+ stub(test_case).passed?.returns(true)
733
+ mock(Configuration.instance).stop_driver?(true) {false}
825
734
 
826
- it "should not stop driver when tests fail" do
827
- test_case.configuration = "Polonium::Configuration"
828
- mock(test_case.configuration).test_browser_mode? {false}
735
+ test_case.selenium_driver = driver
829
736
 
830
- def test_case.passed?;
831
- false;
737
+ test_case.teardown
738
+ end
832
739
  end
833
-
834
- test_case.selenium_driver = driver
835
-
836
- test_case.teardown
837
- end
838
-
839
- it "should stop driver when tests pass" do
840
- test_case.configuration = "Polonium::Configuration"
841
- mock(test_case.configuration).test_browser_mode? {false}
842
-
843
- stub(test_case).passed?.returns(true)
844
-
845
- test_case.selenium_driver = driver
846
-
847
- test_case.teardown
848
740
  end
849
- end
850
-
851
- describe "TestCase in test browser mode and test pass" do
852
- it_should_behave_like "Polonium::TestCase"
853
741
 
854
- it "should stop driver when configuration says to stop test" do
855
- test_case.configuration = "Polonium::Configuration"
856
- mock(test_case.configuration).test_browser_mode?.returns(true)
742
+ describe "when in suite browser mode" do
743
+ it "should not stop driver when tests fail" do
744
+ Configuration.instance = "Polonium::Configuration"
745
+ mock(Configuration.instance).test_browser_mode? {false}
857
746
 
858
- stub(test_case).passed?.returns(true)
859
- mock(test_case.configuration).stop_driver?(true) {true}
747
+ def test_case.passed?;
748
+ false;
749
+ end
860
750
 
861
- mock(driver).stop.once
862
- test_case.selenium_driver = driver
751
+ test_case.selenium_driver = driver
863
752
 
864
- test_case.teardown
865
- end
753
+ test_case.teardown
754
+ end
866
755
 
867
- it "should not stop driver when configuration says not to stop test" do
868
- test_case.configuration = "Polonium::Configuration"
869
- mock(test_case.configuration).test_browser_mode? {true}
756
+ it "should stop driver when tests pass" do
757
+ Configuration.instance = "Polonium::Configuration"
758
+ mock(Configuration.instance).test_browser_mode? {false}
870
759
 
871
- stub(test_case).passed?.returns(true)
872
- mock(test_case.configuration).stop_driver?(true) {false}
760
+ stub(test_case).passed?.returns(true)
873
761
 
874
- test_case.selenium_driver = driver
762
+ test_case.selenium_driver = driver
875
763
 
876
- test_case.teardown
764
+ test_case.teardown
765
+ end
877
766
  end
878
767
  end
879
768
  end