capybara 1.1.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. data/{History.txt → History.md} +138 -0
  2. data/License.txt +22 -0
  3. data/README.md +850 -0
  4. data/lib/capybara/cucumber.rb +2 -5
  5. data/lib/capybara/driver/base.rb +6 -6
  6. data/lib/capybara/driver/node.rb +3 -2
  7. data/lib/capybara/dsl.rb +13 -124
  8. data/lib/capybara/helpers.rb +33 -0
  9. data/lib/capybara/node/actions.rb +16 -30
  10. data/lib/capybara/node/base.rb +56 -13
  11. data/lib/capybara/node/element.rb +18 -30
  12. data/lib/capybara/node/finders.rb +28 -90
  13. data/lib/capybara/node/matchers.rb +121 -73
  14. data/lib/capybara/node/simple.rb +13 -11
  15. data/lib/capybara/query.rb +78 -0
  16. data/lib/capybara/rack_test/browser.rb +27 -39
  17. data/lib/capybara/rack_test/driver.rb +13 -3
  18. data/lib/capybara/rack_test/node.rb +31 -2
  19. data/lib/capybara/result.rb +72 -0
  20. data/lib/capybara/rspec/features.rb +4 -1
  21. data/lib/capybara/rspec/matchers.rb +33 -63
  22. data/lib/capybara/rspec.rb +7 -4
  23. data/lib/capybara/selector.rb +97 -34
  24. data/lib/capybara/selenium/driver.rb +15 -62
  25. data/lib/capybara/selenium/node.rb +14 -21
  26. data/lib/capybara/server.rb +32 -27
  27. data/lib/capybara/session.rb +90 -50
  28. data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
  29. data/lib/capybara/spec/public/jquery-ui.js +791 -0
  30. data/lib/capybara/spec/public/jquery.js +9046 -0
  31. data/lib/capybara/spec/public/test.js +3 -0
  32. data/lib/capybara/spec/session/all_spec.rb +61 -59
  33. data/lib/capybara/spec/session/assert_selector.rb +123 -0
  34. data/lib/capybara/spec/session/attach_file_spec.rb +72 -55
  35. data/lib/capybara/spec/session/body_spec.rb +21 -0
  36. data/lib/capybara/spec/session/check_spec.rb +68 -48
  37. data/lib/capybara/spec/session/choose_spec.rb +32 -18
  38. data/lib/capybara/spec/session/click_button_spec.rb +263 -232
  39. data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -29
  40. data/lib/capybara/spec/session/click_link_spec.rb +96 -96
  41. data/lib/capybara/spec/session/current_url_spec.rb +88 -10
  42. data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
  43. data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
  44. data/lib/capybara/spec/session/fill_in_spec.rb +119 -103
  45. data/lib/capybara/spec/session/find_button_spec.rb +16 -14
  46. data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
  47. data/lib/capybara/spec/session/find_field_spec.rb +23 -21
  48. data/lib/capybara/spec/session/find_link_spec.rb +15 -14
  49. data/lib/capybara/spec/session/find_spec.rb +93 -115
  50. data/lib/capybara/spec/session/first_spec.rb +51 -85
  51. data/lib/capybara/spec/session/has_button_spec.rb +22 -24
  52. data/lib/capybara/spec/session/has_css_spec.rb +190 -205
  53. data/lib/capybara/spec/session/has_field_spec.rb +170 -144
  54. data/lib/capybara/spec/session/has_link_spec.rb +26 -29
  55. data/lib/capybara/spec/session/has_select_spec.rb +161 -109
  56. data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
  57. data/lib/capybara/spec/session/has_table_spec.rb +22 -88
  58. data/lib/capybara/spec/session/has_text_spec.rb +195 -0
  59. data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
  60. data/lib/capybara/spec/session/headers.rb +4 -17
  61. data/lib/capybara/spec/session/html_spec.rb +15 -0
  62. data/lib/capybara/spec/session/node_spec.rb +205 -0
  63. data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
  64. data/lib/capybara/spec/session/response_code.rb +4 -17
  65. data/lib/capybara/spec/session/save_page_spec.rb +46 -0
  66. data/lib/capybara/spec/session/screenshot.rb +13 -0
  67. data/lib/capybara/spec/session/select_spec.rb +99 -88
  68. data/lib/capybara/spec/session/source_spec.rb +12 -0
  69. data/lib/capybara/spec/session/text_spec.rb +15 -12
  70. data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
  71. data/lib/capybara/spec/session/unselect_spec.rb +69 -58
  72. data/lib/capybara/spec/session/visit_spec.rb +74 -0
  73. data/lib/capybara/spec/session/within_frame_spec.rb +31 -0
  74. data/lib/capybara/spec/session/within_spec.rb +118 -131
  75. data/lib/capybara/spec/session/within_window_spec.rb +38 -0
  76. data/lib/capybara/spec/spec_helper.rb +84 -0
  77. data/lib/capybara/spec/test_app.rb +32 -6
  78. data/lib/capybara/spec/views/form.erb +12 -10
  79. data/lib/capybara/spec/views/host_links.erb +2 -2
  80. data/lib/capybara/spec/views/tables.erb +6 -66
  81. data/lib/capybara/spec/views/with_html.erb +9 -4
  82. data/lib/capybara/spec/views/with_js.erb +11 -7
  83. data/lib/capybara/version.rb +1 -1
  84. data/lib/capybara.rb +125 -6
  85. data/spec/basic_node_spec.rb +17 -5
  86. data/spec/capybara_spec.rb +9 -0
  87. data/spec/dsl_spec.rb +31 -17
  88. data/spec/rack_test_spec.rb +157 -0
  89. data/spec/result_spec.rb +51 -0
  90. data/spec/rspec/features_spec.rb +19 -2
  91. data/spec/rspec/matchers_spec.rb +170 -89
  92. data/spec/rspec_spec.rb +1 -3
  93. data/spec/selenium_spec.rb +53 -0
  94. data/spec/server_spec.rb +37 -25
  95. data/spec/spec_helper.rb +1 -30
  96. metadata +39 -31
  97. data/README.rdoc +0 -722
  98. data/lib/capybara/spec/driver.rb +0 -301
  99. data/lib/capybara/spec/session/current_host_spec.rb +0 -68
  100. data/lib/capybara/spec/session/has_content_spec.rb +0 -106
  101. data/lib/capybara/spec/session/javascript.rb +0 -306
  102. data/lib/capybara/spec/session.rb +0 -154
  103. data/lib/capybara/util/save_and_open_page.rb +0 -44
  104. data/lib/capybara/util/timeout.rb +0 -27
  105. data/spec/driver/rack_test_driver_spec.rb +0 -89
  106. data/spec/driver/selenium_driver_spec.rb +0 -37
  107. data/spec/save_and_open_page_spec.rb +0 -155
  108. data/spec/session/rack_test_session_spec.rb +0 -55
  109. data/spec/session/selenium_session_spec.rb +0 -26
  110. data/spec/string_spec.rb +0 -77
  111. data/spec/timeout_spec.rb +0 -28
