capybara 2.0.0.beta2 → 2.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/History.txt +30 -1
  2. data/README.md +52 -31
  3. data/lib/capybara.rb +1 -0
  4. data/lib/capybara/driver/base.rb +1 -1
  5. data/lib/capybara/driver/node.rb +1 -0
  6. data/lib/capybara/dsl.rb +12 -5
  7. data/lib/capybara/helpers.rb +33 -0
  8. data/lib/capybara/node/actions.rb +4 -2
  9. data/lib/capybara/node/base.rb +52 -1
  10. data/lib/capybara/node/element.rb +0 -12
  11. data/lib/capybara/node/finders.rb +1 -1
  12. data/lib/capybara/node/matchers.rb +57 -47
  13. data/lib/capybara/node/simple.rb +4 -0
  14. data/lib/capybara/query.rb +11 -11
  15. data/lib/capybara/rack_test/browser.rb +14 -15
  16. data/lib/capybara/rack_test/driver.rb +2 -2
  17. data/lib/capybara/rack_test/node.rb +15 -2
  18. data/lib/capybara/result.rb +7 -19
  19. data/lib/capybara/rspec.rb +7 -4
  20. data/lib/capybara/rspec/features.rb +4 -1
  21. data/lib/capybara/rspec/matchers.rb +8 -3
  22. data/lib/capybara/selector.rb +1 -2
  23. data/lib/capybara/selenium/driver.rb +2 -2
  24. data/lib/capybara/selenium/node.rb +9 -7
  25. data/lib/capybara/session.rb +47 -31
  26. data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
  27. data/lib/capybara/spec/public/test.js +1 -1
  28. data/lib/capybara/spec/session/all_spec.rb +60 -62
  29. data/lib/capybara/spec/session/assert_selector.rb +123 -0
  30. data/lib/capybara/spec/session/attach_file_spec.rb +72 -58
  31. data/lib/capybara/spec/session/body_spec.rb +21 -0
  32. data/lib/capybara/spec/session/check_spec.rb +67 -50
  33. data/lib/capybara/spec/session/choose_spec.rb +32 -21
  34. data/lib/capybara/spec/session/click_button_spec.rb +261 -221
  35. data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -30
  36. data/lib/capybara/spec/session/click_link_spec.rb +95 -81
  37. data/lib/capybara/spec/session/current_url_spec.rb +70 -60
  38. data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
  39. data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
  40. data/lib/capybara/spec/session/fill_in_spec.rb +118 -92
  41. data/lib/capybara/spec/session/find_button_spec.rb +16 -14
  42. data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
  43. data/lib/capybara/spec/session/find_field_spec.rb +23 -21
  44. data/lib/capybara/spec/session/find_link_spec.rb +15 -14
  45. data/lib/capybara/spec/session/find_spec.rb +96 -91
  46. data/lib/capybara/spec/session/first_spec.rb +53 -55
  47. data/lib/capybara/spec/session/has_button_spec.rb +22 -24
  48. data/lib/capybara/spec/session/has_css_spec.rb +190 -205
  49. data/lib/capybara/spec/session/has_field_spec.rb +167 -169
  50. data/lib/capybara/spec/session/has_link_spec.rb +26 -29
  51. data/lib/capybara/spec/session/has_select_spec.rb +175 -176
  52. data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
  53. data/lib/capybara/spec/session/has_table_spec.rb +22 -26
  54. data/lib/capybara/spec/session/has_text_spec.rb +159 -132
  55. data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
  56. data/lib/capybara/spec/session/headers.rb +4 -17
  57. data/lib/capybara/spec/session/html_spec.rb +15 -0
  58. data/lib/capybara/spec/session/node_spec.rb +172 -82
  59. data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
  60. data/lib/capybara/spec/session/response_code.rb +4 -17
  61. data/lib/capybara/spec/session/save_page_spec.rb +46 -0
  62. data/lib/capybara/spec/session/screenshot.rb +8 -24
  63. data/lib/capybara/spec/session/select_spec.rb +100 -89
  64. data/lib/capybara/spec/session/source_spec.rb +12 -0
  65. data/lib/capybara/spec/session/text_spec.rb +15 -17
  66. data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
  67. data/lib/capybara/spec/session/unselect_spec.rb +57 -52
  68. data/lib/capybara/spec/session/visit_spec.rb +58 -60
  69. data/lib/capybara/spec/session/within_frame_spec.rb +24 -26
  70. data/lib/capybara/spec/session/within_spec.rb +119 -121
  71. data/lib/capybara/spec/session/within_window_spec.rb +29 -31
  72. data/lib/capybara/spec/spec_helper.rb +84 -0
  73. data/lib/capybara/spec/test_app.rb +5 -3
  74. data/lib/capybara/spec/views/form.erb +1 -0
  75. data/lib/capybara/spec/views/with_html.erb +6 -1
  76. data/lib/capybara/spec/views/with_js.erb +1 -0
  77. data/lib/capybara/version.rb +1 -1
  78. data/spec/basic_node_spec.rb +2 -2
  79. data/spec/capybara_spec.rb +9 -0
  80. data/spec/dsl_spec.rb +22 -10
  81. data/spec/rack_test_spec.rb +28 -23
  82. data/spec/result_spec.rb +51 -0
  83. data/spec/rspec/features_spec.rb +19 -0
  84. data/spec/rspec/matchers_spec.rb +6 -0
  85. data/spec/rspec_spec.rb +1 -1
  86. data/spec/selenium_spec.rb +11 -25
  87. data/spec/server_spec.rb +2 -2
  88. data/spec/spec_helper.rb +1 -46
  89. metadata +41 -98
  90. data/lib/capybara/spec/session.rb +0 -183
  91. data/lib/capybara/spec/session/javascript.rb +0 -290
  92. data/lib/capybara/util/save_and_open_page.rb +0 -45
  93. data/spec/save_and_open_page_spec.rb +0 -155
