capybara 2.2.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +26 -0
  3. data/README.md +36 -14
  4. data/lib/capybara.rb +6 -3
  5. data/lib/capybara/driver/base.rb +37 -1
  6. data/lib/capybara/driver/node.rb +10 -2
  7. data/lib/capybara/helpers.rb +21 -13
  8. data/lib/capybara/node/base.rb +12 -7
  9. data/lib/capybara/node/element.rb +17 -1
  10. data/lib/capybara/node/finders.rb +22 -1
  11. data/lib/capybara/node/matchers.rb +26 -5
  12. data/lib/capybara/node/simple.rb +9 -2
  13. data/lib/capybara/rack_test/css_handlers.rb +3 -1
  14. data/lib/capybara/rack_test/form.rb +3 -2
  15. data/lib/capybara/rack_test/node.rb +3 -3
  16. data/lib/capybara/rspec.rb +1 -0
  17. data/lib/capybara/rspec/features.rb +2 -1
  18. data/lib/capybara/rspec/matchers.rb +50 -5
  19. data/lib/capybara/selenium/driver.rb +76 -12
  20. data/lib/capybara/selenium/node.rb +8 -0
  21. data/lib/capybara/server.rb +1 -1
  22. data/lib/capybara/session.rb +234 -29
  23. data/lib/capybara/spec/public/jquery.js +1 -1
  24. data/lib/capybara/spec/public/test.js +7 -0
  25. data/lib/capybara/spec/session/all_spec.rb +88 -17
  26. data/lib/capybara/spec/session/assert_selector.rb +6 -0
  27. data/lib/capybara/spec/session/attach_file_spec.rb +15 -15
  28. data/lib/capybara/spec/session/body_spec.rb +4 -4
  29. data/lib/capybara/spec/session/check_spec.rb +16 -16
  30. data/lib/capybara/spec/session/choose_spec.rb +5 -5
  31. data/lib/capybara/spec/session/click_button_spec.rb +93 -84
  32. data/lib/capybara/spec/session/click_link_or_button_spec.rb +8 -8
  33. data/lib/capybara/spec/session/click_link_spec.rb +26 -19
  34. data/lib/capybara/spec/session/current_scope_spec.rb +3 -3
  35. data/lib/capybara/spec/session/current_url_spec.rb +8 -8
  36. data/lib/capybara/spec/session/evaluate_script_spec.rb +1 -1
  37. data/lib/capybara/spec/session/execute_script_spec.rb +2 -2
  38. data/lib/capybara/spec/session/fill_in_spec.rb +22 -22
  39. data/lib/capybara/spec/session/find_button_spec.rb +4 -4
  40. data/lib/capybara/spec/session/find_by_id_spec.rb +3 -3
  41. data/lib/capybara/spec/session/find_field_spec.rb +7 -7
  42. data/lib/capybara/spec/session/find_link_spec.rb +4 -4
  43. data/lib/capybara/spec/session/find_spec.rb +46 -46
  44. data/lib/capybara/spec/session/first_spec.rb +23 -23
  45. data/lib/capybara/spec/session/go_back_spec.rb +3 -3
  46. data/lib/capybara/spec/session/go_forward_spec.rb +4 -4
  47. data/lib/capybara/spec/session/has_button_spec.rb +13 -13
  48. data/lib/capybara/spec/session/has_css_spec.rb +87 -87
  49. data/lib/capybara/spec/session/has_field_spec.rb +87 -87
  50. data/lib/capybara/spec/session/has_link_spec.rb +11 -11
  51. data/lib/capybara/spec/session/has_select_spec.rb +58 -58
  52. data/lib/capybara/spec/session/has_selector_spec.rb +48 -48
  53. data/lib/capybara/spec/session/has_table_spec.rb +7 -7
  54. data/lib/capybara/spec/session/has_text_spec.rb +73 -73
  55. data/lib/capybara/spec/session/has_title_spec.rb +10 -10
  56. data/lib/capybara/spec/session/has_xpath_spec.rb +44 -44
  57. data/lib/capybara/spec/session/headers.rb +1 -1
  58. data/lib/capybara/spec/session/html_spec.rb +9 -9
  59. data/lib/capybara/spec/session/node_spec.rb +81 -65
  60. data/lib/capybara/spec/session/reset_session_spec.rb +15 -15
  61. data/lib/capybara/spec/session/response_code.rb +1 -1
  62. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +46 -0
  63. data/lib/capybara/spec/session/save_page_spec.rb +9 -9
  64. data/lib/capybara/spec/session/{screenshot.rb → screenshot_spec.rb} +4 -2
  65. data/lib/capybara/spec/session/select_spec.rb +22 -22
  66. data/lib/capybara/spec/session/text_spec.rb +15 -10
  67. data/lib/capybara/spec/session/title_spec.rb +2 -2
  68. data/lib/capybara/spec/session/uncheck_spec.rb +7 -7
  69. data/lib/capybara/spec/session/unselect_spec.rb +14 -14
  70. data/lib/capybara/spec/session/visit_spec.rb +24 -17
  71. data/lib/capybara/spec/session/window/become_closed_spec.rb +84 -0
  72. data/lib/capybara/spec/session/window/current_window_spec.rb +25 -0
  73. data/lib/capybara/spec/session/window/open_new_window_spec.rb +28 -0
  74. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +114 -0
  75. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +83 -0
  76. data/lib/capybara/spec/session/window/window_spec.rb +141 -0
  77. data/lib/capybara/spec/session/window/windows_spec.rb +31 -0
  78. data/lib/capybara/spec/session/window/within_window_spec.rb +188 -0
  79. data/lib/capybara/spec/session/within_frame_spec.rb +9 -9
  80. data/lib/capybara/spec/session/within_spec.rb +16 -16
  81. data/lib/capybara/spec/spec_helper.rb +14 -4
  82. data/lib/capybara/spec/views/form.erb +7 -0
  83. data/lib/capybara/spec/views/popup_one.erb +1 -1
  84. data/lib/capybara/spec/views/popup_two.erb +1 -1
  85. data/lib/capybara/spec/views/with_js.erb +2 -0
  86. data/lib/capybara/spec/views/with_windows.erb +38 -0
  87. data/lib/capybara/version.rb +1 -1
  88. data/lib/capybara/window.rb +123 -0
  89. data/spec/basic_node_spec.rb +32 -32
  90. data/spec/capybara_spec.rb +6 -7
  91. data/spec/dsl_spec.rb +48 -48
  92. data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -2
  93. data/spec/fixtures/selenium_driver_rspec_success.rb +2 -2
  94. data/spec/rack_test_spec.rb +33 -19
  95. data/spec/result_spec.rb +13 -13
  96. data/spec/rspec/features_spec.rb +20 -15
  97. data/spec/rspec/matchers_spec.rb +109 -109
  98. data/spec/rspec_spec.rb +10 -10
  99. data/spec/selenium_spec.rb +31 -6
  100. data/spec/selenium_spec_chrome.rb +2 -2
  101. data/spec/server_spec.rb +13 -13
  102. metadata +51 -62
  103. checksums.yaml.gz.sig +0 -0
  104. data.tar.gz.sig +0 -0
  105. data/lib/capybara/spec/session/within_window_spec.rb +0 -45
  106. data/lib/capybara/spec/views/within_popups.erb +0 -25
  107. metadata.gz.sig +0 -0