@@ -1,18 +1,20 @@
1
- shared_examples_for "find_by_id" do
2
- describe '#find_by_id' do
3
- before do
4
- @session.visit('/with_html')
5
- end
1
+ Capybara::SpecHelper.spec '#find_by_id' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ end
5
+
6
+ it "should find any element by id" do
7
+ @session.find_by_id('red').tag_name.should == 'a'
8
+ @session.find_by_id('hidden_via_ancestor').tag_name.should == 'div'
9
+ end
6
10
 
7
- it "should find any element by id" do
8
- @session.find_by_id('red').tag_name.should == 'a'
9
- @session.find_by_id('hidden_via_ancestor').tag_name.should == 'div'
10
- end
11
+ it "casts to string" do
12
+ @session.find_by_id(:'red').tag_name.should == 'a'
13
+ end
11
14
 
12
- it "should raise error if no element with id is found" do
13
- running do
14
- @session.find_by_id('nothing_with_this_id')
15
- end.should raise_error(Capybara::ElementNotFound)
16
- end
15
+ it "should raise error if no element with id is found" do
16
+ expect do
17
+ @session.find_by_id('nothing_with_this_id')
18
+ end.to raise_error(Capybara::ElementNotFound)
17
19
  end
18
20
  end
@@ -1,26 +1,28 @@
1
- shared_examples_for "find_field" do
2
- describe '#find_field' do
3
- before do
4
- @session.visit('/form')
5
- end
1
+ Capybara::SpecHelper.spec '#find_field' do
2
+ before do
3
+ @session.visit('/form')
4
+ end
6
5
 
