rcarvalho-capybara 0.4.1.1

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 (100) hide show
  1. data/History.txt +202 -0
  2. data/README.rdoc +540 -0
  3. data/lib/capybara.rb +231 -0
  4. data/lib/capybara/cucumber.rb +32 -0
  5. data/lib/capybara/driver/base.rb +60 -0
  6. data/lib/capybara/driver/celerity_driver.rb +164 -0
  7. data/lib/capybara/driver/culerity_driver.rb +26 -0
  8. data/lib/capybara/driver/node.rb +78 -0
  9. data/lib/capybara/driver/rack_test_driver.rb +303 -0
  10. data/lib/capybara/driver/selenium_driver.rb +165 -0
  11. data/lib/capybara/dsl.rb +109 -0
  12. data/lib/capybara/node/actions.rb +160 -0
  13. data/lib/capybara/node/base.rb +47 -0
  14. data/lib/capybara/node/document.rb +17 -0
  15. data/lib/capybara/node/element.rb +182 -0
  16. data/lib/capybara/node/finders.rb +201 -0
  17. data/lib/capybara/node/matchers.rb +391 -0
  18. data/lib/capybara/node/simple.rb +116 -0
  19. data/lib/capybara/rails.rb +17 -0
  20. data/lib/capybara/rspec.rb +18 -0
  21. data/lib/capybara/selector.rb +70 -0
  22. data/lib/capybara/server.rb +90 -0
  23. data/lib/capybara/session.rb +281 -0
  24. data/lib/capybara/spec/driver.rb +243 -0
  25. data/lib/capybara/spec/fixtures/capybara.jpg +0 -0
  26. data/lib/capybara/spec/fixtures/test_file.txt +1 -0
  27. data/lib/capybara/spec/public/jquery-ui.js +35 -0
  28. data/lib/capybara/spec/public/jquery.js +19 -0
  29. data/lib/capybara/spec/public/test.js +33 -0
  30. data/lib/capybara/spec/session.rb +110 -0
  31. data/lib/capybara/spec/session/all_spec.rb +78 -0
  32. data/lib/capybara/spec/session/attach_file_spec.rb +70 -0
  33. data/lib/capybara/spec/session/check_spec.rb +65 -0
  34. data/lib/capybara/spec/session/choose_spec.rb +26 -0
  35. data/lib/capybara/spec/session/click_button_spec.rb +252 -0
  36. data/lib/capybara/spec/session/click_link_or_button_spec.rb +36 -0
  37. data/lib/capybara/spec/session/click_link_spec.rb +113 -0
  38. data/lib/capybara/spec/session/current_url_spec.rb +15 -0
  39. data/lib/capybara/spec/session/fill_in_spec.rb +119 -0
  40. data/lib/capybara/spec/session/find_button_spec.rb +18 -0
  41. data/lib/capybara/spec/session/find_by_id_spec.rb +18 -0
  42. data/lib/capybara/spec/session/find_field_spec.rb +26 -0
  43. data/lib/capybara/spec/session/find_link_spec.rb +19 -0
  44. data/lib/capybara/spec/session/find_spec.rb +121 -0
  45. data/lib/capybara/spec/session/first_spec.rb +72 -0
  46. data/lib/capybara/spec/session/has_button_spec.rb +32 -0
  47. data/lib/capybara/spec/session/has_content_spec.rb +106 -0
  48. data/lib/capybara/spec/session/has_css_spec.rb +213 -0
  49. data/lib/capybara/spec/session/has_field_spec.rb +156 -0
  50. data/lib/capybara/spec/session/has_link_spec.rb +37 -0
  51. data/lib/capybara/spec/session/has_select_spec.rb +129 -0
  52. data/lib/capybara/spec/session/has_selector_spec.rb +129 -0
  53. data/lib/capybara/spec/session/has_table_spec.rb +96 -0
  54. data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
  55. data/lib/capybara/spec/session/headers.rb +19 -0
  56. data/lib/capybara/spec/session/javascript.rb +223 -0
  57. data/lib/capybara/spec/session/response_code.rb +19 -0
  58. data/lib/capybara/spec/session/select_spec.rb +105 -0
  59. data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
  60. data/lib/capybara/spec/session/unselect_spec.rb +61 -0
  61. data/lib/capybara/spec/session/within_spec.rb +160 -0
  62. data/lib/capybara/spec/test_app.rb +117 -0
  63. data/lib/capybara/spec/views/buttons.erb +4 -0
  64. data/lib/capybara/spec/views/fieldsets.erb +29 -0
  65. data/lib/capybara/spec/views/form.erb +348 -0
  66. data/lib/capybara/spec/views/frame_one.erb +8 -0
  67. data/lib/capybara/spec/views/frame_two.erb +8 -0
  68. data/lib/capybara/spec/views/popup_one.erb +8 -0
  69. data/lib/capybara/spec/views/popup_two.erb +8 -0
  70. data/lib/capybara/spec/views/postback.erb +13 -0
  71. data/lib/capybara/spec/views/tables.erb +122 -0
  72. data/lib/capybara/spec/views/with_html.erb +69 -0
  73. data/lib/capybara/spec/views/with_js.erb +39 -0
  74. data/lib/capybara/spec/views/with_scope.erb +36 -0
  75. data/lib/capybara/spec/views/with_simple_html.erb +1 -0
  76. data/lib/capybara/spec/views/within_frames.erb +10 -0
  77. data/lib/capybara/spec/views/within_popups.erb +25 -0
  78. data/lib/capybara/util/save_and_open_page.rb +40 -0
  79. data/lib/capybara/util/timeout.rb +27 -0
  80. data/lib/capybara/version.rb +3 -0
  81. data/spec/basic_node_spec.rb +77 -0
  82. data/spec/capybara_spec.rb +46 -0
  83. data/spec/driver/celerity_driver_spec.rb +13 -0
  84. data/spec/driver/culerity_driver_spec.rb +14 -0
  85. data/spec/driver/rack_test_driver_spec.rb +84 -0
  86. data/spec/driver/remote_culerity_driver_spec.rb +22 -0
  87. data/spec/driver/remote_selenium_driver_spec.rb +16 -0
  88. data/spec/driver/selenium_driver_spec.rb +14 -0
  89. data/spec/dsl_spec.rb +157 -0
  90. data/spec/rspec_spec.rb +47 -0
  91. data/spec/save_and_open_page_spec.rb +159 -0
  92. data/spec/server_spec.rb +85 -0
  93. data/spec/session/celerity_session_spec.rb +24 -0
  94. data/spec/session/culerity_session_spec.rb +26 -0
  95. data/spec/session/rack_test_session_spec.rb +44 -0
  96. data/spec/session/selenium_session_spec.rb +26 -0
  97. data/spec/spec_helper.rb +40 -0
  98. data/spec/string_spec.rb +77 -0
  99. data/spec/timeout_spec.rb +28 -0
  100. metadata +343 -0