@@ -4,11 +4,11 @@ Capybara::SpecHelper.spec '#find_by_id' do
4
4
  end
5
5
 
6
6
  it "should find any element by id" do
7
- @session.find_by_id('red').tag_name.should == 'a'
7
+ expect(@session.find_by_id('red').tag_name).to eq('a')
8
8
  end
9
9
 
10
10
  it "casts to string" do
11
- @session.find_by_id(:'red').tag_name.should == 'a'
11
+ expect(@session.find_by_id(:'red').tag_name).to eq('a')
12
12
  end
13
13
 
14
14
  it "should raise error if no element with id is found" do
@@ -19,7 +19,7 @@ Capybara::SpecHelper.spec '#find_by_id' do
19
19
 
20
20
  context "with :visible option" do
21
21
  it "finds invisible elements when `false`" do
22
- @session.find_by_id("hidden_via_ancestor", :visible => false).text(:all).should =~ /with hidden ancestor/
22
+ expect(@session.find_by_id("hidden_via_ancestor", :visible => false).text(:all)).to match(/with hidden ancestor/)
23
23
  end
24
24
 
25
25
  it "finds invisible elements when `false`" do
@@ -4,13 +4,13 @@ Capybara::SpecHelper.spec '#find_field' do
4
4
  end
5
5
 