7
- it "should find any field" do
8
- @session.find_field('Dog').value.should == 'dog'
9
- @session.find_field('form_description').text.should == 'Descriptive text goes here'
10
- @session.find_field('Region')[:name].should == 'form[region]'
11
- end
6
+ it "should find any field" do
7
+ @session.find_field('Dog').value.should == 'dog'
8
+ @session.find_field('form_description').text.should == 'Descriptive text goes here'
9
+ @session.find_field('Region')[:name].should == 'form[region]'
10
+ end
12
11
 
13
- it "should raise error if the field doesn't exist" do
14
- running do
15
- @session.find_field('Does not exist')
16
- end.should raise_error(Capybara::ElementNotFound)
17
- end
12
+ it "casts to string" do
13
+ @session.find_field(:'Dog').value.should == 'dog'
14
+ end
15
+
16
+ it "should raise error if the field doesn't exist" do
17
+ expect do
18
+ @session.find_field('Does not exist')
19
+ end.to raise_error(Capybara::ElementNotFound)
20
+ end
18
21
 
19
- it "should be aliased as 'field_labeled' for webrat compatibility" do
20
- @session.field_labeled('Dog').value.should == 'dog'
21
- running do
22
- @session.field_labeled('Does not exist')
23
- end.should raise_error(Capybara::ElementNotFound)
24
- end
22
+ it "should be aliased as 'field_labeled' for webrat compatibility" do
23
+ @session.field_labeled('Dog').value.should == 'dog'
24
+ expect do
25
+ @session.field_labeled('Does not exist')
26
+ end.to raise_error(Capybara::ElementNotFound)
25
27
  end
26
28
  end
@@ -1,19 +1,20 @@
1
- shared_examples_for "find_link" do
1
+ Capybara::SpecHelper.spec '#find_link' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ end
2
5
 
3
- describe '#find_link' do
4
- before do
5
- @session.visit('/with_html')
6
- end
6
+ it "should find any field" do
7
+ @session.find_link('foo').text.should == "ullamco"
8
+ @session.find_link('labore')[:href].should =~ %r(/with_simple_html$)
9
+ end
7
10
 
8
- it "should find any field" do
9
- @session.find_link('foo').text.should == "ullamco"
10
- @session.find_link('labore')[:href].should =~ %r(/with_simple_html$)
11
- end
11
+ it "casts to string" do
12
+ @session.find_link(:'foo').text.should == "ullamco"
13
+ end
12
14
 
13
- it "should raise error if the field doesn't exist" do
14
- running do
15
- @session.find_link('Does not exist')
16
- end.should raise_error(Capybara::ElementNotFound)
17
- end
15
+ it "should raise error if the field doesn't exist" do
16
+ expect do
17
+ @session.find_link('Does not exist')
18
+ end.to raise_error(Capybara::ElementNotFound)
18
19
  end
19
20
  end
@@ -1,148 +1,126 @@
1
- shared_examples_for "find" do
2
- describe '#find' do
3
- before do
4
- @session.visit('/with_html')
5
- end
1
+ Capybara::SpecHelper.spec '#find' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ end
6
5
 
7
- after do
8
- Capybara::Selector.remove(:monkey)
9
- end
6
+ after do
7
+ Capybara::Selector.remove(:monkey)
8
+ end
10
9
 
11
- it "should find the first element using the given locator" do
12
- @session.find('//h1').text.should == 'This is a test'
13
- @session.find("//input[@id='test_field']")[:value].should == 'monkey'
14
- end
10
+ it "should find the first element using the given locator" do
11
+ @session.find('//h1').text.should == 'This is a test'
12
+ @session.find("//input[@id='test_field']")[:value].should == 'monkey'
13
+ end
15
14
 
16
- it "should find the first element using the given locator and options" do
17
- @session.find('//a', :text => 'Redirect')[:id].should == 'red'
18
- @session.find(:css, 'a', :text => 'A link')[:title].should == 'twas a fine link'
19
- end
15
+ it "should find the first element using the given locator and options" do
16
+ @session.find('//a', :text => 'Redirect')[:id].should == 'red'
17
+ @session.find(:css, 'a', :text => 'A link came first')[:title].should == 'twas a fine link'
18
+ end
20
19
 
