capybara_minitest_spec 0.2.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/.rvmrc +1 -1
  2. data/HISTORY.md +0 -0
  3. data/README.md +31 -32
  4. data/Rakefile +2 -2
  5. data/capybara_minitest_spec.gemspec +6 -4
  6. data/lib/capybara_minitest_spec.rb +53 -6
  7. data/lib/capybara_minitest_spec/test_name.rb +67 -0
  8. data/lib/capybara_minitest_spec/version.rb +1 -1
  9. data/spec/capybara_minitest_spec.spec.rb +13 -0
  10. data/spec/capybara_rspec_matchers.spec.rb +580 -0
  11. data/spec/helper.rb +39 -0
  12. data/{test_app → spec/test_app}/test_app.rb +0 -0
  13. data/{test_app → spec/test_app}/views/buttons.erb +0 -0
  14. data/{test_app → spec/test_app}/views/fieldsets.erb +0 -0
  15. data/{test_app → spec/test_app}/views/form.erb +0 -0
  16. data/{test_app → spec/test_app}/views/frame_one.erb +0 -0
  17. data/{test_app → spec/test_app}/views/frame_two.erb +0 -0
  18. data/{test_app → spec/test_app}/views/header_links.erb +0 -0
  19. data/{test_app → spec/test_app}/views/host_links.erb +0 -0
  20. data/{test_app → spec/test_app}/views/popup_one.erb +0 -0
  21. data/{test_app → spec/test_app}/views/popup_two.erb +0 -0
  22. data/{test_app → spec/test_app}/views/postback.erb +0 -0
  23. data/{test_app → spec/test_app}/views/tables.erb +0 -0
  24. data/{test_app → spec/test_app}/views/with_html.erb +0 -0
  25. data/{test_app → spec/test_app}/views/with_html_entities.erb +0 -0
  26. data/{test_app → spec/test_app}/views/with_js.erb +0 -0
  27. data/{test_app → spec/test_app}/views/with_scope.erb +0 -0
  28. data/{test_app → spec/test_app}/views/with_simple_html.erb +0 -0
  29. data/{test_app → spec/test_app}/views/within_frames.erb +0 -0
  30. data/{test_app → spec/test_app}/views/within_popups.erb +0 -0
  31. data/spec/test_name.spec.rb +47 -0
  32. metadata +142 -121
  33. data/lib/capybara_minitest_spec/matcher.rb +0 -126
  34. data/test/capybara_node_matchers_spec.rb +0 -471
  35. data/test/custom_matcher_spec.rb +0 -29
  36. data/test/matcher_spec.rb +0 -45
  37. data/test/spec_helper.rb +0 -14
  38. data/test_app/driver.rb +0 -297
  39. data/test_app/fixtures/capybara.jpg +0 -3
  40. data/test_app/fixtures/test_file.txt +0 -1
  41. data/test_app/public/test.js +0 -43
  42. data/test_app/session.rb +0 -154
  43. data/test_app/session/all_spec.rb +0 -78
  44. data/test_app/session/attach_file_spec.rb +0 -73
  45. data/test_app/session/check_spec.rb +0 -65
  46. data/test_app/session/choose_spec.rb +0 -26
  47. data/test_app/session/click_button_spec.rb +0 -304
  48. data/test_app/session/click_link_or_button_spec.rb +0 -36
  49. data/test_app/session/click_link_spec.rb +0 -119
  50. data/test_app/session/current_host_spec.rb +0 -68
  51. data/test_app/session/current_url_spec.rb +0 -15
  52. data/test_app/session/fill_in_spec.rb +0 -125
  53. data/test_app/session/find_button_spec.rb +0 -18
  54. data/test_app/session/find_by_id_spec.rb +0 -18
  55. data/test_app/session/find_field_spec.rb +0 -26
  56. data/test_app/session/find_link_spec.rb +0 -19
  57. data/test_app/session/find_spec.rb +0 -149
  58. data/test_app/session/first_spec.rb +0 -105
  59. data/test_app/session/has_button_spec.rb +0 -32
  60. data/test_app/session/has_content_spec.rb +0 -106
  61. data/test_app/session/has_css_spec.rb +0 -243
  62. data/test_app/session/has_field_spec.rb +0 -192
  63. data/test_app/session/has_link_spec.rb +0 -37
  64. data/test_app/session/has_select_spec.rb +0 -129
  65. data/test_app/session/has_selector_spec.rb +0 -129
  66. data/test_app/session/has_table_spec.rb +0 -96
  67. data/test_app/session/has_xpath_spec.rb +0 -123
  68. data/test_app/session/headers.rb +0 -19
  69. data/test_app/session/javascript.rb +0 -289
  70. data/test_app/session/response_code.rb +0 -19
  71. data/test_app/session/select_spec.rb +0 -113
  72. data/test_app/session/text_spec.rb +0 -19
  73. data/test_app/session/uncheck_spec.rb +0 -21
  74. data/test_app/session/unselect_spec.rb +0 -61
  75. data/test_app/session/within_spec.rb +0 -178