6
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]'
7
+ expect(@session.find_field('Dog').value).to eq('dog')
8
+ expect(@session.find_field('form_description').text).to eq('Descriptive text goes here')
9
+ expect(@session.find_field('Region')[:name]).to eq('form[region]')
10
10
  end
11
11
 
12
12
  it "casts to string" do
13
- @session.find_field(:'Dog').value.should == 'dog'
13
+ expect(@session.find_field(:'Dog').value).to eq('dog')
14
14
  end
15
15
 
16
16
  it "should raise error if the field doesn't exist" do
@@ -20,7 +20,7 @@ Capybara::SpecHelper.spec '#find_field' do
20
20
  end
21
21
 
22
22
  it "should be aliased as 'field_labeled' for webrat compatibility" do
23
- @session.field_labeled('Dog').value.should == 'dog'
23
+ expect(@session.field_labeled('Dog').value).to eq('dog')
24
24
  expect do
25
25
  @session.field_labeled('Does not exist')
26
26
  end.to raise_error(Capybara::ElementNotFound)
@@ -28,7 +28,7 @@ Capybara::SpecHelper.spec '#find_field' do
28
28
 
29
29
  context "with :exact option" do
30
30
  it "should accept partial matches when false" do
31
- @session.find_field("Explanation", :exact => false)[:name].should == "form[name_explanation]"
31
+ expect(@session.find_field("Explanation", :exact => false)[:name]).to eq("form[name_explanation]")
32
32
  end
33
33
 
34
34
  it "should not accept partial matches when true" do
@@ -40,7 +40,7 @@ Capybara::SpecHelper.spec '#find_field' do
40
40
 
41
41
  context "with :disabled option" do
42
42
  it "should find disabled fields when true" do
43
- @session.find_field("Disabled Checkbox", :disabled => true)[:name].should == "form[disabled_checkbox]"
43
+ expect(@session.find_field("Disabled Checkbox", :disabled => true)[:name]).to eq("form[disabled_checkbox]")
44
44
  end
45
45
 
46
46
  it "should not find disabled fields when false" do
@@ -4,12 +4,12 @@ Capybara::SpecHelper.spec '#find_link' do
4
4
  end
5
5
 
6
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$)
7
+ expect(@session.find_link('foo').text).to eq("ullamco")
8
+ expect(@session.find_link('labore')[:href]).to match %r(/with_simple_html$)
9
9
  end
10
10
 
11
11
  it "casts to string" do
12
- @session.find_link(:'foo').text.should == "ullamco"
12
+ expect(@session.find_link(:'foo').text).to eq("ullamco")
13
13
  end
14
14
 
15
15
  it "should raise error if the field doesn't exist" do
@@ -20,7 +20,7 @@ Capybara::SpecHelper.spec '#find_link' do
20
20
 
21
21
  context "with :exact option" do
22
22
  it "should accept partial matches when false" do
23
- @session.find_link('abo', :exact => false).text.should == "labore"
23
+ expect(@session.find_link('abo', :exact => false).text).to eq("labore")
24
24
  end
25
25
 
26
26
  it "should not accept partial matches when true" do
@@ -8,13 +8,13 @@ Capybara::SpecHelper.spec '#find' do
8
8
  end
9
9
 
10
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'
11
+ expect(@session.find('//h1').text).to eq('This is a test')
12
+ expect(@session.find("//input[@id='test_field']")[:value]).to eq('monkey')
13
13
  end
14
14
 
15
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'
16
+ expect(@session.find('//a', :text => 'Redirect')[:id]).to eq('red')
17
+ expect(@session.find(:css, 'a', :text => 'A link came first')[:title]).to eq('twas a fine link')
18
18
  end
19
19
 
20
20
  it "should raise an error if there are multiple matches" do
@@ -24,12 +24,12 @@ Capybara::SpecHelper.spec '#find' do
24
24
  it "should wait for asynchronous load", :requires => [:js] do
25
25
  @session.visit('/with_js')
26
26
  @session.click_link('Click me')
27
- @session.find(:css, "a#has-been-clicked").text.should include('Has been clicked')
27
+ expect(@session.find(:css, "a#has-been-clicked").text).to include('Has been clicked')
28
28
  end
29
29
 
30
30
  context "with :text option" do
31
31
  it "casts text's argument to string" do
32
- @session.find(:css, '.number', text: 42).should have_content("42")
32
+ expect(@session.find(:css, '.number', text: 42)).to have_content("42")
33
33
  end
34
34
  end