21
- describe 'the returned node' do
22
- it "should act like a session object" do
23
- @session.visit('/form')
24
- @form = @session.find(:css, '#get-form')
25
- @form.should have_field('Middle Name')
26
- @form.should have_no_field('Languages')
27
- @form.fill_in('Middle Name', :with => 'Monkey')
28
- @form.click_button('med')
29
- extract_results(@session)['middle_name'].should == 'Monkey'
30
- end
20
+ it "should raise an error if there are multiple matches" do
21
+ expect { @session.find('//a') }.to raise_error(Capybara::Ambiguous)
22
+ end
31
23
 
32
- it "should scope CSS selectors" do
33
- @session.find(:css, '#second').should have_no_css('h1')
34
- end
24
+ it "should wait for asynchronous load", :requires => [:js] do
25
+ @session.visit('/with_js')
26
+ @session.click_link('Click me')
27
+ @session.find(:css, "a#has-been-clicked").text.should include('Has been clicked')
28
+ end
35
29
 
36
- it "should have a reference to its parent if there is one" do
37
- @node = @session.find(:css, '#first')
38
- @node.parent.should == @node.session.document
39
- @node.find('a').parent.should == @node
40
- end
30
+ context "with frozen time", :requires => [:js] do
31
+ it "raises an error suggesting that Capybara is stuck in time" do
32
+ @session.visit('/with_js')
33
+ now = Time.now
34
+ Time.stub(:now).and_return(now)
35
+ expect { @session.find('//isnotthere') }.to raise_error(Capybara::FrozenInTime)
41
36
  end
37
+ end
42
38
 
43
- context "with css selectors" do
44
- it "should find the first element using the given locator" do
45
- @session.find(:css, 'h1').text.should == 'This is a test'
46
- @session.find(:css, "input[id='test_field']")[:value].should == 'monkey'
47
- end
39
+ context "with css selectors" do
40
+ it "should find the first element using the given locator" do
41
+ @session.find(:css, 'h1').text.should == 'This is a test'
42
+ @session.find(:css, "input[id='test_field']")[:value].should == 'monkey'
48
43
  end
44
+ end
49
45
 