@@ -1,67 +1,72 @@
1
- shared_examples_for "unselect" do
2
- describe "#unselect" do
3
- before do
4
- @session.visit('/form')
1
+ Capybara::SpecHelper.spec "#unselect" do
2
+ before do
3
+ @session.visit('/form')
4
+ end
5
+
6
+ context "with multiple select" do
7
+ it "should unselect an option from a select box by id" do
8
+ @session.unselect('Commando', :from => 'form_underwear')
9
+ @session.click_button('awesome')
10
+ extract_results(@session)['underwear'].should include('Briefs', 'Boxerbriefs')
11
+ extract_results(@session)['underwear'].should_not include('Commando')
5
12
  end
6
13
 
7
- context "with multiple select" do
8
- it "should unselect an option from a select box by id" do
9
- @session.unselect('Commando', :from => 'form_underwear')
10
- @session.click_button('awesome')
11
- extract_results(@session)['underwear'].should include('Briefs', 'Boxerbriefs')
12
- extract_results(@session)['underwear'].should_not include('Commando')
13
- end
14
+ it "should unselect an option without a select box" do
15
+ @session.unselect('Commando')
16
+ @session.click_button('awesome')
17
+ extract_results(@session)['underwear'].should include('Briefs', 'Boxerbriefs')
18
+ extract_results(@session)['underwear'].should_not include('Commando')
19
+ end
14
20
 
15
- it "should unselect an option without a select box" do
16
- @session.unselect('Commando')
17
- @session.click_button('awesome')
18
- extract_results(@session)['underwear'].should include('Briefs', 'Boxerbriefs')
19
- extract_results(@session)['underwear'].should_not include('Commando')
20
- end
21
+ it "should unselect an option from a select box by label" do
22
+ @session.unselect('Commando', :from => 'Underwear')
23
+ @session.click_button('awesome')
24
+ extract_results(@session)['underwear'].should include('Briefs', 'Boxerbriefs')
25
+ extract_results(@session)['underwear'].should_not include('Commando')
26
+ end
21
27
 