35
35
 
@@ -53,7 +53,7 @@ Capybara::SpecHelper.spec '#find' do
53
53
  it "should find element if it appears before given wait duration" do
54
54
  @session.visit('/with_js')
55
55
  @session.click_link('Click me')
56
- @session.find(:css, "a#has-been-clicked", :wait => 0.9).text.should include('Has been clicked')
56
+ expect(@session.find(:css, "a#has-been-clicked", :wait => 0.9).text).to include('Has been clicked')
57
57
  end
58
58
  end
59
59
 
@@ -61,26 +61,26 @@ Capybara::SpecHelper.spec '#find' do
61
61
  it "raises an error suggesting that Capybara is stuck in time" do
62
62
  @session.visit('/with_js')
63
63
  now = Time.now
64
- Time.stub(:now).and_return(now)
64
+ allow(Time).to receive(:now).and_return(now)
65
65
  expect { @session.find('//isnotthere') }.to raise_error(Capybara::FrozenInTime)
66
66
  end
67
67
  end
68
68
 
69
69
  context "with css selectors" do
70
70
  it "should find the first element using the given locator" do
71
- @session.find(:css, 'h1').text.should == 'This is a test'
72
- @session.find(:css, "input[id='test_field']")[:value].should == 'monkey'
71
+ expect(@session.find(:css, 'h1').text).to eq('This is a test')
72
+ expect(@session.find(:css, "input[id='test_field']")[:value]).to eq('monkey')
73
73
  end
74
74
 
75
75
  it "should support pseudo selectors" do
76
- @session.find(:css, 'input:disabled').value.should == 'This is disabled'
76
+ expect(@session.find(:css, 'input:disabled').value).to eq('This is disabled')
77
77
  end
78
78
  end
79
79
 
80
80
  context "with xpath selectors" do
81
81
  it "should find the first element using the given locator" do
82
- @session.find(:xpath, '//h1').text.should == 'This is a test'
83
- @session.find(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
82
+ expect(@session.find(:xpath, '//h1').text).to eq('This is a test')
83
+ expect(@session.find(:xpath, "//input[@id='test_field']")[:value]).to eq('monkey')
84
84
  end
85
85
  end
86
86
 
@@ -89,8 +89,8 @@ Capybara::SpecHelper.spec '#find' do
89
89
  Capybara.add_selector(:beatle) do
90
90
  xpath { |name| ".//*[@id='#{name}']" }
91
91
  end
92
- @session.find(:beatle, 'john').text.should == 'John'
93
- @session.find(:beatle, 'paul').text.should == 'Paul'
92
+ expect(@session.find(:beatle, 'john').text).to eq('John')
93
+ expect(@session.find(:beatle, 'paul').text).to eq('Paul')
94
94
  end
95
95
  end
96
96
 
@@ -100,10 +100,10 @@ Capybara::SpecHelper.spec '#find' do
100
100
  xpath { |num| ".//*[contains(@class, 'beatle')][#{num}]" }
101
101
  match { |value| value.is_a?(Fixnum) }
102
102
  end
103
- @session.find(:beatle, '2').text.should == 'Paul'
104
- @session.find(1).text.should == 'John'
105
- @session.find(2).text.should == 'Paul'
106
- @session.find('//h1').text.should == 'This is a test'
103
+ expect(@session.find(:beatle, '2').text).to eq('Paul')
104
+ expect(@session.find(1).text).to eq('John')
105
+ expect(@session.find(2).text).to eq('Paul')
106
+ expect(@session.find('//h1').text).to eq('This is a test')
107
107
  end
108
108
  end
109
109
 
@@ -116,13 +116,13 @@ Capybara::SpecHelper.spec '#find' do
116
116
  end
117
117
 
118
118
  it "should find elements that match the filter" do
119
- @session.find(:beatle, 'Paul', :type => 'drummer').text.should == 'Paul'
120
- @session.find(:beatle, 'Ringo', :type => 'drummer').text.should == 'Ringo'
119
+ expect(@session.find(:beatle, 'Paul', :type => 'drummer').text).to eq('Paul')
120
+ expect(@session.find(:beatle, 'Ringo', :type => 'drummer').text).to eq('Ringo')
121
121
  end
122
122
 
123
123
  it "ignores filter when it is not given" do
124
- @session.find(:beatle, 'Paul').text.should == 'Paul'
125
- @session.find(:beatle, 'John').text.should == 'John'
124
+ expect(@session.find(:beatle, 'Paul').text).to eq('Paul')
125
+ expect(@session.find(:beatle, 'John').text).to eq('John')
126
126
  end
127
127
 
128
128
  it "should not find elements that don't match the filter" do
@@ -140,12 +140,12 @@ Capybara::SpecHelper.spec '#find' do
140
140
  end
141
141
 
142
142
  it "should find elements that match the filter" do
143
- @session.find(:beatle, 'Paul', :type => 'drummer').text.should == 'Paul'
144
- @session.find(:beatle, 'Ringo', :type => 'drummer').text.should == 'Ringo'
143
+ expect(@session.find(:beatle, 'Paul', :type => 'drummer').text).to eq('Paul')
144
+ expect(@session.find(:beatle, 'Ringo', :type => 'drummer').text).to eq('Ringo')
145
145
  end
146
146
 
147
147
  it "should use default value when filter is not given" do
148
- @session.find(:beatle, 'Paul').text.should == 'Paul'
148
+ expect(@session.find(:beatle, 'Paul').text).to eq('Paul')
149
149
  expect { @session.find(:beatle, 'John') }.to raise_error(Capybara::ElementNotFound)
150
150
  end
151
151
 
@@ -158,8 +158,8 @@ Capybara::SpecHelper.spec '#find' do
158
158
  context "with css as default selector" do
159
159
  before { Capybara.default_selector = :css }
160
160
  it "should find the first element using the given locator" do
161
- @session.find('h1').text.should == 'This is a test'
162
- @session.find("input[id='test_field']")[:value].should == 'monkey'
161
+ expect(@session.find('h1').text).to eq('This is a test')
162
+ expect(@session.find("input[id='test_field']")[:value]).to eq('monkey')
163
163
  end
164
164
  after { Capybara.default_selector = :xpath }
165
165
  end
@@ -173,20 +173,20 @@ Capybara::SpecHelper.spec '#find' do
173
173
  it "should accept an XPath instance" do
174
174
  @session.visit('/form')
175
175
  @xpath = XPath::HTML.fillable_field('First Name')
176
- @session.find(@xpath).value.should == 'John'
176
+ expect(@session.find(@xpath).value).to eq('John')
177
177
  end
178
178
 
179
179
  context "with :exact option" do
180
180
  it "matches exactly when true" do
181
- @session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], :exact => true).value.should == "monkey"
181
+ expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], :exact => true).value).to eq("monkey")
182
182
  expect do