@@ -0,0 +1,72 @@
1
+ shared_examples_for "first" do
2
+ describe '#first' do
3
+ before do
4
+ @session.visit('/with_html')
5
+ end
6
+
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
11
+
12
+ it "should return nil when nothing was found" do
13
+ @session.first('//div[@id="nosuchthing"]').should be_nil
14
+ end
15
+
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
21
+
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
27
+ end
28
+
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
34
+ end
35
+
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 }
43
+ end
44
+
45
+ context "with visible filter" do
46
+ after { Capybara.ignore_hidden_elements = false }
47
+ it "should only find visible nodes" do
48
+ @session.first(:css, "a.visibility").should_not be_visible
49
+ @session.first(:css, "a.visibility", :visible => true).should be_visible
50
+ Capybara.ignore_hidden_elements = true
51
+ @session.first(:css, "a.visibility").should be_visible
52
+ end
53
+
54
+ it "should only find invisible nodes" do
55
+ Capybara.ignore_hidden_elements = true
56
+ @session.first(:css, "a.visibility", :visible => false).should_not be_visible
57
+ end
58
+ end
59
+
60
+ context "within a scope" do
61
+ before do
62
+ @session.visit('/with_scope')
63
+ end
64
+
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
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,32 @@
1
+ shared_examples_for "has_button" do
2
+ describe '#has_button?' do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
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
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
15
+ end
16
+
17
+ describe '#has_no_button?' do
18
+ before do
19
+ @session.visit('/form')
20
+ end
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
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
30
+ end
31
+ end
32
+
@@ -0,0 +1,106 @@
1
+ shared_examples_for "has_content" do
2
+ describe '#has_content?' do
3
+ it "should be true if the given content is on the page at least once" do
4
+ @session.visit('/with_html')
5
+ @session.should have_content('est')
6
+ @session.should have_content('Lorem')
7
+ @session.should have_content('Redirect')
8
+ end
9
+
10
+ it "should be true if scoped to an element which has the content" do
11
+ @session.visit('/with_html')
12
+ @session.within("//a[@title='awesome title']") do
13
+ @session.should have_content('labore')
14
+ end
15
+ end
16
+
17
+ it "should be false if scoped to an element which does not have the content" do
18
+ @session.visit('/with_html')
19
+ @session.within("//a[@title='awesome title']") do
20
+ @session.should_not have_content('monkey')
21
+ end
22
+ end
23
+
24
+ it "should ignore tags" do
25
+ @session.visit('/with_html')
26
+ @session.should_not have_content('exercitation <a href="/foo" id="foo">ullamco</a> laboris')
27
+ @session.should have_content('exercitation ullamco laboris')
28
+ end
29
+
30
+ it "should ignore extra whitespace and newlines" do
31
+ @session.visit('/with_html')
32
+ @session.should have_content('text with whitespace')
33
+ end
34
+
35
+ it "should be false if the given content is not on the page" do
36
+ @session.visit('/with_html')
37
+ @session.should_not have_content('xxxxyzzz')
38
+ @session.should_not have_content('monkey')
39
+ end
40
+
41
+ it 'should handle single quotes in the content' do
42
+ @session.visit('/with-quotes')
43
+ @session.should have_content("can't")
44
+ end
45
+
46
+ it 'should handle double quotes in the content' do
47
+ @session.visit('/with-quotes')
48
+ @session.should have_content(%q{"No," he said})
49
+ end
50
+
51
+ it 'should handle mixed single and double quotes in the content' do
52
+ @session.visit('/with-quotes')
53
+ @session.should have_content(%q{"you can't do that."})
54
+ end
55
+ end
56
+
57
+ describe '#has_no_content?' do
58
+ it "should be false if the given content is on the page at least once" do
59
+ @session.visit('/with_html')
60
+ @session.should_not have_no_content('est')
61
+ @session.should_not have_no_content('Lorem')
62
+ @session.should_not have_no_content('Redirect')
63
+ end
64
+
65
+ it "should be false if scoped to an element which has the content" do
66
+ @session.visit('/with_html')
67
+ @session.within("//a[@title='awesome title']") do
68
+ @session.should_not have_no_content('labore')
69
+ end
70
+ end
71
+
72
+ it "should be true if scoped to an element which does not have the content" do
73
+ @session.visit('/with_html')
74
+ @session.within("//a[@title='awesome title']") do
75
+ @session.should have_no_content('monkey')
76
+ end
77
+ end
78
+
79
+ it "should ignore tags" do
80
+ @session.visit('/with_html')
81
+ @session.should have_no_content('exercitation <a href="/foo" id="foo">ullamco</a> laboris')
82
+ @session.should_not have_no_content('exercitation ullamco laboris')
83
+ end
84
+
85
+ it "should be true if the given content is not on the page" do
86
+ @session.visit('/with_html')
87
+ @session.should have_no_content('xxxxyzzz')
88
+ @session.should have_no_content('monkey')
89
+ end
90
+
91
+ it 'should handle single quotes in the content' do
92
+ @session.visit('/with-quotes')
93
+ @session.should_not have_no_content("can't")
94
+ end
95
+
96
+ it 'should handle double quotes in the content' do
97
+ @session.visit('/with-quotes')
98
+ @session.should_not have_no_content(%q{"No," he said})
99
+ end
100
+
101
+ it 'should handle mixed single and double quotes in the content' do
102
+ @session.visit('/with-quotes')
103
+ @session.should_not have_no_content(%q{"you can't do that."})
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,213 @@
1
+ shared_examples_for "has_css" do
2
+ describe '#has_css?' do
3
+ before do
4
+ @session.visit('/with_html')
5
+ end
6
+
7
+ it "should be true if the given selector is on the page" do
8
+ @session.should have_css("p")
9
+ @session.should have_css("p a#foo")
10
+ end
11
+
12
+ it "should be false if the given selector is not on the page" do
13
+ @session.should_not have_css("abbr")
14
+ @session.should_not have_css("p a#doesnotexist")
15
+ @session.should_not have_css("p.nosuchclass")
16
+ end
17
+
18
+ it "should respect scopes" do
19
+ @session.within "//p[@id='first']" do
20
+ @session.should have_css("a#foo")
21
+ @session.should_not have_css("a#red")
22
+ end
23
+ end
24
+
25
+ context "with between" do
26
+ it "should be true if the content occurs within the range given" do
27
+ @session.should have_css("p", :between => 1..4)
28
+ @session.should have_css("p a#foo", :between => 1..3)
29
+ end
30
+
31
+ it "should be false if the content occurs more or fewer times than range" do
32
+ @session.should_not have_css("p", :between => 6..11 )
33
+ @session.should_not have_css("p a#foo", :between => 4..7)
34
+ end
35
+
36
+ it "should be false if the content isn't on the page at all" do
37
+ @session.should_not have_css("abbr", :between => 1..8)
38
+ @session.should_not have_css("p a.doesnotexist", :between => 3..8)
39
+ end
40
+ end
41
+
42
+ context "with count" do
43
+ it "should be true if the content is on the page the given number of times" do
44
+ @session.should have_css("p", :count => 3)
45
+ @session.should have_css("p a#foo", :count => 1)
46
+ end
47
+
48
+ it "should be false if the content occurs the given number of times" do
49
+ @session.should_not have_css("p", :count => 6)
50
+ @session.should_not have_css("p a#foo", :count => 2)
51
+ end
52
+
53
+ it "should be false if the content isn't on the page at all" do
54
+ @session.should_not have_css("abbr", :count => 2)
55
+ @session.should_not have_css("p a.doesnotexist", :count => 1)
56
+ end
57
+ end
58
+
59
+ context "with maximum" do
60
+ it "should be true when content occurs same or fewer times than given" do
61
+ @session.should have_css("h2.head", :maximum => 5) # edge case
62
+ @session.should have_css("h2", :maximum => 10)
63
+ end
64
+
65
+ it "should be false when content occurs more times than given" do
66
+ @session.should_not have_css("h2.head", :maximum => 4) # edge case
67
+ @session.should_not have_css("h2", :maximum => 6)
68
+ @session.should_not have_css("p", :maximum => 1)
69
+ end
70
+
71
+ it "should be false if the content isn't on the page at all" do
72
+ @session.should_not have_css("abbr", :maximum => 2)
73
+ @session.should_not have_css("p a.doesnotexist", :maximum => 1)
74
+ end
75
+ end
76
+
77
+ context "with minimum" do
78
+ it "should be true when content occurs same or more times than given" do
79
+ @session.should have_css("h2.head", :minimum => 5) # edge case
80
+ @session.should have_css("h2", :minimum => 3)
81
+ end
82
+
83
+ it "should be false when content occurs fewer times than given" do
84
+ @session.should_not have_css("h2.head", :minimum => 6) # edge case
85
+ @session.should_not have_css("h2", :minimum => 8)
86
+ @session.should_not have_css("p", :minimum => 10)
87
+ end
88
+
89
+ it "should be false if the content isn't on the page at all" do
90
+ @session.should_not have_css("abbr", :minimum => 2)
91
+ @session.should_not have_css("p a.doesnotexist", :minimum => 7)
92
+ end
93
+ end
94
+
95
+ context "with text" do
96
+ it "should discard all matches where the given string is not contained" do
97
+ @session.should have_css("p a", :text => "Redirect", :count => 1)
98
+ @session.should_not have_css("p a", :text => "Doesnotexist")
99
+ end
100
+
101
+ it "should discard all matches where the given regexp is not matched" do
102
+ @session.should have_css("p a", :text => /re[dab]i/i, :count => 1)
103
+ @session.should_not have_css("p a", :text => /Red$/)
104
+ end
105
+ end
106
+ end
107
+
108
+ describe '#has_no_css?' do
109
+ before do
110
+ @session.visit('/with_html')
111
+ end
112
+
113
+ it "should be false if the given selector is on the page" do
114
+ @session.should_not have_no_css("p")
115
+ @session.should_not have_no_css("p a#foo")
116
+ end
117
+
118
+ it "should be true if the given selector is not on the page" do
119
+ @session.should have_no_css("abbr")
120
+ @session.should have_no_css("p a#doesnotexist")
121
+ @session.should have_no_css("p.nosuchclass")
122
+ end
123
+
124
+ it "should respect scopes" do
125
+ @session.within "//p[@id='first']" do
126
+ @session.should_not have_no_css("a#foo")
127
+ @session.should have_no_css("a#red")
128
+ end
129
+ end
130
+
131
+ context "with between" do
132
+ it "should be false if the content occurs within the range given" do
133
+ @session.should_not have_no_css("p", :between => 1..4)
134
+ @session.should_not have_no_css("p a#foo", :between => 1..3)
135
+ end
136
+
137
+ it "should be true if the content occurs more or fewer times than range" do
138
+ @session.should have_no_css("p", :between => 6..11 )
139
+ @session.should have_no_css("p a#foo", :between => 4..7)
140
+ end
141
+
142
+ it "should be true if the content isn't on the page at all" do
143
+ @session.should have_no_css("abbr", :between => 1..8)
144
+ @session.should have_no_css("p a.doesnotexist", :between => 3..8)
145
+ end
146
+ end
147
+
148
+ context "with count" do
149
+ it "should be false if the content is on the page the given number of times" do
150
+ @session.should_not have_no_css("p", :count => 3)
151
+ @session.should_not have_no_css("p a#foo", :count => 1)
152
+ end
153
+
154
+ it "should be true if the content is on the page the given number of times" do
155
+ @session.should have_no_css("p", :count => 6)
156
+ @session.should have_no_css("p a#foo", :count => 2)
157
+ end
158
+
159
+ it "should be true if the content isn't on the page at all" do
160
+ @session.should have_no_css("abbr", :count => 2)
161
+ @session.should have_no_css("p a.doesnotexist", :count => 1)
162
+ end
163
+ end
164
+
165
+ context "with maximum" do
166
+ it "should be false when content occurs same or fewer times than given" do
167
+ @session.should_not have_no_css("h2.head", :maximum => 5) # edge case
168
+ @session.should_not have_no_css("h2", :maximum => 10)
169
+ end
170
+
171
+ it "should be true when content occurs more times than given" do
172
+ @session.should have_no_css("h2.head", :maximum => 4) # edge case
173
+ @session.should have_no_css("h2", :maximum => 6)
174
+ @session.should have_no_css("p", :maximum => 1)
175
+ end
176
+
177
+ it "should be true if the content isn't on the page at all" do
178
+ @session.should have_no_css("abbr", :maximum => 5)
179
+ @session.should have_no_css("p a.doesnotexist", :maximum => 10)
180
+ end
181
+ end
182
+
183
+ context "with minimum" do
184
+ it "should be false when content occurs more times than given" do
185
+ @session.should_not have_no_css("h2.head", :minimum => 4) # edge case
186
+ @session.should_not have_no_css("h2", :minimum => 3)
187
+ end
188
+
189
+ it "should be true when content occurs fewer times than given" do
190
+ @session.should have_no_css("h2.head", :minimum => 6) # edge case
191
+ @session.should have_no_css("h2", :minimum => 8)
192
+ @session.should have_no_css("p", :minimum => 15)
193
+ end
194
+
195
+ it "should be true if the content isn't on the page at all" do
196
+ @session.should have_no_css("abbr", :minimum => 5)
197
+ @session.should have_no_css("p a.doesnotexist", :minimum => 10)
198
+ end
199
+ end
200
+
201
+ context "with text" do
202
+ it "should discard all matches where the given string is not contained" do
203
+ @session.should_not have_no_css("p a", :text => "Redirect", :count => 1)
204
+ @session.should have_no_css("p a", :text => "Doesnotexist")
205
+ end
206
+
207
+ it "should discard all matches where the given regexp is not matched" do
208
+ @session.should_not have_no_css("p a", :text => /re[dab]i/i, :count => 1)
209
+ @session.should have_no_css("p a", :text => /Red$/)
210
+ end
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,156 @@
1
+ shared_examples_for "has_field" do
2
+ describe '#has_field' do
3
+ before { @session.visit('/form') }
4
+
5
+ it "should be true if the field is on the page" do
6
+ @session.should have_field('Dog')
7
+ @session.should have_field('form_description')
8
+ @session.should have_field('Region')
9
+ end
10
+
11
+ it "should be false if the field is not on the page" do
12
+ @session.should_not have_field('Monkey')
13
+ end
14
+
15
+ context 'with value' do
16
+ it "should be true if a field with the given value is on the page" do
17
+ @session.should have_field('First Name', :with => 'John')
18
+ @session.should have_field('Phone', :with => '+1 555 7021')
19
+ @session.should have_field('Street', :with => 'Sesame street 66')
20
+ @session.should have_field('Description', :with => 'Descriptive text goes here')
21
+ end
22
+
23
+ it "should be false if the given field is not on the page" do
24
+ @session.should_not have_field('First Name', :with => 'Peter')
25
+ @session.should_not have_field('Wrong Name', :with => 'John')
26
+ @session.should_not have_field('Description', :with => 'Monkey')
27
+ end
28
+
29
+ it "should be true after the field has been filled in with the given value" do
30
+ @session.fill_in('First Name', :with => 'Jonas')
31
+ @session.should have_field('First Name', :with => 'Jonas')
32
+ end
33
+
34
+ it "should be false after the field has been filled in with a different value" do
35
+ @session.fill_in('First Name', :with => 'Jonas')
36
+ @session.should_not have_field('First Name', :with => 'John')
37
+ end
38
+ end
39
+ end
40
+
41
+ describe '#has_no_field' do
42
+ before { @session.visit('/form') }
43
+
44
+ it "should be false if the field is on the page" do
45
+ @session.should_not have_no_field('Dog')
46
+ @session.should_not have_no_field('form_description')
47
+ @session.should_not have_no_field('Region')
48
+ end
49
+
50
+ it "should be true if the field is not on the page" do
51
+ @session.should have_no_field('Monkey')
52
+ end
53
+
54
+ context 'with value' do
55
+ it "should be false if a field with the given value is on the page" do
56
+ @session.should_not have_no_field('First Name', :with => 'John')
57
+ @session.should_not have_no_field('Phone', :with => '+1 555 7021')
58
+ @session.should_not have_no_field('Street', :with => 'Sesame street 66')
59
+ @session.should_not have_no_field('Description', :with => 'Descriptive text goes here')
60
+ end
61
+
62
+ it "should be true if the given field is not on the page" do
63
+ @session.should have_no_field('First Name', :with => 'Peter')
64
+ @session.should have_no_field('Wrong Name', :with => 'John')
65
+ @session.should have_no_field('Description', :with => 'Monkey')
66
+ end
67
+
68
+ it "should be false after the field has been filled in with the given value" do
69
+ @session.fill_in('First Name', :with => 'Jonas')
70
+ @session.should_not have_no_field('First Name', :with => 'Jonas')
71
+ end
72
+
73
+ it "should be true after the field has been filled in with a different value" do
74
+ @session.fill_in('First Name', :with => 'Jonas')
75
+ @session.should have_no_field('First Name', :with => 'John')
76
+ end
77
+ end
78
+ end
79
+
80
+ describe '#has_checked_field?' do
81
+ before { @session.visit('/form') }
82
+
83
+ it "should be true if a checked field is on the page" do
84
+ @session.should have_checked_field('gender_female')
85
+ @session.should have_checked_field('Hamster')
86
+ end
87
+
88
+ it "should be false if an unchecked field is on the page" do
89
+ @session.should_not have_checked_field('form_pets_cat')
90
+ @session.should_not have_checked_field('Male')
91
+ end
92
+
93
+ it "should be false if no field is on the page" do
94
+ @session.should_not have_checked_field('Does Not Exist')
95
+ end
96
+
97
+ it "should be true after an unchecked checkbox is checked" do
98
+ @session.check('form_pets_cat')
99
+ @session.should have_checked_field('form_pets_cat')
100
+ end
101
+
102
+ it "should be false after a checked checkbox is unchecked" do
103
+ @session.uncheck('form_pets_dog')
104
+ @session.should_not have_checked_field('form_pets_dog')
105
+ end
106
+
107
+ it "should be true after an unchecked radio button is chosen" do
108
+ @session.choose('gender_male')
109
+ @session.should have_checked_field('gender_male')
110
+ end
111
+
112
+ it "should be false after another radio button in the group is chosen" do
113
+ @session.choose('gender_male')
114
+ @session.should_not have_checked_field('gender_female')
115
+ end
116
+ end
117
+
118
+ describe '#has_unchecked_field?' do
119
+ before { @session.visit('/form') }
120
+
121
+ it "should be false if a checked field is on the page" do
122
+ @session.should_not have_unchecked_field('gender_female')
123
+ @session.should_not have_unchecked_field('Hamster')
124
+ end
125
+
126
+ it "should be true if an unchecked field is on the page" do
127
+ @session.should have_unchecked_field('form_pets_cat')
128
+ @session.should have_unchecked_field('Male')
129
+ end
130
+
131
+ it "should be false if no field is on the page" do
132
+ @session.should_not have_unchecked_field('Does Not Exist')
133
+ end
134
+
135
+ it "should be false after an unchecked checkbox is checked" do
136
+ @session.check('form_pets_cat')
137
+ @session.should_not have_unchecked_field('form_pets_cat')
138
+ end
139
+
140
+ it "should be true after a checked checkbox is unchecked" do
141
+ @session.uncheck('form_pets_dog')
142
+ @session.should have_unchecked_field('form_pets_dog')
143
+ end
144
+
145
+ it "should be false after an unchecked radio button is chosen" do
146
+ @session.choose('gender_male')
147
+ @session.should_not have_unchecked_field('gender_male')
148
+ end
149
+
150
+ it "should be true after another radio button in the group is chosen" do
151
+ @session.choose('gender_male')
152
+ @session.should have_unchecked_field('gender_female')
153
+ end
154
+ end
155
+ end
156
+