22
- it "should unselect an option from a select box by label" do
23
- @session.unselect('Commando', :from => 'Underwear')
24
- @session.click_button('awesome')
25
- extract_results(@session)['underwear'].should include('Briefs', 'Boxerbriefs')
26
- extract_results(@session)['underwear'].should_not include('Commando')
27
- end
28
+ it "should favour exact matches to option labels" do
29
+ @session.unselect("Briefs", :from => 'Underwear')
30
+ @session.click_button('awesome')
31
+ extract_results(@session)['underwear'].should include('Commando', 'Boxerbriefs')
32
+ extract_results(@session)['underwear'].should_not include('Briefs')
33
+ end
28
34
 
29
- it "should favour exact matches to option labels" do
30
- @session.unselect("Briefs", :from => 'Underwear')
31
- @session.click_button('awesome')
32
- extract_results(@session)['underwear'].should include('Commando', 'Boxerbriefs')
33
- extract_results(@session)['underwear'].should_not include('Briefs')
34
- end
35
+ it "should escape quotes" do
36
+ @session.unselect("Frenchman's Pantalons", :from => 'Underwear')
37
+ @session.click_button('awesome')
38
+ extract_results(@session)['underwear'].should_not include("Frenchman's Pantalons")
39
+ end
35
40
 
36
- it "should escape quotes" do
37
- @session.unselect("Frenchman's Pantalons", :from => 'Underwear')
38
- @session.click_button('awesome')
39
- extract_results(@session)['underwear'].should_not include("Frenchman's Pantalons")
40
- end
41
+ it "casts to string" do
42
+ @session.unselect(:"Briefs", :from => :'Underwear')
43
+ @session.click_button('awesome')
44
+ extract_results(@session)['underwear'].should include('Commando', 'Boxerbriefs')
45
+ extract_results(@session)['underwear'].should_not include('Briefs')
41
46
  end
47
+ end
42
48
 
43
- context "with single select" do
44
- it "should raise an error" do
45
- running { @session.unselect("English", :from => 'form_locale') }.should raise_error(Capybara::UnselectNotAllowed)
46
- end
49
+ context "with single select" do
50
+ it "should raise an error" do
51
+ expect { @session.unselect("English", :from => 'form_locale') }.to raise_error(Capybara::UnselectNotAllowed)
47
52
  end
53
+ end
48
54
 
49
- context "with a locator that doesn't exist" do
50
- it "should raise an error" do
51
- msg = "Unable to find select box \"does not exist\""
52
- running do
53
- @session.unselect('foo', :from => 'does not exist')
54
- end.should raise_error(Capybara::ElementNotFound, msg)
55
- end
55
+ context "with a locator that doesn't exist" do
56
+ it "should raise an error" do
57
+ msg = "Unable to find select box \"does not exist\""
58
+ expect do
59
+ @session.unselect('foo', :from => 'does not exist')
60
+ end.to raise_error(Capybara::ElementNotFound, msg)
56
61
  end
62
+ end
57
63
 
58
- context "with an option that doesn't exist" do
59
- it "should raise an error" do
60
- msg = "Unable to find option \"Does not Exist\""
61
- running do
62
- @session.unselect('Does not Exist', :from => 'form_underwear')
63
- end.should raise_error(Capybara::ElementNotFound, msg)
64
- end
64
+ context "with an option that doesn't exist" do
65
+ it "should raise an error" do
66
+ msg = "Unable to find option \"Does not Exist\""
67
+ expect do
68
+ @session.unselect('Does not Exist', :from => 'form_underwear')
69
+ end.to raise_error(Capybara::ElementNotFound, msg)
65
70
  end
66
71
  end
67
72
  end