@@ -1,78 +0,0 @@
1
- shared_examples_for "all" do
2
- describe '#all' do
3
- before do
4
- @session.visit('/with_html')
5
- end
6
-
7
- it "should find all elements using the given locator" do
8
- @session.all('//p').should have(3).elements
9
- @session.all('//h1').first.text.should == 'This is a test'
10
- @session.all("//input[@id='test_field']").first[:value].should == 'monkey'
11
- end
12
-
13
- it "should return an empty array when nothing was found" do
14
- @session.all('//div[@id="nosuchthing"]').should be_empty
15
- end
16
-
17
- it "should accept an XPath instance" do
18
- @session.visit('/form')
19
- @xpath = XPath::HTML.fillable_field('Name')
20
- @result = @session.all(@xpath).map { |r| r.value }
21
- @result.should include('Smith', 'John', 'John Smith')
22
- end
23
-
24
- context "with css selectors" do
25
- it "should find all elements using the given selector" do
26
- @session.all(:css, 'h1').first.text.should == 'This is a test'
27
- @session.all(:css, "input[id='test_field']").first[:value].should == 'monkey'
28
- end
29
-
30
- it "should find all elements when given a list of selectors" do
31
- @session.all(:css, 'h1, p').should have(4).elements
32
- end
33
- end
34
-
35
- context "with xpath selectors" do
36
- it "should find the first element using the given locator" do
37
- @session.all(:xpath, '//h1').first.text.should == 'This is a test'
38
- @session.all(:xpath, "//input[@id='test_field']").first[:value].should == 'monkey'
39
- end
40
- end
41
-
42
- context "with css as default selector" do
43
- before { Capybara.default_selector = :css }
44
- it "should find the first element using the given locator" do
45
- @session.all('h1').first.text.should == 'This is a test'
46
- @session.all("input[id='test_field']").first[:value].should == 'monkey'
47
- end
48
- after { Capybara.default_selector = :xpath }
49
- end
50
-
51
- context "with visible filter" do
52
- after { Capybara.ignore_hidden_elements = false }
53
- it "should only find visible nodes" do
54
- @session.all("//a[@title='awesome title']").should have(2).elements
55
- @session.all("//a[@title='awesome title']", :visible => true).should have(1).elements
56
- Capybara.ignore_hidden_elements = true
57
- @session.all("//a[@title='awesome title']").should have(1).elements
58
- end
59
-
60
- it "should only find invisible nodes" do
61
- Capybara.ignore_hidden_elements = true
62
- @session.all("//a[@title='awesome title']", :visible => false).should have(2).elements
63
- end
64
- end
65
-
66
- context "within a scope" do
67
- before do
68
- @session.visit('/with_scope')
69
- end
70
-
71
- it "should find any element using the given locator" do
72
- @session.within(:xpath, "//div[@id='for_bar']") do
73
- @session.all('.//li').should have(2).elements
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,73 +0,0 @@
1
- shared_examples_for "attach_file" do
2
-
3
- describe "#attach_file" do
4
- before do
5
- @test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
6
- @test_jpg_file_path = File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__))
7
- @session.visit('/form')
8
- end
9
-
10
- context "with normal form" do
11
- it "should set a file path by id" do
12
- @session.attach_file "form_image", __FILE__
13
- @session.click_button('awesome')
14
- extract_results(@session)['image'].should == File.basename(__FILE__)
15
- end
16
-
17
- it "should set a file path by label" do
18
- @session.attach_file "Image", __FILE__
19
- @session.click_button('awesome')
20
- extract_results(@session)['image'].should == File.basename(__FILE__)
21
- end
22
- end
23
-
24
- context "with multipart form" do
25
- it "should set a file path by id" do
26
- @session.attach_file "form_document", @test_file_path
27
- @session.click_button('Upload')
28
- @session.body.should include(File.read(@test_file_path))
29
- end
30
-
31
- it "should set a file path by label" do
32
- @session.attach_file "Document", @test_file_path
33
- @session.click_button('Upload')
34
- @session.body.should include(File.read(@test_file_path))
35
- end
36
-
37
- it "should not break if no file is submitted" do
38
- @session.click_button('Upload')
39
- @session.body.should include('No file uploaded')
40
- end
41
-
42
- it "should send content type text/plain when uploading a text file" do
43
- @session.attach_file "Document", @test_file_path
44
- @session.click_button 'Upload'
45
- @session.body.should include('text/plain')
46
- end
47
-
48
- it "should send content type image/jpeg when uploading an image" do
49
- @session.attach_file "Document", @test_jpg_file_path
50
- @session.click_button 'Upload'
51
- @session.body.should include('image/jpeg')
52
- end
53
-
54
- it "should not break when using HTML5 multiple file input" do
55
- @session.attach_file "Multiple Documents", @test_file_path
56
- @session.click_button('Upload Multiple')
57
- @session.body.should include(File.read(@test_file_path))
58
- end
59
- end
60
-
61
- context "with a locator that doesn't exist" do
62
- it "should raise an error" do
63
- running { @session.attach_file('does not exist', @test_file_path) }.should raise_error(Capybara::ElementNotFound)
64
- end
65
- end
66
-
67
- context "with a path that doesn't exist" do
68
- it "should raise an error" do
69
- running { @session.attach_file('Image', '/no_such_file.png') }.should raise_error(Capybara::FileNotFound)
70
- end
71
- end
72
- end
73
- end
@@ -1,65 +0,0 @@
1
- shared_examples_for "check" do
2
-
3
- describe "#check" do
4
- before do
5
- @session.visit('/form')
6
- end
7
-
8
- describe "'checked' attribute" do
9
- it "should be true if checked" do
10
- @session.check("Terms of Use")
11
- @session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_true
12
- end
13
-
14
- it "should be false if unchecked" do
15
- @session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_false
16
- end
17
- end
18
-
19
- describe "checking" do
20
- it "should not change an already checked checkbox" do
21
- @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
22
- @session.check('form_pets_dog')
23
- @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
24
- end
25
-
26
- it "should check an unchecked checkbox" do
27
- @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
28
- @session.check('form_pets_cat')
29
- @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_true
30
- end
31
- end
32
-
33
- describe "unchecking" do
34
- it "should not change an already unchecked checkbox" do
35
- @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
36
- @session.uncheck('form_pets_cat')
37
- @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
38
- end
39
-
40
- it "should uncheck a checked checkbox" do
41
- @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
42
- @session.uncheck('form_pets_dog')
43
- @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_false
44
- end
45
- end
46
-
47
- it "should check a checkbox by id" do
48
- @session.check("form_pets_cat")
49
- @session.click_button('awesome')
50
- extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
51
- end
52
-
53
- it "should check a checkbox by label" do
54
- @session.check("Cat")
55
- @session.click_button('awesome')
56
- extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
57
- end
58
-
59
- context "with a locator that doesn't exist" do
60
- it "should raise an error" do
61
- running { @session.check('does not exist') }.should raise_error(Capybara::ElementNotFound)
62
- end
63
- end
64
- end
65
- end
@@ -1,26 +0,0 @@
1
- shared_examples_for "choose" do
2
-
3
- describe "#choose" do
4
- before do
5
- @session.visit('/form')
6
- end
7
-
8
- it "should choose a radio button by id" do
9
- @session.choose("gender_male")
10
- @session.click_button('awesome')
11
- extract_results(@session)['gender'].should == 'male'
12
- end
13
-
14
- it "should choose a radio button by label" do
15
- @session.choose("Both")
16
- @session.click_button('awesome')
17
- extract_results(@session)['gender'].should == 'both'
18
- end
19
-
20
- context "with a locator that doesn't exist" do
21
- it "should raise an error" do
22
- running { @session.choose('does not exist') }.should raise_error(Capybara::ElementNotFound)
23
- end
24
- end
25
- end
26
- end
@@ -1,304 +0,0 @@
1
- shared_examples_for "click_button" do
2
- describe '#click_button' do
3
- before do
4
- @session.visit('/form')
5
- end
6
-
7
- context "with multiple values with the same name" do
8
- it "should use the latest given value" do
9
- @session.check('Terms of Use')
10
- @session.click_button('awesome')
11
- extract_results(@session)['terms_of_use'].should == '1'
12
- end
13
- end
14
-
15
- context "with a form that has a relative url as an action" do
16
- it "should post to the correct url" do
17
- @session.click_button('Relative Action')
18
- @session.current_path.should == '/relative'
19
- extract_results(@session)['relative'].should == 'Relative Action'
20
- end
21
- end
22
-
23
- context "with a form that has no action specified" do
24
- it "should post to the correct url" do
25
- @session.click_button('No Action')
26
- @session.current_path.should == '/form'
27
- extract_results(@session)['no_action'].should == 'No Action'
28
- end
29
- end
30
-
31
- context "with value given on a submit button" do
32
- context "on a form with HTML5 fields" do
33
- before do
34
- @session.click_button('html5_submit')
35
- @results = extract_results(@session)
36
- end
37
-
38
- it "should serialise and submit search fields" do
39
- @results['html5_search'].should == 'what are you looking for'
40
- end
41
-
42
- it "should serialise and submit email fields" do
43
- @results['html5_email'].should == 'person@email.com'
44
- end
45
-
46
- it "should serialise and submit url fields" do
47
- @results['html5_url'].should == 'http://www.example.com'
48
- end
49
-
50
- it "should serialise and submit tel fields" do
51
- @results['html5_tel'].should == '911'
52
- end
53
-
54
- it "should serialise and submit color fields" do
55
- @results['html5_color'].should == '#FFFFFF'
56
- end
57
- end
58
-
59
- context "on an HTML4 form" do
60
- before do
61
- @session.click_button('awesome')
62
- @results = extract_results(@session)
63
- end
64
-
65
- it "should serialize and submit text fields" do
66
- @results['first_name'].should == 'John'
67
- end
68
-
69
- it "should escape fields when submitting" do
70
- @results['phone'].should == '+1 555 7021'
71
- end
72
-
73
- it "should serialize and submit password fields" do
74
- @results['password'].should == 'seeekrit'
75
- end
76
-
77
- it "should serialize and submit hidden fields" do
78
- @results['token'].should == '12345'
79
- end
80
-
81
- it "should not serialize fields from other forms" do
82
- @results['middle_name'].should be_nil
83
- end
84
-
85
- it "should submit the button that was clicked, but not other buttons" do
86
- @results['awesome'].should == 'awesome'
87
- @results['crappy'].should be_nil
88
- end
89
-
90
- it "should serialize radio buttons" do
91
- @results['gender'].should == 'female'
92
- end
93
-
94
- it "should serialize check boxes" do
95
- @results['pets'].should include('dog', 'hamster')
96
- @results['pets'].should_not include('cat')
97
- end
98
-
99
- it "should serialize text areas" do
100
- @results['description'].should == 'Descriptive text goes here'
101
- end
102
-
103
- it "should serialize select tag with values" do
104
- @results['locale'].should == 'en'
105
- end
106
-
107
- it "should serialize select tag without values" do
108
- @results['region'].should == 'Norway'
109
- end
110
-
111
- it "should serialize first option for select tag with no selection" do
112
- @results['city'].should == 'London'
113
- end
114
-
115
- it "should not serialize a select tag without options" do
116
- @results['tendency'].should be_nil
117
- end
118
-
119
- it "should not submit disabled fields" do
120
- @results['disabled_text_field'].should be_nil
121
- @results['disabled_textarea'].should be_nil
122
- @results['disabled_checkbox'].should be_nil
123
- @results['disabled_radio'].should be_nil
124
- @results['disabled_select'].should be_nil
125
- @results['disabled_file'].should be_nil
126
- end
127
- end
128
- end
129
-
130
- context "with id given on a submit button" do
131
- it "should submit the associated form" do
132
- @session.click_button('awe123')
133
- extract_results(@session)['first_name'].should == 'John'
134
- end
135
-
136
- it "should work with partial matches" do
137
- @session.click_button('Go')
138
- @session.body.should include('You landed')
139
- end
140
- end
141
-
142
- context "with title given on a submit button" do
143
- it "should submit the associated form" do
144
- @session.click_button('What an Awesome Button')
145
- extract_results(@session)['first_name'].should == 'John'
146
- end
147
-
148
- it "should work with partial matches" do
149
- @session.click_button('What an Awesome')
150
- extract_results(@session)['first_name'].should == 'John'
151
- end
152
- end
153
-
154
- context "with alt given on an image button" do
155
- it "should submit the associated form" do
156
- @session.click_button('oh hai thar')
157
- extract_results(@session)['first_name'].should == 'John'
158
- end
159
-
160
- it "should work with partial matches" do
161
- @session.click_button('hai')
162
- extract_results(@session)['first_name'].should == 'John'
163
- end
164
- end
165
-
166
- context "with value given on an image button" do
167
- it "should submit the associated form" do
168
- @session.click_button('okay')
169
- extract_results(@session)['first_name'].should == 'John'
170
- end
171
-
172
- it "should work with partial matches" do
173
- @session.click_button('kay')
174
- extract_results(@session)['first_name'].should == 'John'
175
- end
176
- end
177
-
178
- context "with id given on an image button" do
179
- it "should submit the associated form" do
180
- @session.click_button('okay556')
181
- extract_results(@session)['first_name'].should == 'John'
182
- end
183
- end
184
-
185
- context "with title given on an image button" do
186
- it "should submit the associated form" do
187
- @session.click_button('Okay 556 Image')
188
- extract_results(@session)['first_name'].should == 'John'
189
- end
190
-
191
- it "should work with partial matches" do
192
- @session.click_button('Okay 556')
193
- extract_results(@session)['first_name'].should == 'John'
194
- end
195
- end
196
-
197
- context "with text given on a button defined by <button> tag" do
198
- it "should submit the associated form" do
199
- @session.click_button('Click me')
200
- extract_results(@session)['first_name'].should == 'John'
201
- end
202
-
203
- it "should work with partial matches" do
204
- @session.click_button('Click')
205
- extract_results(@session)['first_name'].should == 'John'
206
- end
207
-
208
- it "should prefer exact matches over partial matches" do
209
- @session.click_button('Just an input')
210
- extract_results(@session)['button'].should == 'button_second'
211
- end
212
- end
213
-
214
- context "with id given on a button defined by <button> tag" do
215
- it "should submit the associated form" do
216
- @session.click_button('click_me_123')
217
- extract_results(@session)['first_name'].should == 'John'
218
- end
219
-
220
- it "should serialize and send GET forms" do
221
- @session.visit('/form')
222
- @session.click_button('med')
223
- @results = extract_results(@session)
224
- @results['middle_name'].should == 'Darren'
225
- @results['foo'].should be_nil
226
- end
227
- end
228
-
229
- context "with value given on a button defined by <button> tag" do
230
- it "should submit the associated form" do
231
- @session.click_button('click_me')
232
- extract_results(@session)['first_name'].should == 'John'
233
- end
234
-
235
- it "should work with partial matches" do
236
- @session.click_button('ck_me')
237
- extract_results(@session)['first_name'].should == 'John'
238
- end
239
-
240
- it "should prefer exact matches over partial matches" do
241
- @session.click_button('Just a button')
242
- extract_results(@session)['button'].should == 'Just a button'
243
- end
244
- end
245
-
246
- context "with title given on a button defined by <button> tag" do
247
- it "should submit the associated form" do
248
- @session.click_button('Click Title button')
249
- extract_results(@session)['first_name'].should == 'John'
250
- end
251
-
252
- it "should work with partial matches" do
253
- @session.click_button('Click Title')
254
- extract_results(@session)['first_name'].should == 'John'
255
- end
256
- end
257
- context "with a locator that doesn't exist" do
258
- it "should raise an error" do
259
- running do
260
- @session.click_button('does not exist')
261
- end.should raise_error(Capybara::ElementNotFound)
262
- end
263
- end
264
-
265
- it "should serialize and send valueless buttons that were clicked" do
266
- @session.click_button('No Value!')
267
- @results = extract_results(@session)
268
- @results['no_value'].should_not be_nil
269
- end
270
-
271
- it "should not send image buttons that were not clicked" do
272
- @session.click_button('Click me!')
273
- @results = extract_results(@session)
274
- @results['okay'].should be_nil
275
- end
276
-
277
- it "should serialize and send GET forms" do
278
- @session.visit('/form')
279
- @session.click_button('med')
280
- @results = extract_results(@session)
281
- @results['middle_name'].should == 'Darren'
282
- @results['foo'].should be_nil
283
- end
284
-
285
- it "should follow redirects" do
286
- @session.click_button('Go FAR')
287
- @session.current_url.should match(%r{/landed$})
288
- @session.body.should include('You landed')
289
- end
290
-
291
- it "should post pack to the same URL when no action given" do
292
- @session.visit('/postback')
293
- @session.click_button('With no action')
294
- @session.body.should include('Postback')
295
- end
296
-
297
- it "should post pack to the same URL when blank action given" do
298
- @session.visit('/postback')
299
- @session.click_button('With blank action')
300
- @session.body.should include('Postback')
301
- end
302
- end
303
-
304
- end