183
183
  @session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], :exact => true)
184
184
  end.to raise_error(Capybara::ElementNotFound)
185
185
  end
186
186
 
187
187
  it "matches loosely when false" do
188
- @session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], :exact => false).value.should == "monkey"
189
- @session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], :exact => false).value.should == "monkey"
188
+ expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], :exact => false).value).to eq("monkey")
189
+ expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], :exact => false).value).to eq("monkey")
190
190
  end
191
191
 
192
192
  it "defaults to `Capybara.exact`" do
@@ -212,7 +212,7 @@ Capybara::SpecHelper.spec '#find' do
212
212
  end.to raise_error(Capybara::Ambiguous)
213
213
  end
214
214
  it "returns the element if there is only one" do
215
- @session.find(:css, ".singular", :match => :one).text.should == "singular"
215
+ expect(@session.find(:css, ".singular", :match => :one).text).to eq("singular")
216
216
  end
217
217
  it "raises an error if there is no match" do
218
218
  expect do
@@ -223,7 +223,7 @@ Capybara::SpecHelper.spec '#find' do
223
223
 
224
224
  context "when set to `first`" do
225
225
  it "returns the first matched element" do
226
- @session.find(:css, ".multiple", :match => :first).text.should == "multiple one"
226
+ expect(@session.find(:css, ".multiple", :match => :first).text).to eq("multiple one")
227
227
  end
228
228
  it "raises an error if there is no match" do
229
229
  expect do
@@ -241,7 +241,7 @@ Capybara::SpecHelper.spec '#find' do
241
241
  end
242
242
  it "finds a single exact match when there also are inexact matches" do
243
243
  result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :match => :smart, :exact => false)
244
- result.text.should == "almost singular"
244
+ expect(result.text).to eq("almost singular")
245
245
  end
246
246
  it "raises an error when there are multiple inexact matches" do
247
247
  expect do
