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
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Capybara::Result do
3
+ RSpec.describe Capybara::Result do
4
4
  let :string do
5
5
  Capybara.string <<-STRING
6
6
  <ul>
@@ -17,7 +17,7 @@ describe Capybara::Result do
17
17
  end
18
18
 
19
19
  it "has a length" do
20
- result.length.should == 4
20
+ expect(result.length).to eq(4)
21
21
  end
22
22
 
23
23
  it "has a first element" do
@@ -29,37 +29,37 @@ describe Capybara::Result do
29
29
  end
30
30
 
31
31
  it 'can supports values_at method' do
32
- result.values_at(0, 2).map(&:text).should == %w(Alpha Gamma)
32
+ expect(result.values_at(0, 2).map(&:text)).to eq(%w(Alpha Gamma))
33
33
  end
34
34
 
35
35
  it "can return an element by its index" do
36
- result.at(1).text.should == 'Beta'
37
- result[2].text.should == 'Gamma'
36
+ expect(result.at(1).text).to eq('Beta')
37
+ expect(result[2].text).to eq('Gamma')
38
38
  end
39
39
 
40
40
  it "can be mapped" do
41
- result.map(&:text).should == %w(Alpha Beta Gamma Delta)
41
+ expect(result.map(&:text)).to eq(%w(Alpha Beta Gamma Delta))
42
42
  end
43
43
 
44
44
  it "can be selected" do
45
- result.select do |element|
45
+ expect(result.select do |element|
46
46
  element.text.include? 't'
47
- end.length.should == 2
47
+ end.length).to eq(2)
48
48
  end
49
49
 
50
50
  it "can be reduced" do
51
- result.reduce('') do |memo, element|
51
+ expect(result.reduce('') do |memo, element|
52
52
  memo += element.text[0]
53
- end.should == 'ABGD'
53
+ end).to eq('ABGD')
54
54
  end
55
55
 
56
56
  it 'can be sampled' do
57
- result.should include(result.sample)
57
+ expect(result).to include(result.sample)
58
58
  end
59
59
 
60
60
  it 'can be indexed' do
61
- result.index do |el|
61
+ expect(result.index do |el|
62
62
  el.text == 'Gamma'
63
- end.should == 2
63
+ end).to eq(2)
64
64
  end
65
65
  end