@@ -1,76 +1,74 @@
1
- shared_examples_for "visit" do
2
- describe '#visit' do
3
- it "should fetch a response from the driver with a relative url" do
4
- @session.visit('/')
5
- @session.body.should include('Hello world!')
6
- @session.visit('/foo')
7
- @session.body.should include('Another World')
8
- end
1
+ Capybara::SpecHelper.spec '#visit' do
2
+ it "should fetch a response from the driver with a relative url" do
3
+ @session.visit('/')
4
+ @session.should have_content('Hello world!')
5
+ @session.visit('/foo')
6
+ @session.should have_content('Another World')
7
+ end
9
8
 
10
- it "should fetch a response from the driver with an absolute url with a port" do
11
- # Preparation
12
- @session.visit('/')
13
- root_uri = URI.parse(@session.current_url)
9
+ it "should fetch a response from the driver with an absolute url with a port" do
10
+ # Preparation
11
+ @session.visit('/')
12
+ root_uri = URI.parse(@session.current_url)
14
13
 
15
- @session.visit("http://#{root_uri.host}:#{root_uri.port}/")
16
- @session.body.should include('Hello world!')
17
- @session.visit("http://#{root_uri.host}:#{root_uri.port}/foo")
18
- @session.body.should include('Another World')
19
- end
14
+ @session.visit("http://#{root_uri.host}:#{root_uri.port}/")
15
+ @session.should have_content('Hello world!')
16
+ @session.visit("http://#{root_uri.host}:#{root_uri.port}/foo")
17
+ @session.should have_content('Another World')
18
+ end
20
19
 
21
- context "when Capybara.always_include_port is true" do
20
+ context "when Capybara.always_include_port is true" do
22
21
 
23
- let(:root_uri) do
24
- @session.visit('/')
25
- URI.parse(@session.current_url)
26
- end
22
+ let(:root_uri) do
23
+ @session.visit('/')
24
+ URI.parse(@session.current_url)
25
+ end
27
26
 
28
- before(:each) do
29
- Capybara.always_include_port = true
30
- end
27
+ before(:each) do
28
+ Capybara.always_include_port = true
29
+ end
31
30
 
32
- after(:each) do
33
- Capybara.always_include_port = false
34
- end
31
+ after(:each) do
32
+ Capybara.always_include_port = false
33
+ end
35
34
 
36
- it "should fetch a response from the driver with an absolute url without a port" do
37
- @session.visit("http://#{root_uri.host}/")
38
- URI.parse(@session.current_url).port.should == root_uri.port
39
- @session.body.should include('Hello world!')
35
+ it "should fetch a response from the driver with an absolute url without a port" do
36
+ @session.visit("http://#{root_uri.host}/")
37
+ URI.parse(@session.current_url).port.should == root_uri.port
38
+ @session.should have_content('Hello world!')
40
39
 
41
- @session.visit("http://#{root_uri.host}/foo")
42
- URI.parse(@session.current_url).port.should == root_uri.port
43
- @session.body.should include('Another World')
44
- end
40
+ @session.visit("http://#{root_uri.host}/foo")
41
+ URI.parse(@session.current_url).port.should == root_uri.port
42
+ @session.should have_content('Another World')
45
43
  end
44
+ end
46
45
 
47
- it "should send no referer when visiting a page" do
48
- @session.visit '/get_referer'
49
- @session.body.should include 'No referer'
50
- end
46
+ it "should send no referer when visiting a page" do
47
+ @session.visit '/get_referer'
48
+ @session.should have_content 'No referer'
49
+ end
51
50
 
52
- it "should send no referer when visiting a second page" do
53
- @session.visit '/get_referer'
54
- @session.visit '/get_referer'
55
- @session.body.should include 'No referer'
56
- end
51
+ it "should send no referer when visiting a second page" do
52
+ @session.visit '/get_referer'
53
+ @session.visit '/get_referer'
54
+ @session.should have_content 'No referer'
55
+ end
57
56
 