@@ -250,7 +250,7 @@ Capybara::SpecHelper.spec '#find' do
250
250
  end
251
251
  it "finds a single inexact match" do
252
252
  result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :match => :smart, :exact => false)
253
- result.text.should == "almost singular but not quite"
253
+ expect(result.text).to eq("almost singular but not quite")
254
254
  end
255
255
  it "raises an error if there is no match" do
256
256
  expect do
@@ -267,7 +267,7 @@ Capybara::SpecHelper.spec '#find' do
267
267
  end
268
268
  it "finds a single exact match when there also are inexact matches" do
269
269
  result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :match => :smart, :exact => true)
270
- result.text.should == "almost singular"
270
+ expect(result.text).to eq("almost singular")
271
271
  end
272
272
  it "raises an error when there are multiple inexact matches" do
273
273
  expect do
@@ -291,19 +291,19 @@ Capybara::SpecHelper.spec '#find' do
291
291
  context "and `exact` set to `false`" do
292
292
  it "picks the first one when there are multiple exact matches" do
293
293
  result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :match => :prefer_exact, :exact => false)
294
- result.text.should == "multiple one"
294
+ expect(result.text).to eq("multiple one")
295
295
  end
296
296
  it "finds a single exact match when there also are inexact matches" do
297
297
  result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :match => :prefer_exact, :exact => false)
298
- result.text.should == "almost singular"
298
+ expect(result.text).to eq("almost singular")
299
299
  end
300
300
  it "picks the first one when there are multiple inexact matches" do
301
301
  result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :match => :prefer_exact, :exact => false)
302
- result.text.should == "almost singular but not quite"
302
+ expect(result.text).to eq("almost singular but not quite")
303
303
  end
304
304
  it "finds a single inexact match" do
305
305
  result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :match => :prefer_exact, :exact => false)
306
- result.text.should == "almost singular but not quite"
306
+ expect(result.text).to eq("almost singular but not quite")
307
307
  end
308
308
  it "raises an error if there is no match" do
309
309
  expect do
@@ -315,11 +315,11 @@ Capybara::SpecHelper.spec '#find' do
315
315
  context "with `exact` set to `true`" do
316
316
  it "picks the first one when there are multiple exact matches" do
317
317
  result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :match => :prefer_exact, :exact => true)
318
- result.text.should == "multiple one"
318
+ expect(result.text).to eq("multiple one")
319
319
  end
320
320
  it "finds a single exact match when there also are inexact matches" do
321
321
  result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :match => :prefer_exact, :exact => true)
322
- result.text.should == "almost singular"
322
+ expect(result.text).to eq("almost singular")
323
323
  end
324
324
  it "raises an error if there are multiple inexact matches" do
325
325
  expect do
@@ -345,7 +345,7 @@ Capybara::SpecHelper.spec '#find' do
345
345
  @session.find(:css, ".multiple")
346
346
  end.to raise_error(Capybara::Ambiguous)
347
347
  Capybara.match = :first
348
- @session.find(:css, ".multiple").text.should == "multiple one"
348
+ expect(@session.find(:css, ".multiple").text).to eq("multiple one")
349
349
  end
350
350
 
351
351
  it "raises an error when unknown option given" do
@@ -362,13 +362,13 @@ Capybara::SpecHelper.spec '#find' do
362
362
 
363
363
  it "should find the an element using the given locator" do
364
364
  @session.within(:xpath, "//div[@id='for_bar']") do
365
- @session.find('.//li[1]').text.should =~ /With Simple HTML/
365
+ expect(@session.find('.//li[1]').text).to match(/With Simple HTML/)
366
366
  end
367
367
  end
368
368
 
369
369
  it "should support pseudo selectors" do
370
370
  @session.within(:xpath, "//div[@id='for_bar']") do
371
- @session.find(:css, 'input:disabled').value.should == 'James'
371
+ expect(@session.find(:css, 'input:disabled').value).to eq('James')
372
372
  end
373
373
  end
374
374
  end
@@ -4,73 +4,73 @@ Capybara::SpecHelper.spec '#first' do
4
4
  end
5
5
 
6
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'
7
+ expect(@session.first('//h1').text).to eq('This is a test')
8
+ expect(@session.first("//input[@id='test_field']")[:value]).to eq('monkey')
9
9
  end
10
10
 
11
11
  it "should return nil when nothing was found" do
12
- @session.first('//div[@id="nosuchthing"]').should be_nil
12
+ expect(@session.first('//div[@id="nosuchthing"]')).to be_nil
13
13
  end