@@ -5,48 +5,53 @@ RSpec.configuration.before(:each, :example_group => {:file_path => "./spec/rspec
5
5
  @in_filtered_hook = true
6
6
  end
7
7
 
8
- feature "Capybara's feature DSL" do
8
+ feature "Capybara's feature DSL" do
9
9
  background do
10
10
  @in_background = true
11
11
  end
12
+
13
+ def current_example(context)
14
+ RSpec.respond_to?(:current_example) ? RSpec.current_example : context.example
15
+ end
12
16
 
13
17
  scenario "includes Capybara" do
14
18
  visit('/')
15
- page.should have_content('Hello world!')
19
+ expect(page).to have_content('Hello world!')
16
20
  end
17
21
 
18
- scenario "preserves description" do
19
- example.metadata[:full_description].should == "Capybara's feature DSL preserves description"
22
+ scenario "preserves description" do
23
+ expect(current_example(self).metadata[:full_description])
24
+ .to eq("Capybara's feature DSL preserves description")
20
25
  end
21
26
 
22
27
  scenario "allows driver switching", :driver => :selenium do
23
- Capybara.current_driver.should == :selenium
28
+ expect(Capybara.current_driver).to eq(:selenium)
24
29
  end
25
30
 
26
31
  scenario "runs background" do
27
- @in_background.should be_true
32
+ expect(@in_background).to be_truthy
28
33
  end
29
34
 
30
35
  scenario "runs hooks filtered by file path" do
31
- @in_filtered_hook.should be_true
36
+ expect(@in_filtered_hook).to be_truthy
32
37
  end
33
38
 
34
39
  scenario "doesn't pollute the Object namespace" do
35
- Object.new.respond_to?(:feature, true).should be_false
40
+ expect(Object.new.respond_to?(:feature, true)).to be_falsey
36
41
  end
37
42
 
38
43
  feature 'nested features' do
39
44
  scenario 'work as expected' do
40
45
  visit '/'
41
- page.should have_content 'Hello world!'
46
+ expect(page).to have_content 'Hello world!'
42
47
  end
43
48
 
44
49
  scenario 'are marked in the metadata as capybara_feature' do
45
- example.metadata[:capybara_feature].should be_true
50
+ expect(current_example(self).metadata[:capybara_feature]).to be_truthy
46
51
  end
47
52
 
48
53
  scenario 'have a type of :feature' do
49
- example.metadata[:type].should eq :feature
54
+ expect(current_example(self).metadata[:type]).to eq :feature
50
55
  end
51
56
  end
52
57
  end
@@ -56,12 +61,12 @@ feature "given and given! aliases to let and let!" do
56
61
  given!(:value_in_background) { :available }
57
62
 
58
63
  background do
59
- value_in_background.should be(:available)
64
+ expect(value_in_background).to be(:available)
60
65
  end
61
66
 
62
67
  scenario "given and given! work as intended" do
63
- value.should be(:available)
64
- value_in_background.should be(:available)
68
+ expect(value).to be(:available)
69
+ expect(value_in_background).to be(:available)
65
70
  end
66
71
  end
67
72
 
@@ -72,6 +77,6 @@ end
72
77
 
73
78
  feature "Capybara's feature DSL with driver", :driver => :culerity do
74
79
  scenario "switches driver" do
75
- Capybara.current_driver.should == :culerity
80
+ expect(Capybara.current_driver).to eq(:culerity)
76
81
  end
77
82
  end
@@ -2,52 +2,52 @@ require 'spec_helper'
2
2
  require 'capybara/dsl'
3
3
  require 'capybara/rspec/matchers'
4
4
 
5
- describe Capybara::RSpecMatchers do
5
+ RSpec.describe Capybara::RSpecMatchers do
6
6
  include Capybara::DSL
7
7
  include Capybara::RSpecMatchers
8
8
 
9
9
  describe "have_css matcher" do
10
10
  it "gives proper description" do
11
- have_css('h1').description.should == "have css \"h1\""
11
+ expect(have_css('h1').description).to eq("have css \"h1\"")
12
12
  end
13
13
 
14
14
  context "on a string" do
15
15
  context "with should" do
16
16
  it "passes if has_css? returns true" do
17
- "<h1>Text</h1>".should have_css('h1')
17
+ expect("<h1>Text</h1>").to have_css('h1')
18
18
  end
19
19
 
20
20
  it "fails if has_css? returns false" do
21
21
  expect do
22
- "<h1>Text</h1>".should have_css('h2')
22
+ expect("<h1>Text</h1>").to have_css('h2')
23
23
  end.to raise_error(/expected to find css "h2" but there were no matches/)
24
24
  end
25
25
 
26
26
  it "passes if matched node count equals expected count" do
27
- "<h1>Text</h1>".should have_css('h1', :count => 1)
27
+ expect("<h1>Text</h1>").to have_css('h1', :count => 1)
28
28
  end
29
29
 
30
30
  it "fails if matched node count does not equal expected count" do
31
31
  expect do
32
- "<h1>Text</h1>".should have_css('h1', count: 2)
32
+ expect("<h1>Text</h1>").to have_css('h1', count: 2)
33
33
  end.to raise_error("expected to find css \"h1\" 2 times, found 1 match: \"Text\"")
34
34
  end
35
35
 
36
36
  it "fails if matched node count is less than expected minimum count" do
37
37
  expect do
38
- "<h1>Text</h1>".should have_css('p', minimum: 1)
38
+ expect("<h1>Text</h1>").to have_css('p', minimum: 1)
39
39
  end.to raise_error("expected to find css \"p\" at least 1 time but there were no matches")
40
40
  end
41
41
 
42
42
  it "fails if matched node count is more than expected maximum count" do
43
43
  expect do
44
- "<h1>Text</h1><h1>Text</h1><h1>Text</h1>".should have_css('h1', maximum: 2)
44
+ expect("<h1>Text</h1><h1>Text</h1><h1>Text</h1>").to have_css('h1', maximum: 2)
45
45
  end.to raise_error('expected to find css "h1" at most 2 times, found 3 matches: "Text", "Text", "Text"')
46
46
  end
47
47
 
48
48
  it "fails if matched node count does not belong to expected range" do
49
49
  expect do
50
- "<h1>Text</h1>".should have_css('h1', between: 2..3)
50
+ expect("<h1>Text</h1>").to have_css('h1', between: 2..3)
51
51
  end.to raise_error("expected to find css \"h1\" between 2 and 3 times, found 1 match: \"Text\"")
52
52
  end
53
53
 
@@ -55,22 +55,22 @@ describe Capybara::RSpecMatchers do
55
55
 
56
56
  context "with should_not" do
57
57
  it "passes if has_no_css? returns true" do
58
- "<h1>Text</h1>".should_not have_css('h2')
58
+ expect("<h1>Text</h1>").not_to have_css('h2')
59
59
  end
60
60
 
61
61
  it "fails if has_no_css? returns false" do
62
62
  expect do
63
- "<h1>Text</h1>".should_not have_css('h1')
63
+ expect("<h1>Text</h1>").not_to have_css('h1')
64
64
  end.to raise_error(/expected not to find css "h1"/)
65
65
  end
66
66
 
67
67
  it "passes if matched node count does not equal expected count" do
68
- "<h1>Text</h1>".should_not have_css('h1', :count => 2)
68
+ expect("<h1>Text</h1>").not_to have_css('h1', :count => 2)
69
69
  end
70
70
 
71
71
  it "fails if matched node count equals expected count" do
72
72
  expect do
73
- "<h1>Text</h1>".should_not have_css('h1', :count => 1)
73
+ expect("<h1>Text</h1>").not_to have_css('h1', :count => 1)
74
74
  end.to raise_error(/expected not to find css "h1"/)
75
75
  end
76
76
  end
@@ -83,24 +83,24 @@ describe Capybara::RSpecMatchers do
83
83
 
84
84
  context "with should" do
85
85
  it "passes if has_css? returns true" do
86
- page.should have_css('h1')
86
+ expect(page).to have_css('h1')
87
87
  end
88
88
 
89
89
  it "fails if has_css? returns false" do
90
90
  expect do
91
- page.should have_css('h1#doesnotexist')
91
+ expect(page).to have_css('h1#doesnotexist')
92
92
  end.to raise_error(/expected to find css "h1#doesnotexist" but there were no matches/)
93
93
  end
94
94
  end
95
95
 
96
96
  context "with should_not" do
97
97
  it "passes if has_no_css? returns true" do
98
- page.should_not have_css('h1#doesnotexist')
98
+ expect(page).not_to have_css('h1#doesnotexist')
99
99
  end
100
100
 
101
101
  it "fails if has_no_css? returns false" do
102
102
  expect do
103
- page.should_not have_css('h1')
103
+ expect(page).not_to have_css('h1')
104
104
  end.to raise_error(/expected not to find css "h1"/)
105
105
  end
106
106
  end
@@ -109,30 +109,30 @@ describe Capybara::RSpecMatchers do
109
109
 
110
110
  describe "have_xpath matcher" do
111
111
  it "gives proper description" do
112
- have_xpath('//h1').description.should == "have xpath \"\/\/h1\""
112
+ expect(have_xpath('//h1').description).to eq("have xpath \"\/\/h1\"")
113
113
  end
114
114
 
115
115
  context "on a string" do
116
116
  context "with should" do
117
117
  it "passes if has_xpath? returns true" do
118
- "<h1>Text</h1>".should have_xpath('//h1')
118
+ expect("<h1>Text</h1>").to have_xpath('//h1')
119
119
  end
120
120
 
121
121
  it "fails if has_xpath? returns false" do
122
122
  expect do
123
- "<h1>Text</h1>".should have_xpath('//h2')
123
+ expect("<h1>Text</h1>").to have_xpath('//h2')
124
124
  end.to raise_error(%r(expected to find xpath "//h2" but there were no matches))
125
125
  end
126
126
  end
127
127
 
128
128
  context "with should_not" do
129
129
  it "passes if has_no_xpath? returns true" do
130
- "<h1>Text</h1>".should_not have_xpath('//h2')
130
+ expect("<h1>Text</h1>").not_to have_xpath('//h2')
131
131
  end
132
132
 
133
133
  it "fails if has_no_xpath? returns false" do
134
134
  expect do
135
- "<h1>Text</h1>".should_not have_xpath('//h1')
135
+ expect("<h1>Text</h1>").not_to have_xpath('//h1')
136
136
  end.to raise_error(%r(expected not to find xpath "//h1"))
137
137
  end
138
138
  end
@@ -145,24 +145,24 @@ describe Capybara::RSpecMatchers do
145
145
 
146
146
  context "with should" do
147
147
  it "passes if has_xpath? returns true" do
148
- page.should have_xpath('//h1')
148
+ expect(page).to have_xpath('//h1')
149
149
  end
150
150
 
151
151
  it "fails if has_xpath? returns false" do
152
152
  expect do
153
- page.should have_xpath("//h1[@id='doesnotexist']")
153
+ expect(page).to have_xpath("//h1[@id='doesnotexist']")
154
154
  end.to raise_error(%r(expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
155
155
  end
156
156
  end
157
157
 
158
158
  context "with should_not" do
159
159
  it "passes if has_no_xpath? returns true" do
160
- page.should_not have_xpath('//h1[@id="doesnotexist"]')
160
+ expect(page).not_to have_xpath('//h1[@id="doesnotexist"]')
161
161
  end
162
162
 
163
163
  it "fails if has_no_xpath? returns false" do
164
164
  expect do
165
- page.should_not have_xpath('//h1')
165
+ expect(page).not_to have_xpath('//h1')
166
166
  end.to raise_error(%r(expected not to find xpath "//h1"))
167
167
  end
168
168
  end
@@ -172,31 +172,31 @@ describe Capybara::RSpecMatchers do
172
172
  describe "have_selector matcher" do
173
173
  it "gives proper description" do
174
174
  matcher = have_selector('//h1')
175
- "<h1>Text</h1>".should matcher
176
- matcher.description.should == "have xpath \"//h1\""
175
+ expect("<h1>Text</h1>").to matcher
176
+ expect(matcher.description).to eq("have xpath \"//h1\"")
177
177
  end
178
178
 
179
179
  context "on a string" do
180
180
  context "with should" do
181
181
  it "passes if has_selector? returns true" do
182
- "<h1>Text</h1>".should have_selector('//h1')
182
+ expect("<h1>Text</h1>").to have_selector('//h1')
183
183
  end
184
184
 
185
185
  it "fails if has_selector? returns false" do
186
186
  expect do
187
- "<h1>Text</h1>".should have_selector('//h2')
187
+ expect("<h1>Text</h1>").to have_selector('//h2')
188
188
  end.to raise_error(%r(expected to find xpath "//h2" but there were no matches))
189
189
  end
190
190
  end
191
191
 
192
192
  context "with should_not" do
193
193
  it "passes if has_no_selector? returns true" do
194
- "<h1>Text</h1>".should_not have_selector(:css, 'h2')
194
+ expect("<h1>Text</h1>").not_to have_selector(:css, 'h2')
195
195
  end
196
196
 
197
197
  it "fails if has_no_selector? returns false" do
198
198
  expect do
199
- "<h1>Text</h1>".should_not have_selector(:css, 'h1')
199
+ expect("<h1>Text</h1>").not_to have_selector(:css, 'h1')
200
200
  end.to raise_error(%r(expected not to find css "h1"))
201
201
  end
202
202
  end
@@ -209,30 +209,30 @@ describe Capybara::RSpecMatchers do
209
209
 
210
210
  context "with should" do
211
211
  it "passes if has_selector? returns true" do
212
- page.should have_selector('//h1', :text => 'test')
212
+ expect(page).to have_selector('//h1', :text => 'test')
213
213
  end
214
214
 
215
215
  it "fails if has_selector? returns false" do
216
216
  expect do
217
- page.should have_selector("//h1[@id='doesnotexist']")
217
+ expect(page).to have_selector("//h1[@id='doesnotexist']")
218
218
  end.to raise_error(%r(expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
219
219
  end
220
220
 
221
221
  it "includes text in error message" do
222
222
  expect do
223
- page.should have_selector("//h1", :text => 'wrong text')
223
+ expect(page).to have_selector("//h1", :text => 'wrong text')
224
224
  end.to raise_error(%r(expected to find xpath "//h1" with text "wrong text" but there were no matches))
225
225
  end
226
226
  end
227
227
 
228
228
  context "with should_not" do
229
229
  it "passes if has_no_css? returns true" do
230
- page.should_not have_selector(:css, 'h1#doesnotexist')
230
+ expect(page).not_to have_selector(:css, 'h1#doesnotexist')
231
231
  end
232
232
 
233
233
  it "fails if has_no_selector? returns false" do
234
234
  expect do
235
- page.should_not have_selector(:css, 'h1', :text => 'test')
235
+ expect(page).not_to have_selector(:css, 'h1', :text => 'test')
236
236
  end.to raise_error(%r(expected not to find css "h1" with text "test"))
237
237
  end
238
238
  end
@@ -241,38 +241,38 @@ describe Capybara::RSpecMatchers do
241
241
 
242
242
  describe "have_content matcher" do
243
243
  it "gives proper description" do
244
- have_content('Text').description.should == "text \"Text\""
244
+ expect(have_content('Text').description).to eq("text \"Text\"")
245
245
  end
246
246
 
247
247
  context "on a string" do
248
248
  context "with should" do
249
249
  it "passes if has_content? returns true" do
250
- "<h1>Text</h1>".should have_content('Text')
250
+ expect("<h1>Text</h1>").to have_content('Text')
251
251
  end
252
252
 
253
253
  it "passes if has_content? returns true using regexp" do
254
- "<h1>Text</h1>".should have_content(/ext/)
254
+ expect("<h1>Text</h1>").to have_content(/ext/)
255
255
  end
256
256
 
257
257
  it "fails if has_content? returns false" do
258
258
  expect do
259
- "<h1>Text</h1>".should have_content('No such Text')
259
+ expect("<h1>Text</h1>").to have_content('No such Text')
260
260
  end.to raise_error(/expected to find text "No such Text" in "Text"/)
261
261
  end
262
262
  end
263
263
 
264
264
  context "with should_not" do
265
265
  it "passes if has_no_content? returns true" do
266
- "<h1>Text</h1>".should_not have_content('No such Text')
266
+ expect("<h1>Text</h1>").not_to have_content('No such Text')
267
267
  end
268
268
 
269
269
  it "passes because escapes any characters that would have special meaning in a regexp" do
270
- "<h1>Text</h1>".should_not have_content('.')
270
+ expect("<h1>Text</h1>").not_to have_content('.')
271
271
  end
272
272
 
273
273
  it "fails if has_no_content? returns false" do
274
274
  expect do
275
- "<h1>Text</h1>".should_not have_content('Text')
275
+ expect("<h1>Text</h1>").not_to have_content('Text')
276
276
  end.to raise_error(/expected not to find text "Text" in "Text"/)
277
277
  end
278
278
  end
@@ -285,16 +285,16 @@ describe Capybara::RSpecMatchers do
285
285
 
286
286
  context "with should" do
287
287
  it "passes if has_content? returns true" do
288
- page.should have_content('This is a test')
288
+ expect(page).to have_content('This is a test')
289
289
  end
290
290
 
291
291
  it "passes if has_content? returns true using regexp" do
292
- page.should have_content(/test/)
292
+ expect(page).to have_content(/test/)
293
293
  end
294
294
 
295
295
  it "fails if has_content? returns false" do
296
296
  expect do
297
- page.should have_content('No such Text')
297
+ expect(page).to have_content('No such Text')
298
298
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
299
299
  end
300
300
 
@@ -302,7 +302,7 @@ describe Capybara::RSpecMatchers do
302
302
  before { Capybara.default_selector = :css }
303
303
  it "fails if has_content? returns false" do
304
304
  expect do
305
- page.should have_content('No such Text')
305
+ expect(page).to have_content('No such Text')
306
306
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
307
307
  end
308
308
  after { Capybara.default_selector = :xpath }
@@ -311,12 +311,12 @@ describe Capybara::RSpecMatchers do
311
311
 
312
312
  context "with should_not" do
313
313
  it "passes if has_no_content? returns true" do
314
- page.should_not have_content('No such Text')
314
+ expect(page).not_to have_content('No such Text')
315
315
  end
316
316
 
317
317
  it "fails if has_no_content? returns false" do
318
318
  expect do
319
- page.should_not have_content('This is a test')
319
+ expect(page).not_to have_content('This is a test')
320
320
  end.to raise_error(/expected not to find text "This is a test"/)
321
321
  end
322
322
  end
@@ -325,68 +325,68 @@ describe Capybara::RSpecMatchers do
325
325
 
326
326
  describe "have_text matcher" do
327
327
  it "gives proper description" do
328
- have_text('Text').description.should == "text \"Text\""
328
+ expect(have_text('Text').description).to eq("text \"Text\"")
329
329
  end
330
330
 
331
331
  context "on a string" do
332
332
  context "with should" do
333
333
  it "passes if has_text? returns true" do
334
- "<h1>Text</h1>".should have_text('Text')
334
+ expect("<h1>Text</h1>").to have_text('Text')
335
335
  end
336
336
 
337
337
  it "passes if has_text? returns true using regexp" do
338
- "<h1>Text</h1>".should have_text(/ext/)
338
+ expect("<h1>Text</h1>").to have_text(/ext/)
339
339
  end
340
340
 
341
341
  it "fails if has_text? returns false" do
342
342
  expect do
343
- "<h1>Text</h1>".should have_text('No such Text')
343
+ expect("<h1>Text</h1>").to have_text('No such Text')
344
344
  end.to raise_error(/expected to find text "No such Text" in "Text"/)
345
345
  end
346
346
 
347
347
  it "casts Fixnum to string" do
348
348
  expect do
349
- "<h1>Text</h1>".should have_text(3)
349
+ expect("<h1>Text</h1>").to have_text(3)
350
350
  end.to raise_error(/expected to find text "3" in "Text"/)
351
351
  end
352
352
 
353
353
  it "fails if matched text count does not equal to expected count" do
354
354
  expect do
355
- "<h1>Text</h1>".should have_text('Text', count: 2)
355
+ expect("<h1>Text</h1>").to have_text('Text', count: 2)
356
356
  end.to raise_error(/expected to find text "Text" 2 times in "Text"/)
357
357
  end
358
358
 
359
359
  it "fails if matched text count is less than expected minimum count" do
360
360
  expect do
361
- "<h1>Text</h1>".should have_text('Lorem', minimum: 1)
361
+ expect("<h1>Text</h1>").to have_text('Lorem', minimum: 1)
362
362
  end.to raise_error(/expected to find text "Lorem" at least 1 time in "Text"/)
363
363
  end
364
364
 
365
365
  it "fails if matched text count is more than expected maximum count" do
366
366
  expect do
367
- "<h1>Text TextText</h1>".should have_text('Text', maximum: 2)
367
+ expect("<h1>Text TextText</h1>").to have_text('Text', maximum: 2)
368
368
  end.to raise_error(/expected to find text "Text" at most 2 times in "Text TextText"/)
369
369
  end
370
370
 
371
371
  it "fails if matched text count does not belong to expected range" do
372
372
  expect do
373
- "<h1>Text</h1>".should have_text('Text', between: 2..3)
373
+ expect("<h1>Text</h1>").to have_text('Text', between: 2..3)
374
374
  end.to raise_error(/expected to find text "Text" between 2 and 3 times in "Text"/)
375
375
  end
376
376
  end
377
377
 
378
378
  context "with should_not" do
379
379
  it "passes if has_no_text? returns true" do
380
- "<h1>Text</h1>".should_not have_text('No such Text')
380
+ expect("<h1>Text</h1>").not_to have_text('No such Text')
381
381
  end
382
382
 
383
383
  it "passes because escapes any characters that would have special meaning in a regexp" do
384
- "<h1>Text</h1>".should_not have_text('.')
384
+ expect("<h1>Text</h1>").not_to have_text('.')
385
385
  end
386
386
 
387
387
  it "fails if has_no_text? returns false" do
388
388
  expect do
389
- "<h1>Text</h1>".should_not have_text('Text')
389
+ expect("<h1>Text</h1>").not_to have_text('Text')
390
390
  end.to raise_error(/expected not to find text "Text" in "Text"/)
391
391
  end
392
392
  end
@@ -399,25 +399,25 @@ describe Capybara::RSpecMatchers do
399
399
 
400
400
  context "with should" do
401
401
  it "passes if has_text? returns true" do
402
- page.should have_text('This is a test')
402
+ expect(page).to have_text('This is a test')
403
403
  end
404
404
 
405
405
  it "passes if has_text? returns true using regexp" do
406
- page.should have_text(/test/)
406
+ expect(page).to have_text(/test/)
407
407
  end
408
408
 
409
409
  it "can check for all text" do
410
- page.should have_text(:all, 'Some of this text is hidden!')
410
+ expect(page).to have_text(:all, 'Some of this text is hidden!')
411
411
  end
412
412
 
413
413
  it "can check for visible text" do
414
- page.should have_text(:visible, 'Some of this text is')
415
- page.should_not have_text(:visible, 'Some of this text is hidden!')
414
+ expect(page).to have_text(:visible, 'Some of this text is')
415
+ expect(page).not_to have_text(:visible, 'Some of this text is hidden!')
416
416
  end
417
417
 
418
418
  it "fails if has_text? returns false" do
419
419
  expect do
420
- page.should have_text('No such Text')
420
+ expect(page).to have_text('No such Text')
421
421
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
422
422
  end
423
423
 
@@ -425,7 +425,7 @@ describe Capybara::RSpecMatchers do
425
425
  before { Capybara.default_selector = :css }
426
426
  it "fails if has_text? returns false" do
427
427
  expect do
428
- page.should have_text('No such Text')
428
+ expect(page).to have_text('No such Text')
429
429
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
430
430
  end
431
431
  after { Capybara.default_selector = :xpath }
@@ -434,12 +434,12 @@ describe Capybara::RSpecMatchers do
434
434
 
435
435
  context "with should_not" do
436
436
  it "passes if has_no_text? returns true" do
437
- page.should_not have_text('No such Text')
437
+ expect(page).not_to have_text('No such Text')
438
438
  end
439
439
 
440
440
  it "fails if has_no_text? returns false" do
441
441
  expect do
442
- page.should_not have_text('This is a test')
442
+ expect(page).not_to have_text('This is a test')
443
443
  end.to raise_error(/expected not to find text "This is a test"/)
444
444
  end
445
445
  end
@@ -450,35 +450,35 @@ describe Capybara::RSpecMatchers do
450
450
  let(:html) { '<a href="#">Just a link</a>' }
451
451
 
452
452
  it "gives proper description" do
453
- have_link('Just a link').description.should == "have link \"Just a link\""
453
+ expect(have_link('Just a link').description).to eq("have link \"Just a link\"")
454
454
  end
455
455
 
456
456
  it "passes if there is such a button" do
457
- html.should have_link('Just a link')
457
+ expect(html).to have_link('Just a link')
458
458
  end
459
459
 
460
460
  it "fails if there is no such button" do
461
461
  expect do
462
- html.should have_link('No such Link')
462
+ expect(html).to have_link('No such Link')
463
463
  end.to raise_error(/expected to find link "No such Link"/)
464
464
  end
465
465
  end
466
466
 
467
467
  describe "have_title matcher" do
468
468
  it "gives proper description" do
469
- have_title('Just a title').description.should == "have title \"Just a title\""
469
+ expect(have_title('Just a title').description).to eq("have title \"Just a title\"")
470
470
  end
471
471
 
472
472
  context "on a string" do
473
473
  let(:html) { '<title>Just a title</title>' }
474
474
 
475
475
  it "passes if there is such a title" do
476
- html.should have_title('Just a title')
476
+ expect(html).to have_title('Just a title')
477
477
  end
478
478
 
479
479
  it "fails if there is no such title" do
480
480
  expect do
481
- html.should have_title('No such title')
481
+ expect(html).to have_title('No such title')
482
482
  end.to raise_error(/expected there to be title "No such title"/)
483
483
  end
484
484
  end
@@ -489,12 +489,12 @@ describe Capybara::RSpecMatchers do
489
489
  end
490
490
 
491
491
  it "passes if there is such a title" do
492
- page.should have_title('with_js')
492
+ expect(page).to have_title('with_js')
493
493
  end
494
494
 
495
495
  it "fails if there is no such title" do
496
496
  expect do
497
- page.should have_title('No such title')
497
+ expect(page).to have_title('No such title')
498
498
  end.to raise_error(/expected there to be title "No such title"/)
499
499
  end
500
500
  end
@@ -504,16 +504,16 @@ describe Capybara::RSpecMatchers do
504
504
  let(:html) { '<button>A button</button><input type="submit" value="Another button"/>' }
505
505
 
506
506
  it "gives proper description" do
507
- have_button('A button').description.should == "have button \"A button\""
507
+ expect(have_button('A button').description).to eq("have button \"A button\"")
508
508
  end
509
509
 
510
510
  it "passes if there is such a button" do
511
- html.should have_button('A button')
511
+ expect(html).to have_button('A button')
512
512
  end
513
513
 
514
514
  it "fails if there is no such button" do
515
515
  expect do
516
- html.should have_button('No such Button')
516
+ expect(html).to have_button('No such Button')
517
517
  end.to raise_error(/expected to find button "No such Button"/)
518
518
  end
519
519
  end
@@ -522,30 +522,30 @@ describe Capybara::RSpecMatchers do
522
522
  let(:html) { '<p><label>Text field<input type="text" value="some value"/></label></p>' }
523
523
 
524
524
  it "gives proper description" do
525
- have_field('Text field').description.should == "have field \"Text field\""
525
+ expect(have_field('Text field').description).to eq("have field \"Text field\"")
526
526
  end
527
527
 
528
528
  it "gives proper description for a given value" do
529
- have_field('Text field', with: 'some value').description.should == "have field \"Text field\" with value \"some value\""
529
+ expect(have_field('Text field', with: 'some value').description).to eq("have field \"Text field\" with value \"some value\"")
530
530
  end
531
531
 
532
532
  it "passes if there is such a field" do
533
- html.should have_field('Text field')
533
+ expect(html).to have_field('Text field')
534
534
  end
535
535
 
536
536
  it "passes if there is such a field with value" do
537
- html.should have_field('Text field', with: 'some value')
537
+ expect(html).to have_field('Text field', with: 'some value')
538
538
  end
539
539
 
540
540
  it "fails if there is no such field" do
541
541
  expect do
542
- html.should have_field('No such Field')
542
+ expect(html).to have_field('No such Field')
543
543
  end.to raise_error(/expected to find field "No such Field"/)
544
544
  end
545
545
 
546
546
  it "fails if there is such field but with false value" do
547
547
  expect do
548
- html.should have_field('Text field', with: 'false value')
548
+ expect(html).to have_field('Text field', with: 'false value')
549
549
  end.to raise_error(/expected to find field "Text field"/)
550
550
  end
551
551
 
@@ -555,7 +555,7 @@ describe Capybara::RSpecMatchers do
555
555
  "some value"
556
556
  end
557
557
  end
558
- html.should have_field('Text field', with: Foo.new)
558
+ expect(html).to have_field('Text field', with: Foo.new)
559
559
  end
560
560
  end
561
561
 
@@ -566,23 +566,23 @@ describe Capybara::RSpecMatchers do
566
566
  end
567
567
 
568
568
  it "gives proper description" do
569
- have_checked_field('it is checked').description.should == "have field \"it is checked\""
569
+ expect(have_checked_field('it is checked').description).to eq("have field \"it is checked\"")
570
570
  end
571
571
 
572
572
  context "with should" do
573
573
  it "passes if there is such a field and it is checked" do
574
- html.should have_checked_field('it is checked')
574
+ expect(html).to have_checked_field('it is checked')
575
575
  end
576
576
 
577
577
  it "fails if there is such a field but it is not checked" do
578
578
  expect do
579
- html.should have_checked_field('unchecked field')
579
+ expect(html).to have_checked_field('unchecked field')
580
580
  end.to raise_error(/expected to find field "unchecked field"/)
581
581
  end
582
582
 
583
583
  it "fails if there is no such field" do
584
584
  expect do
585
- html.should have_checked_field('no such field')
585
+ expect(html).to have_checked_field('no such field')
586
586
  end.to raise_error(/expected to find field "no such field"/)
587
587
  end
588
588
  end
@@ -590,16 +590,16 @@ describe Capybara::RSpecMatchers do
590
590
  context "with should not" do
591
591
  it "fails if there is such a field and it is checked" do
592
592
  expect do
593
- html.should_not have_checked_field('it is checked')
593
+ expect(html).not_to have_checked_field('it is checked')
594
594
  end.to raise_error(/expected not to find field "it is checked"/)
595
595
  end
596
596
 
597
597
  it "passes if there is such a field but it is not checked" do
598
- html.should_not have_checked_field('unchecked field')
598
+ expect(html).not_to have_checked_field('unchecked field')
599
599
  end
600
600
 
601
601
  it "passes if there is no such field" do
602
- html.should_not have_checked_field('no such field')
602
+ expect(html).not_to have_checked_field('no such field')
603
603
  end
604
604
  end
605
605
  end
@@ -611,23 +611,23 @@ describe Capybara::RSpecMatchers do
611
611
  end
612
612
 
613
613
  it "gives proper description" do
614
- have_unchecked_field('unchecked field').description.should == "have field \"unchecked field\""
614
+ expect(have_unchecked_field('unchecked field').description).to eq("have field \"unchecked field\"")
615
615
  end
616
616
 
617
617
  context "with should" do
618
618
  it "passes if there is such a field and it is not checked" do
619
- html.should have_unchecked_field('unchecked field')
619
+ expect(html).to have_unchecked_field('unchecked field')
620
620
  end
621
621
 
622
622
  it "fails if there is such a field but it is checked" do
623
623
  expect do
624
- html.should have_unchecked_field('it is checked')
624
+ expect(html).to have_unchecked_field('it is checked')
625
625
  end.to raise_error(/expected to find field "it is checked"/)
626
626
  end
627
627
 
628
628
  it "fails if there is no such field" do
629
629
  expect do
630
- html.should have_unchecked_field('no such field')
630
+ expect(html).to have_unchecked_field('no such field')
631
631
  end.to raise_error(/expected to find field "no such field"/)
632
632
  end
633
633
  end
@@ -635,16 +635,16 @@ describe Capybara::RSpecMatchers do
635
635
  context "with should not" do
636
636
  it "fails if there is such a field and it is not checked" do
637
637
  expect do
638
- html.should_not have_unchecked_field('unchecked field')
638
+ expect(html).not_to have_unchecked_field('unchecked field')
639
639
  end.to raise_error(/expected not to find field "unchecked field"/)
640
640
  end
641
641
 
642
642
  it "passes if there is such a field but it is checked" do
643
- html.should_not have_unchecked_field('it is checked')
643
+ expect(html).not_to have_unchecked_field('it is checked')
644
644
  end
645
645
 
646
646
  it "passes if there is no such field" do
647
- html.should_not have_unchecked_field('no such field')
647
+ expect(html).not_to have_unchecked_field('no such field')
648
648
  end
649
649
  end
650
650
  end
@@ -653,16 +653,16 @@ describe Capybara::RSpecMatchers do
653
653
  let(:html) { '<label>Select Box<select></select></label>' }
654
654
 
655
655
  it "gives proper description" do
656
- have_select('Select Box').description.should == "have select box \"Select Box\""
656
+ expect(have_select('Select Box').description).to eq("have select box \"Select Box\"")
657
657
  end
658
658
 
659
659
  it "passes if there is such a select" do
660
- html.should have_select('Select Box')
660
+ expect(html).to have_select('Select Box')
661
661
  end
662
662
 
663
663
  it "fails if there is no such select" do
664
664
  expect do
665
- html.should have_select('No such Select box')
665
+ expect(html).to have_select('No such Select box')
666
666
  end.to raise_error(/expected to find select box "No such Select box"/)
667
667
  end
668
668
  end
@@ -671,16 +671,16 @@ describe Capybara::RSpecMatchers do
671
671
  let(:html) { '<table><caption>Lovely table</caption></table>' }
672
672
 
673
673
  it "gives proper description" do
674
- have_table('Lovely table').description.should == "have table \"Lovely table\""
674
+ expect(have_table('Lovely table').description).to eq("have table \"Lovely table\"")
675
675
  end
676
676
 
677
677
  it "passes if there is such a select" do
678
- html.should have_table('Lovely table')
678
+ expect(html).to have_table('Lovely table')
679
679
  end
680
680
 
681
681
  it "fails if there is no such select" do
682
682
  expect do
683
- html.should have_table('No such Table')
683
+ expect(html).to have_table('No such Table')
684
684
  end.to raise_error(/expected to find table "No such Table"/)
685
685
  end
686
686
  end