58
- it "should send a referer when following a link" do
59
- @session.visit '/referer_base'
60
- @session.find('//a[@href="/get_referer"]').click
61
- @session.body.should match %r{http://.*/referer_base}
62
- end
57
+ it "should send a referer when following a link" do
58
+ @session.visit '/referer_base'
59
+ @session.find('//a[@href="/get_referer"]').click
60
+ @session.body.should match %r{http://.*/referer_base}
61
+ end
63
62
 
64
- it "should preserve the original referer URL when following a redirect" do
65
- @session.visit('/referer_base')
66
- @session.find('//a[@href="/redirect_to_get_referer"]').click
67
- @session.body.should match %r{http://.*/referer_base}
68
- end
63
+ it "should preserve the original referer URL when following a redirect" do
64
+ @session.visit('/referer_base')
65
+ @session.find('//a[@href="/redirect_to_get_referer"]').click
66
+ @session.body.should match %r{http://.*/referer_base}
67
+ end
69
68
 
70
- it "should send a referer when submitting a form" do
71
- @session.visit '/referer_base'
72
- @session.find('//input').click
73
- @session.body.should match %r{http://.*/referer_base}
74
- end
69
+ it "should send a referer when submitting a form" do
70
+ @session.visit '/referer_base'
71
+ @session.find('//input').click
72
+ @session.body.should match %r{http://.*/referer_base}
75
73
  end
76
74
  end
@@ -1,33 +1,31 @@
1
- shared_examples_for "session with frame support" do
2
- describe '#within_frame' do
3
- before(:each) do
4
- @session.visit('/within_frames')
5
- end
1
+ Capybara::SpecHelper.spec '#within_frame', :requires => [:frames] do
2
+ before(:each) do
3
+ @session.visit('/within_frames')
4
+ end
6
5
 
7
- it "should find the div in frameOne" do
8
- @session.within_frame("frameOne") do
9
- @session.find("//*[@id='divInFrameOne']").text.should eql 'This is the text of divInFrameOne'
10
- end
6
+ it "should find the div in frameOne" do
7
+ @session.within_frame("frameOne") do
8
+ @session.find("//*[@id='divInFrameOne']").text.should eql 'This is the text of divInFrameOne'
11
9
  end
12
- it "should find the div in FrameTwo" do
13
- @session.within_frame("frameTwo") do
14
- @session.find("//*[@id='divInFrameTwo']").text.should eql 'This is the text of divInFrameTwo'
15
- end
16
- end
17
- it "should find the text div in the main window after finding text in frameOne" do
18
- @session.within_frame("frameOne") do
19
- @session.find("//*[@id='divInFrameOne']").text.should eql 'This is the text of divInFrameOne'
20
- end
21
- @session.find("//*[@id='divInMainWindow']").text.should eql 'This is the text for divInMainWindow'
10
+ end
11
+ it "should find the div in FrameTwo" do
12
+ @session.within_frame("frameTwo") do
13
+ @session.find("//*[@id='divInFrameTwo']").text.should eql 'This is the text of divInFrameTwo'
22
14
  end
23
- it "should find the text div in the main window after finding text in frameTwo" do
24
- @session.within_frame("frameTwo") do
25
- @session.find("//*[@id='divInFrameTwo']").text.should eql 'This is the text of divInFrameTwo'
26
- end
27
- @session.find("//*[@id='divInMainWindow']").text.should eql 'This is the text for divInMainWindow'
15
+ end
16
+ it "should find the text div in the main window after finding text in frameOne" do
17
+ @session.within_frame("frameOne") do
18
+ @session.find("//*[@id='divInFrameOne']").text.should eql 'This is the text of divInFrameOne'
28
19
  end
29
- it "should return the result of executing the block" do
30
- @session.within_frame("frameOne") { "return value" }.should eql "return value"
20
+ @session.find("//*[@id='divInMainWindow']").text.should eql 'This is the text for divInMainWindow'
21
+ end
22
+ it "should find the text div in the main window after finding text in frameTwo" do
23
+ @session.within_frame("frameTwo") do
24
+ @session.find("//*[@id='divInFrameTwo']").text.should eql 'This is the text of divInFrameTwo'
31
25
  end
26
+ @session.find("//*[@id='divInMainWindow']").text.should eql 'This is the text for divInMainWindow'
27
+ end
28
+ it "should return the result of executing the block" do
29
+ @session.within_frame("frameOne") { "return value" }.should eql "return value"
32
30
  end
33
31
  end
@@ -1,167 +1,165 @@
1
- shared_examples_for "within" do
2
- describe '#within' do
3
- before do
4
- @session.visit('/with_scope')
1
+ Capybara::SpecHelper.spec '#within' do
2
+ before do
3
+ @session.visit('/with_scope')
4
+ end
5
+
6
+ context "with CSS selector" do
7
+ it "should click links in the given scope" do
8
+ @session.within(:css, "#for_bar li[contains('With Simple HTML')]") do
9
+ @session.click_link('Go')
10
+ end
11
+ @session.should have_content('Bar')
5
12
  end
6
13
 
7
- context "with CSS selector" do
8
- it "should click links in the given scope" do
9
- @session.within(:css, "#for_bar li[contains('With Simple HTML')]") do
10
- @session.click_link('Go')
11
- end
12
- @session.body.should include('Bar')
14
+ it "should assert content in the given scope" do
15
+ @session.within(:css, "#for_foo") do
16
+ @session.should_not have_content('First Name')
13
17
  end
18
+ @session.should have_content('First Name')
19
+ end
14
20
 
15
- it "should assert content in the given scope" do
16
- @session.within(:css, "#for_foo") do
17
- @session.should_not have_content('First Name')
18
- end
19
- @session.should have_content('First Name')
21
+ it "should accept additional options" do
22
+ @session.within(:css, "#for_bar li", :text => 'With Simple HTML') do
23
+ @session.click_link('Go')
20
24
  end
25
+ @session.should have_content('Bar')
26
+ end
27
+ end
21
28
 
22
- it "should accept additional options" do
23
- @session.within(:css, "#for_bar li", :text => 'With Simple HTML') do
24
- @session.click_link('Go')
25
- end
26
- @session.body.should include('Bar')
29
+ context "with XPath selector" do
30
+ it "should click links in the given scope" do
31
+ @session.within(:xpath, "//div[@id='for_bar']//li[contains(.,'With Simple HTML')]") do
32
+ @session.click_link('Go')
27
33
  end
34
+ @session.should have_content('Bar')
28
35
  end
36
+ end
29
37
 
30
- context "with XPath selector" do
31
- it "should click links in the given scope" do
32
- @session.within(:xpath, "//div[@id='for_bar']//li[contains(.,'With Simple HTML')]") do
33
- @session.click_link('Go')
34
- end
35
- @session.body.should include('Bar')
38
+ context "with the default selector" do
39
+ it "should use XPath" do
40
+ @session.within("//div[@id='for_bar']//li[contains(.,'With Simple HTML')]") do
41
+ @session.click_link('Go')
36
42
  end
43
+ @session.should have_content('Bar')
37
44
  end
45
+ end
38
46
 
39
- context "with the default selector" do
40
- it "should use XPath" do
41
- @session.within("//div[@id='for_bar']//li[contains(.,'With Simple HTML')]") do
42
- @session.click_link('Go')
43
- end
44
- @session.body.should include('Bar')
47
+ context "with Node rather than selector" do
48
+ it "should click links in the given scope" do
49
+ node_of_interest = @session.find(:css, "#for_bar li[contains('With Simple HTML')]")
50
+
51
+ @session.within(node_of_interest) do
52
+ @session.click_link('Go')
45
53
  end
54
+ @session.should have_content('Bar')
46
55
  end
56
+ end
47
57
 
48
- context "with Node rather than selector" do
49
- it "should click links in the given scope" do
50
- node_of_interest = @session.find(:css, "#for_bar li[contains('With Simple HTML')]")
58
+ context "with the default selector set to CSS" do
59
+ before { Capybara.default_selector = :css }
60
+ it "should use CSS" do
61
+ @session.within("#for_bar li[contains('With Simple HTML')]") do
62
+ @session.click_link('Go')
63
+ end
64
+ @session.should have_content('Bar')
65
+ end
66
+ after { Capybara.default_selector = :xpath }
67
+ end
51
68
 
52
- @session.within(node_of_interest) do
69
+ context "with nested scopes" do
70
+ it "should respect the inner scope" do
71
+ @session.within("//div[@id='for_bar']") do
72
+ @session.within(".//li[contains(.,'Bar')]") do
53
73
  @session.click_link('Go')
54
74
  end
55
- @session.body.should include('Bar')
56
75
  end
76
+ @session.should have_content('Another World')
57
77
  end
58
78
 
59
- context "with the default selector set to CSS" do
60
- before { Capybara.default_selector = :css }
61
- it "should use CSS" do
62
- @session.within("#for_bar li[contains('With Simple HTML')]") do
79
+ it "should respect the outer scope" do
80
+ @session.within("//div[@id='another_foo']") do
81
+ @session.within(".//li[contains(.,'With Simple HTML')]") do
63
82
  @session.click_link('Go')
64
83
  end
65
- @session.body.should include('Bar')
66
84
  end
67
- after { Capybara.default_selector = :xpath }
85
+ @session.should have_content('Hello world')
68
86
  end
87
+ end
69
88
 
70
- context "with nested scopes" do
71
- it "should respect the inner scope" do
72
- @session.within("//div[@id='for_bar']") do
73
- @session.within(".//li[contains(.,'Bar')]") do
74
- @session.click_link('Go')
75
- end
76
- end
77
- @session.body.should include('Another World')
89
+ it "should raise an error if the scope is not found on the page" do
90
+ expect do
91
+ @session.within("//div[@id='doesnotexist']") do
78
92
  end
93
+ end.to raise_error(Capybara::ElementNotFound)
94
+ end
79
95
 
80
- it "should respect the outer scope" do
81
- @session.within("//div[@id='another_foo']") do
82
- @session.within(".//li[contains(.,'With Simple HTML')]") do
83
- @session.click_link('Go')
84
- end
85
- end
86
- @session.body.should include('Hello world')
96
+ it "should restore the scope when an error is raised" do
97
+ expect do
98
+ @session.within("//div[@id='for_bar']") do
99
+ expect do
100
+ expect do
101
+ @session.within(".//div[@id='doesnotexist']") do
102
+ end
103
+ end.to raise_error(Capybara::ElementNotFound)
104
+ end.to_not change { @session.has_xpath?(".//div[@id='another_foo']") }.from(false)
87
105
  end
88
- end
89
-
90
- it "should raise an error if the scope is not found on the page" do
91
- running do
92
- @session.within("//div[@id='doesnotexist']") do
93
- end
94
- end.should raise_error(Capybara::ElementNotFound)
95
- end
106
+ end.to_not change { @session.has_xpath?(".//div[@id='another_foo']") }.from(true)
107
+ end
96
108
 
97
- it "should restore the scope when an error is raised" do
98
- running do
99
- @session.within("//div[@id='for_bar']") do
100
- running do
101
- running do
102
- @session.within(".//div[@id='doesnotexist']") do
103
- end
104
- end.should raise_error(Capybara::ElementNotFound)
105
- end.should_not change { @session.has_xpath?(".//div[@id='another_foo']") }.from(false)
106
- end
107
- end.should_not change { @session.has_xpath?(".//div[@id='another_foo']") }.from(true)
109
+ it "should fill in a field and click a button" do
110
+ @session.within("//li[contains(.,'Bar')]") do
111
+ @session.click_button('Go')
108
112
  end
109
-
110
- it "should fill in a field and click a button" do
111
- @session.within("//li[contains(.,'Bar')]") do
112
- @session.click_button('Go')
113
- end
114
- extract_results(@session)['first_name'].should == 'Peter'
115
- @session.visit('/with_scope')
116
- @session.within("//li[contains(.,'Bar')]") do
117
- @session.fill_in('First Name', :with => 'Dagobert')
118
- @session.click_button('Go')
119
- end
120
- extract_results(@session)['first_name'].should == 'Dagobert'
113
+ extract_results(@session)['first_name'].should == 'Peter'
114
+ @session.visit('/with_scope')
115
+ @session.within("//li[contains(.,'Bar')]") do
116
+ @session.fill_in('First Name', :with => 'Dagobert')
117
+ @session.click_button('Go')
121
118
  end
119
+ extract_results(@session)['first_name'].should == 'Dagobert'
122
120
  end
121
+ end
123
122
 
124
- describe '#within_fieldset' do
125
- before do
126
- @session.visit('/fieldsets')
127
- end
123
+ Capybara::SpecHelper.spec '#within_fieldset' do
124
+ before do
125
+ @session.visit('/fieldsets')
126
+ end
128
127
 
129
- it "should restrict scope to a fieldset given by id" do
130
- @session.within_fieldset("villain_fieldset") do
131
- @session.fill_in("Name", :with => 'Goldfinger')
132
- @session.click_button("Create")
133
- end
134
- extract_results(@session)['villain_name'].should == 'Goldfinger'
128
+ it "should restrict scope to a fieldset given by id" do
129
+ @session.within_fieldset("villain_fieldset") do
130
+ @session.fill_in("Name", :with => 'Goldfinger')
131
+ @session.click_button("Create")
135
132
  end
133
+ extract_results(@session)['villain_name'].should == 'Goldfinger'
134
+ end
136
135
 
137
- it "should restrict scope to a fieldset given by legend" do
138
- @session.within_fieldset("Villain") do
139
- @session.fill_in("Name", :with => 'Goldfinger')
140
- @session.click_button("Create")
141
- end
142
- extract_results(@session)['villain_name'].should == 'Goldfinger'
136
+ it "should restrict scope to a fieldset given by legend" do
137
+ @session.within_fieldset("Villain") do
138
+ @session.fill_in("Name", :with => 'Goldfinger')
139
+ @session.click_button("Create")
143
140
  end
141
+ extract_results(@session)['villain_name'].should == 'Goldfinger'
144
142
  end
143
+ end
145
144
 
146
- describe '#within_table' do
147
- before do
148
- @session.visit('/tables')
149
- end
145
+ Capybara::SpecHelper.spec '#within_table' do
146
+ before do
147
+ @session.visit('/tables')
148
+ end
150
149
 
151
- it "should restrict scope to a fieldset given by id" do
152
- @session.within_table("girl_table") do
153
- @session.fill_in("Name", :with => 'Christmas')
154
- @session.click_button("Create")
155
- end
156
- extract_results(@session)['girl_name'].should == 'Christmas'
150
+ it "should restrict scope to a fieldset given by id" do
151
+ @session.within_table("girl_table") do
152
+ @session.fill_in("Name", :with => 'Christmas')
153
+ @session.click_button("Create")
157
154
  end
155
+ extract_results(@session)['girl_name'].should == 'Christmas'
156
+ end
158
157
 
159
- it "should restrict scope to a fieldset given by legend" do
160
- @session.within_table("Villain") do
161
- @session.fill_in("Name", :with => 'Quantum')
162
- @session.click_button("Create")
163
- end
164
- extract_results(@session)['villain_name'].should == 'Quantum'
158
+ it "should restrict scope to a fieldset given by legend" do
159
+ @session.within_table("Villain") do
160
+ @session.fill_in("Name", :with => 'Quantum')
161
+ @session.click_button("Create")
165
162
  end
163
+ extract_results(@session)['villain_name'].should == 'Quantum'
166
164
  end
167
165
  end