14
14
 
15
15
  it "should accept an XPath instance" do
16
16
  @session.visit('/form')
17
17
  @xpath = XPath::HTML.fillable_field('First Name')
18
- @session.first(@xpath).value.should == 'John'
18
+ expect(@session.first(@xpath).value).to eq('John')
19
19
  end
20
20
 
21
21
  context "with css selectors" do
22
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'
23
+ expect(@session.first(:css, 'h1').text).to eq('This is a test')
24
+ expect(@session.first(:css, "input[id='test_field']")[:value]).to eq('monkey')
25
25
  end
26
26
  end
27
27
 
28
28
  context "with xpath selectors" do
29
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'
30
+ expect(@session.first(:xpath, '//h1').text).to eq('This is a test')
31
+ expect(@session.first(:xpath, "//input[@id='test_field']")[:value]).to eq('monkey')
32
32
  end
33
33
  end
34
34
 
35
35
  context "with css as default selector" do
36
36
  before { Capybara.default_selector = :css }
37
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'
38
+ expect(@session.first('h1').text).to eq('This is a test')
39
+ expect(@session.first("input[id='test_field']")[:value]).to eq('monkey')
40
40
  end
41
41
  end
42
42
 
43
43
  context "with visible filter" do
44
44
  it "should only find visible nodes when true" do
45
- @session.first(:css, "a#invisible", :visible => true).should be_nil
45
+ expect(@session.first(:css, "a#invisible", :visible => true)).to be_nil
46
46
  end
47
47
 
48
48
  it "should find nodes regardless of whether they are invisible when false" do
49
- @session.first(:css, "a#invisible", :visible => false).should_not be_nil
50
- @session.first(:css, "a#visible", :visible => false).should_not be_nil
49
+ expect(@session.first(:css, "a#invisible", :visible => false)).not_to be_nil
50
+ expect(@session.first(:css, "a#visible", :visible => false)).not_to be_nil
51
51
  end
52
52
 
53
53
  it "should find nodes regardless of whether they are invisible when :all" do
54
- @session.first(:css, "a#invisible", :visible => :all).should_not be_nil
55
- @session.first(:css, "a#visible", :visible => :all).should_not be_nil
54
+ expect(@session.first(:css, "a#invisible", :visible => :all)).not_to be_nil
55
+ expect(@session.first(:css, "a#visible", :visible => :all)).not_to be_nil
56
56
  end
57
57
 
58
58
  it "should find only hidden nodes when :hidden" do
59
- @session.first(:css, "a#invisible", :visible => :hidden).should_not be_nil
60
- @session.first(:css, "a#visible", :visible => :hidden).should be_nil
59
+ expect(@session.first(:css, "a#invisible", :visible => :hidden)).not_to be_nil
60
+ expect(@session.first(:css, "a#visible", :visible => :hidden)).to be_nil
61
61
  end
62
62
 
63
63
  it "should find only visible nodes when :visible" do
64
- @session.first(:css, "a#invisible", :visible => :visible).should be_nil
65
- @session.first(:css, "a#visible", :visible => :visible).should_not be_nil
64
+ expect(@session.first(:css, "a#invisible", :visible => :visible)).to be_nil
65
+ expect(@session.first(:css, "a#visible", :visible => :visible)).not_to be_nil
66
66
  end
67
67
 
68
68
  it "should default to Capybara.ignore_hidden_elements" do
69
69
  Capybara.ignore_hidden_elements = true
70
- @session.first(:css, "a#invisible").should be_nil
70
+ expect(@session.first(:css, "a#invisible")).to be_nil
71
71
  Capybara.ignore_hidden_elements = false
72
- @session.first(:css, "a#invisible").should_not be_nil
73
- @session.first(:css, "a").should_not be_nil
72
+ expect(@session.first(:css, "a#invisible")).not_to be_nil
73
+ expect(@session.first(:css, "a")).not_to be_nil
74
74
  end
75
75
  end
76
76
 
@@ -81,7 +81,7 @@ Capybara::SpecHelper.spec '#first' do
81
81
 
82
82
  it "should find the first element using the given locator" do
83
83
  @session.within(:xpath, "//div[@id='for_bar']") do
84
- @session.first('.//form').should_not be_nil
84
+ expect(@session.first('.//form')).not_to be_nil
85
85
  end
86
86
  end
87
87
  end