50
- context "with id selectors" do
51
- it "should find the first element using the given locator" do
52
- @session.find(:id, 'john_monkey').text.should == 'Monkey John'
53
- @session.find(:id, 'red').text.should == 'Redirect'
54
- @session.find(:red).text.should == 'Redirect'
55
- end
46
+ context "with xpath selectors" do
47
+ it "should find the first element using the given locator" do
48
+ @session.find(:xpath, '//h1').text.should == 'This is a test'
49
+ @session.find(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
56
50
  end
51
+ end
57
52
 
58
- context "with xpath selectors" do
59
- it "should find the first element using the given locator" do
60
- @session.find(:xpath, '//h1').text.should == 'This is a test'
61
- @session.find(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
53
+ context "with custom selector" do
54
+ it "should use the custom selector" do
55
+ Capybara.add_selector(:monkey) do
56
+ xpath { |name| ".//*[@id='#{name}_monkey']" }
62
57
  end
58
+ @session.find(:monkey, 'john').text.should == 'Monkey John'
59
+ @session.find(:monkey, 'paul').text.should == 'Monkey Paul'
63
60
  end
61
+ end
64
62
 
65
- context "with custom selector" do
66
- it "should use the custom selector" do
67
- Capybara.add_selector(:monkey) do
68
- xpath { |name| ".//*[@id='#{name}_monkey']" }
69
- end
70
- @session.find(:monkey, 'john').text.should == 'Monkey John'
71
- @session.find(:monkey, 'paul').text.should == 'Monkey Paul'
63
+ context "with custom selector with :for option" do
64
+ it "should use the selector when it matches the :for option" do
65
+ Capybara.add_selector(:monkey) do
66
+ xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
67
+ match { |value| value.is_a?(Fixnum) }
72
68
  end
69
+ @session.find(:monkey, '2').text.should == 'Monkey Paul'
70
+ @session.find(1).text.should == 'Monkey John'
71
+ @session.find(2).text.should == 'Monkey Paul'
72
+ @session.find('//h1').text.should == 'This is a test'
73
73
  end
74
+ end
74
75
 
75
- context "with custom selector with :for option" do
76
- it "should use the selector when it matches the :for option" do
77
- Capybara.add_selector(:monkey) do
78
- xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
79
- match { |value| value.is_a?(Fixnum) }
80
- end
81
- @session.find(:monkey, '2').text.should == 'Monkey Paul'
82
- @session.find(1).text.should == 'Monkey John'
83
- @session.find(2).text.should == 'Monkey Paul'
84
- @session.find('//h1').text.should == 'This is a test'
76
+ context "with custom selector with custom filter" do
77
+ before do
78
+ Capybara.add_selector(:monkey) do
79
+ xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
80
+ filter(:name) { |node, name| node.text == name }
85
81
  end
86
82
  end
87
83
 
88
- context "with custom selector with failure_message option" do
89
- it "should raise an error with the failure message if the element is not found" do
90
- Capybara.add_selector(:monkey) do
91
- xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
92
- failure_message { |node, selector| node.all(".//*[contains(@id, 'monkey')]").map { |node| node.text }.sort.join(', ') }
93
- end
94
- running do
95
- @session.find(:monkey, '14').text.should == 'Monkey Paul'
96
- end.should raise_error(Capybara::ElementNotFound, "Monkey John, Monkey Paul")
97
- end
98
-
99
- it "should pass the selector as the second argument" do
100
- Capybara.add_selector(:monkey) do
101
- xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
102
- failure_message { |node, selector| selector.name.to_s + ': ' + selector.locator + ' - ' + node.all(".//*[contains(@id, 'monkey')]").map { |node| node.text }.sort.join(', ') }
103
- end
104
- running do
105
- @session.find(:monkey, '14').text.should == 'Monkey Paul'
106
- end.should raise_error(Capybara::ElementNotFound, "monkey: 14 - Monkey John, Monkey Paul")
107
- end
84
+ it "should find elements that match the filter" do
85
+ @session.find(:monkey, '1', :name => 'Monkey John').text.should == 'Monkey John'
86
+ @session.find(:monkey, '2', :name => 'Monkey Paul').text.should == 'Monkey Paul'
108
87
  end
109
88
 
110
- context "with css as default selector" do
111
- before { Capybara.default_selector = :css }
112
- it "should find the first element using the given locator" do
113
- @session.find('h1').text.should == 'This is a test'
114
- @session.find("input[id='test_field']")[:value].should == 'monkey'
115
- end
116
- after { Capybara.default_selector = :xpath }
89
+ it "should not find elements that don't match the filter" do
90
+ expect { @session.find(:monkey, '2', :name => 'Monkey John') }.to raise_error(Capybara::ElementNotFound)
91
+ expect { @session.find(:monkey, '1', :name => 'Monkey Paul') }.to raise_error(Capybara::ElementNotFound)
117
92
  end
93
+ end
118
94
 
119
- it "should raise ElementNotFound with specified fail message if nothing was found" do
120
- running do
121
- @session.find(:xpath, '//div[@id="nosuchthing"]', :message => 'arghh').should be_nil
122
- end.should raise_error(Capybara::ElementNotFound, "arghh")
95
+ context "with css as default selector" do
96
+ before { Capybara.default_selector = :css }
97
+ it "should find the first element using the given locator" do
98
+ @session.find('h1').text.should == 'This is a test'
99
+ @session.find("input[id='test_field']")[:value].should == 'monkey'
123
100
  end
101
+ after { Capybara.default_selector = :xpath }
102
+ end
124
103
 
125
- it "should raise ElementNotFound with a useful default message if nothing was found" do
126
- running do
127
- @session.find(:xpath, '//div[@id="nosuchthing"]').should be_nil
128
- end.should raise_error(Capybara::ElementNotFound, "Unable to find xpath \"//div[@id=\\\"nosuchthing\\\"]\"")
129
- end
104
+ it "should raise ElementNotFound with a useful default message if nothing was found" do
105
+ expect do
106
+ @session.find(:xpath, '//div[@id="nosuchthing"]').to be_nil
107
+ end.to raise_error(Capybara::ElementNotFound, "Unable to find xpath \"//div[@id=\\\"nosuchthing\\\"]\"")
108
+ end
130
109
 
131
- it "should accept an XPath instance and respect the order of paths" do
132
- @session.visit('/form')
133
- @xpath = XPath::HTML.fillable_field('Name')
134
- @session.find(@xpath).value.should == 'John Smith'
135
- end
110
+ it "should accept an XPath instance" do
111
+ @session.visit('/form')
112
+ @xpath = XPath::HTML.fillable_field('First Name')
113
+ @session.find(@xpath).value.should == 'John'
114
+ end
136
115
 
137
- context "within a scope" do
138
- before do
139
- @session.visit('/with_scope')
140
- end
116
+ context "within a scope" do
117
+ before do
118
+ @session.visit('/with_scope')
119
+ end
141
120
 
142
- it "should find the first element using the given locator" do
143
- @session.within(:xpath, "//div[@id='for_bar']") do
144
- @session.find('.//li').text.should =~ /With Simple HTML/
145
- end
121
+ it "should find the an element using the given locator" do
122
+ @session.within(:xpath, "//div[@id='for_bar']") do
123
+ @session.find('.//li[1]').text.should =~ /With Simple HTML/
146
124
  end
147
125
  end
148
126
  end
@@ -1,104 +1,70 @@
1
- shared_examples_for "first" do
2
- describe '#first' do
3
- before do
4
- @session.visit('/with_html')
5
- end
1
+ Capybara::SpecHelper.spec '#first' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ end
6
5
 
7
- it "should find the first element using the given locator" do
8
- @session.first('//h1').text.should == 'This is a test'
9
- @session.first("//input[@id='test_field']")[:value].should == 'monkey'
10
- end
6
+ it "should find the first element using the given locator" do
7
+ @session.first('//h1').text.should == 'This is a test'
8
+ @session.first("//input[@id='test_field']")[:value].should == 'monkey'
9
+ end
11
10
 
12
- it "should return nil when nothing was found" do
13
- @session.first('//div[@id="nosuchthing"]').should be_nil
14
- end
11
+ it "should return nil when nothing was found" do
12
+ @session.first('//div[@id="nosuchthing"]').should be_nil
13
+ end
15
14
 
16
- it "should accept an XPath instance" do
17
- @session.visit('/form')
18
- @xpath = XPath::HTML.fillable_field('Name')
19
- @session.first(@xpath).value.should == 'John Smith'
20
- end
15
+ it "should accept an XPath instance" do
16
+ @session.visit('/form')
17
+ @xpath = XPath::HTML.fillable_field('First Name')
18
+ @session.first(@xpath).value.should == 'John'
19
+ end
21
20
 
22
- context "with css selectors" do
23
- it "should find the first element using the given selector" do
24
- @session.first(:css, 'h1').text.should == 'This is a test'
25
- @session.first(:css, "input[id='test_field']")[:value].should == 'monkey'
26
- end
21
+ context "with css selectors" do
22
+ it "should find the first element using the given selector" do
23
+ @session.first(:css, 'h1').text.should == 'This is a test'
24
+ @session.first(:css, "input[id='test_field']")[:value].should == 'monkey'
27
25
  end
26
+ end
28
27
 
29
- context "with xpath selectors" do
30
- it "should find the first element using the given locator" do
31
- @session.first(:xpath, '//h1').text.should == 'This is a test'
32
- @session.first(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
33
- end
28
+ context "with xpath selectors" do
29
+ it "should find the first element using the given locator" do
30
+ @session.first(:xpath, '//h1').text.should == 'This is a test'
31
+ @session.first(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
34
32
  end
33
+ end
35
34
 
36
- context "with css as default selector" do
37
- before { Capybara.default_selector = :css }
38
- it "should find the first element using the given locator" do
39
- @session.first('h1').text.should == 'This is a test'
40
- @session.first("input[id='test_field']")[:value].should == 'monkey'
41
- end
42
- after { Capybara.default_selector = :xpath }
35
+ context "with css as default selector" do
36
+ before { Capybara.default_selector = :css }
37
+ it "should find the first element using the given locator" do
38
+ @session.first('h1').text.should == 'This is a test'
39
+ @session.first("input[id='test_field']")[:value].should == 'monkey'
43
40
  end
41
+ after { Capybara.default_selector = :xpath }
42
+ end
44
43
 
45
- context "with visible filter" do
46
- after { Capybara.ignore_hidden_elements = false }
47
- it "should only find visible nodes if true given" do
48
- @session.first(:css, "a#invisible").should_not be_nil
49
- @session.first(:css, "a#invisible", :visible => true).should be_nil
50
- Capybara.ignore_hidden_elements = true
51
- @session.first(:css, "a#invisible").should be_nil
52
- end
53
-
54
- it "should include invisible nodes if false given" do
55
- Capybara.ignore_hidden_elements = true
56
- @session.first(:css, "a#invisible", :visible => false).should_not be_nil
57
- @session.first(:css, "a#invisible").should be_nil
58
- end
44
+ context "with visible filter" do
45
+ after { Capybara.ignore_hidden_elements = false }
46
+ it "should only find visible nodes if true given" do
47
+ @session.first(:css, "a#invisible").should_not be_nil
48
+ @session.first(:css, "a#invisible", :visible => true).should be_nil
49
+ Capybara.ignore_hidden_elements = true
50
+ @session.first(:css, "a#invisible").should be_nil
59
51
  end
60
52
 
61
- context "with prefer visible elements" do
62
- it "should find invisible elements if no visible element exists" do
63
- @session.first(:css, 'a#invisible')[:id].should == 'invisible'
64
- end
65
-
66
- it "should prefer visible elements over invisible elements" do
67
- @session.first(:css, 'a.visibility')[:id].should == 'visible'
68
- end
69
-
70
- it "should return the first invisible element if no visible elements exist" do
71
- @session.first(:css, 'a.hidden')[:id].should == 'first_invisble'
72
- end
73
-
74
- it "find visible links normally" do
75
- @session.first(:css, 'a#visible')[:id].should == 'visible'
76
- end
53
+ it "should include invisible nodes if false given" do
54
+ Capybara.ignore_hidden_elements = true
55
+ @session.first(:css, "a#invisible", :visible => false).should_not be_nil
56
+ @session.first(:css, "a#invisible").should be_nil
77
57
  end
58
+ end
78
59
 
79
- context "without prefer visible elements" do
80
- before { Capybara.prefer_visible_elements = false }
81
-
82
- it "should find invisible elements if no visible element exists" do
83
- @session.first(:css, 'a#invisible')[:id].should == 'invisible'
84
- end
85
-
86
- it "should not prefer visible elements over invisible elements" do
87
- @session.first(:css, 'a.visibility')[:id].should == 'invisible'
88
- end
89
-
90
- after { Capybara.prefer_visible_elements = true }
60
+ context "within a scope" do
61
+ before do
62
+ @session.visit('/with_scope')
91
63
  end
92
64
 
93
- context "within a scope" do
94
- before do
95
- @session.visit('/with_scope')
96
- end
97
-
98
- it "should find the first element using the given locator" do
99
- @session.within(:xpath, "//div[@id='for_bar']") do
100
- @session.first('.//form').should_not be_nil
101
- end
65
+ it "should find the first element using the given locator" do
66
+ @session.within(:xpath, "//div[@id='for_bar']") do
67
+ @session.first('.//form').should_not be_nil
102
68
  end
103
69
  end
104
70
  end
@@ -1,32 +1,30 @@
1
- shared_examples_for "has_button" do
2
- describe '#has_button?' do
3
- before do
4
- @session.visit('/form')
5
- end
1
+ Capybara::SpecHelper.spec '#has_button?' do
2
+ before do
3
+ @session.visit('/form')
4
+ end
6
5
 
7
- it "should be true if the given button is on the page" do
8
- @session.should have_button('med')
9
- @session.should have_button('crap321')
10
- end
6
+ it "should be true if the given button is on the page" do
7
+ @session.should have_button('med')
8
+ @session.should have_button('crap321')
9
+ @session.should have_button(:'crap321')
10
+ end
11
11
 
12
- it "should be false if the given button is not on the page" do
13
- @session.should_not have_button('monkey')
14
- end
12
+ it "should be false if the given button is not on the page" do
13
+ @session.should_not have_button('monkey')
15
14
  end
15
+ end
16
16
 
17
- describe '#has_no_button?' do
18
- before do
19
- @session.visit('/form')
20
- end
17
+ Capybara::SpecHelper.spec '#has_no_button?' do
18
+ before do
19
+ @session.visit('/form')
20
+ end
21
21
 
22
- it "should be true if the given button is on the page" do
23
- @session.should_not have_no_button('med')
24
- @session.should_not have_no_button('crap321')
25
- end
22
+ it "should be true if the given button is on the page" do
23
+ @session.should_not have_no_button('med')
24
+ @session.should_not have_no_button('crap321')
25
+ end
26
26
 
27
- it "should be false if the given button is not on the page" do
28
- @session.should have_no_button('monkey')
29
- end
27
+ it "should be false if the given button is not on the page" do
28
+ @session.should have_no_button('monkey')
30
29
  end
31
30
  end
32
-