hermes 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. data/README.rdoc +4 -0
  2. data/lib/hermes.rb +7 -1
  3. data/lib/hermes/actions.rb +81 -0
  4. data/lib/hermes/assertions.rb +34 -29
  5. data/lib/hermes/builders.rb +46 -21
  6. data/lib/hermes/context.rb +0 -2
  7. data/lib/hermes/integration_case.rb +7 -3
  8. data/lib/hermes/rails.rb +4 -0
  9. data/lib/hermes/scopes.rb +32 -0
  10. data/lib/hermes/version.rb +1 -1
  11. data/test/builders.rb +13 -0
  12. data/test/fixtures/users.yml +4 -0
  13. data/test/hermes/actions_test.rb +118 -0
  14. data/test/hermes/assertions_test.rb +493 -0
  15. data/test/hermes/builders_test.rb +109 -0
  16. data/test/hermes/context_test.rb +5 -0
  17. data/test/hermes/scopes_test.rb +47 -0
  18. data/test/rails_app/Rakefile +7 -0
  19. data/test/rails_app/app/controllers/application_controller.rb +3 -0
  20. data/test/rails_app/app/controllers/users_controller.rb +23 -0
  21. data/test/rails_app/app/helpers/application_helper.rb +2 -0
  22. data/test/rails_app/app/models/user.rb +11 -0
  23. data/test/rails_app/app/views/layouts/application.html.erb +14 -0
  24. data/test/rails_app/app/views/users/index.html.erb +10 -0
  25. data/test/rails_app/app/views/users/new.html.erb +62 -0
  26. data/test/rails_app/config.ru +4 -0
  27. data/test/rails_app/config/application.rb +42 -0
  28. data/test/rails_app/config/boot.rb +10 -0
  29. data/test/rails_app/config/database.yml +20 -0
  30. data/test/rails_app/config/environment.rb +5 -0
  31. data/test/rails_app/config/environments/development.rb +26 -0
  32. data/test/rails_app/config/environments/production.rb +49 -0
  33. data/test/rails_app/config/environments/test.rb +35 -0
  34. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  35. data/test/rails_app/config/initializers/inflections.rb +10 -0
  36. data/test/rails_app/config/initializers/mime_types.rb +5 -0
  37. data/test/rails_app/config/initializers/secret_token.rb +7 -0
  38. data/test/rails_app/config/initializers/session_store.rb +8 -0
  39. data/test/rails_app/config/locales/en.yml +5 -0
  40. data/test/rails_app/config/routes.rb +7 -0
  41. data/test/rails_app/db/migrate/20110228170406_create_users.rb +15 -0
  42. data/test/rails_app/db/schema.rb +21 -0
  43. data/test/rails_app/log/development.log +29 -0
  44. data/test/rails_app/log/production.log +0 -0
  45. data/test/rails_app/log/server.log +0 -0
  46. data/test/rails_app/log/test.log +1519 -0
  47. data/test/rails_app/public/404.html +26 -0
  48. data/test/rails_app/public/422.html +26 -0
  49. data/test/rails_app/public/500.html +26 -0
  50. data/test/rails_app/public/favicon.ico +0 -0
  51. data/test/rails_app/public/javascripts/application.js +2 -0
  52. data/test/rails_app/public/javascripts/controls.js +965 -0
  53. data/test/rails_app/public/javascripts/dragdrop.js +974 -0
  54. data/test/rails_app/public/javascripts/effects.js +1123 -0
  55. data/test/rails_app/public/javascripts/prototype.js +6001 -0
  56. data/test/rails_app/public/javascripts/rails.js +191 -0
  57. data/test/rails_app/script/rails +6 -0
  58. data/test/support/assertions.rb +23 -0
  59. data/test/support/models.rb +11 -0
  60. data/test/test_helper.rb +29 -3
  61. metadata +108 -7
@@ -0,0 +1,493 @@
1
+ require 'test_helper'
2
+
3
+ class AssertionsTest < Hermes::IntegrationCase
4
+ fixtures :users
5
+
6
+ context "#assert_current_path" do
7
+ setup do
8
+ visit '/users'
9
+ end
10
+
11
+ test 'assert equal path' do
12
+ assert_current_path '/users'
13
+ end
14
+
15
+ test 'refuse different path' do
16
+ msg = %Q(<"/not_a_valid_path"> expected but was\n<"/users">.)
17
+
18
+ assert_failure(msg) do
19
+ assert_current_path '/not_a_valid_path'
20
+ end
21
+ end
22
+ end
23
+
24
+ context "#assert_difference_on_click_button" do
25
+ setup do
26
+ visit '/users/new'
27
+ end
28
+
29
+ test 'assert difference exists on click button' do
30
+ fill_in :name, :with => 'User'
31
+ assert_difference_on_click_button('Submit', 'User.count')
32
+ end
33
+
34
+ test "refuse if difference doesn't exist" do
35
+ # There's already a user in fixtures
36
+ msg = "\"User.count\" didn't change by 1.\n" <<
37
+ "<2> expected but was\n" <<
38
+ "<1>."
39
+
40
+ assert_failure msg do
41
+ assert_difference_on_click_button('Submit', 'User.count')
42
+ end
43
+ end
44
+ end
45
+
46
+ context "#assert_difference_on_click_link" do
47
+ test 'assert difference exists on click link' do
48
+ create_user
49
+ visit '/users'
50
+
51
+ assert_difference_on_click_link 'Block', 'User.blocked.count'
52
+ end
53
+
54
+ test "refuse if difference doesn't exist" do
55
+ msg = "\"User.blocked.count\" didn't change by 1.\n" <<
56
+ "<1> expected but was\n" <<
57
+ "<0>."
58
+
59
+ create_user
60
+ visit '/users'
61
+
62
+ assert_failure msg do
63
+ assert_difference_on_click_link 'New', 'User.blocked.count'
64
+ end
65
+ end
66
+ end
67
+
68
+ context "#assert_content" do
69
+ test 'assert content on success' do
70
+ visit '/users'
71
+ assert_content 'New'
72
+ end
73
+
74
+ test 'refuse content that does not exist' do
75
+ random_content = random_string
76
+
77
+ visit '/users'
78
+ assert_failure(/Expected to have #{random_content}/)do
79
+ assert_content random_content
80
+ end
81
+ end
82
+ end
83
+
84
+ context "#assert_no_content" do
85
+ test 'assert no content on success' do
86
+ visit '/users'
87
+
88
+ assert_no_content random_string
89
+ end
90
+
91
+ test 'refuse content that does not exist' do
92
+ visit '/users'
93
+
94
+ assert_failure(/Expected to have no content New/)do
95
+ assert_no_content 'New'
96
+ end
97
+ end
98
+ end
99
+
100
+ context "#assert_xpath" do
101
+ test 'assert_xpath on success' do
102
+ visit '/users'
103
+ assert_xpath "//div[@id='users']"
104
+ end
105
+
106
+ test 'refuse content that does not exist' do
107
+ random_content = random_string
108
+
109
+ visit '/users'
110
+
111
+ assert_failure(/Expected to have xpath/) do
112
+ assert_xpath "//div[@id='#{random_content}']"
113
+ end
114
+ end
115
+ end
116
+
117
+ context "#assert_no_xpath" do
118
+ test 'assert_no_xpath on success' do
119
+ random_content = random_string
120
+
121
+ visit '/users'
122
+
123
+ assert_no_xpath "//div[@id='#{random_content}']"
124
+ end
125
+
126
+ test 'refuse content that does not exist' do
127
+ visit '/users'
128
+
129
+ assert_failure(/Expected to have no xpath/) do
130
+ assert_no_xpath "//div[@id='users']"
131
+ end
132
+ end
133
+ end
134
+
135
+ context "#assert_css" do
136
+ test 'assert_css on success' do
137
+ visit '/users'
138
+ assert_css "div#users"
139
+ end
140
+
141
+ test 'refuse content that does not exist' do
142
+ random_content = random_string
143
+
144
+ visit '/users'
145
+
146
+ assert_failure(/Expected to have css/) do
147
+ assert_css "div##{random_content}"
148
+ end
149
+ end
150
+ end
151
+
152
+ context "#assert_no_css" do
153
+ test 'assert_no_css on success' do
154
+ random_content = random_string
155
+
156
+ visit '/users'
157
+
158
+ assert_no_css "div##{random_content}"
159
+ end
160
+
161
+ test 'refuse content that does not exist' do
162
+ visit '/users'
163
+
164
+ assert_failure(/Expected to have no css/) do
165
+ assert_no_css "div#users"
166
+ end
167
+ end
168
+ end
169
+
170
+ context "#assert_link" do
171
+ test 'assert_link on success' do
172
+ visit '/users'
173
+ assert_link "New"
174
+ end
175
+
176
+ test 'refuse content that does not exist' do
177
+ random_content = random_string
178
+
179
+ visit '/users'
180
+
181
+ assert_failure(/Expected to have link/) do
182
+ assert_link random_content
183
+ end
184
+ end
185
+ end
186
+
187
+ context "#assert_no_link" do
188
+ test 'assert_no_link on success' do
189
+ random_content = random_string
190
+
191
+ visit '/users'
192
+
193
+ assert_no_link random_content
194
+ end
195
+
196
+ test 'refuse content that does not exist' do
197
+ visit '/users'
198
+
199
+ assert_failure(/Expected to have no link/) do
200
+ assert_no_link "New"
201
+ end
202
+ end
203
+ end
204
+
205
+ context "#assert_select" do
206
+ test 'assert_select on success' do
207
+ visit '/users/new'
208
+ assert_select "Useless select"
209
+ end
210
+
211
+ test 'refuse content that does not exist' do
212
+ random_content = random_string
213
+
214
+ visit '/users/new'
215
+
216
+ assert_failure(/Expected to have select/) do
217
+ assert_select random_content
218
+ end
219
+ end
220
+ end
221
+
222
+ context "#assert_no_select" do
223
+ test 'assert_no_select on success' do
224
+ random_content = random_string
225
+
226
+ visit '/users/new'
227
+
228
+ assert_no_select random_content
229
+ end
230
+
231
+ test 'refuse select that does exist' do
232
+ visit '/users/new'
233
+
234
+ assert_failure(/Expected to have no select/) do
235
+ assert_no_select "Useless select"
236
+ end
237
+ end
238
+ end
239
+
240
+ context "#assert_field" do
241
+ test 'assert_field on success' do
242
+ visit '/users/new'
243
+ assert_field "Name"
244
+ end
245
+
246
+ test 'refuse field that does not exist' do
247
+ random_content = random_string
248
+
249
+ visit '/users/new'
250
+
251
+ assert_failure(/Expected to have field/) do
252
+ assert_field random_content
253
+ end
254
+ end
255
+ end
256
+
257
+ context "#assert_no_field" do
258
+ test 'assert_no_field on success' do
259
+ random_content = random_string
260
+
261
+ visit '/users/new'
262
+
263
+ assert_no_field random_content
264
+ end
265
+
266
+ test 'refuse field that does exist' do
267
+ visit '/users/new'
268
+
269
+ assert_failure(/Expected to have no field/) do
270
+ assert_no_field "Name"
271
+ end
272
+ end
273
+ end
274
+
275
+ context "#assert_button" do
276
+ test 'assert_button on success' do
277
+ visit '/users/new'
278
+ assert_button "Submit"
279
+ end
280
+
281
+ test 'refuse button that does not exist' do
282
+ random_content = random_string
283
+
284
+ visit '/users/new'
285
+
286
+ assert_failure(/Expected to have button/) do
287
+ assert_button random_content
288
+ end
289
+ end
290
+ end
291
+
292
+ context "#assert_no_button" do
293
+ test 'assert_no_button on success' do
294
+ random_content = random_string
295
+
296
+ visit '/users/new'
297
+
298
+ assert_no_button random_content
299
+ end
300
+
301
+ test 'refuse button that does exist' do
302
+ visit '/users/new'
303
+
304
+ assert_failure(/Expected to have no button/) do
305
+ assert_no_button 'Submit'
306
+ end
307
+ end
308
+ end
309
+
310
+ context "#assert_checked_field" do
311
+ test 'assert_checked_field on success' do
312
+ visit '/users/new'
313
+ assert_checked_field "Useless checkbox"
314
+ end
315
+
316
+ test 'refuse checkbox that does not exist' do
317
+ random_content = random_string
318
+
319
+ visit '/users/new'
320
+
321
+ assert_failure(/Expected to have checked field/) do
322
+ assert_checked_field random_content
323
+ end
324
+ end
325
+ end
326
+
327
+ context "#assert_unchecked_field" do
328
+ test 'assert_unchecked_field on success' do
329
+ visit '/users/new'
330
+ assert_unchecked_field "Useless unchecked checkbox"
331
+ end
332
+
333
+ test 'refuse unchecked field that does not exist' do
334
+ random_content = random_string
335
+
336
+ visit '/users/new'
337
+
338
+ assert_failure(/Expected to have unchecked field/) do
339
+ assert_unchecked_field random_content
340
+ end
341
+ end
342
+ end
343
+
344
+ context "#assert_selector" do
345
+ test 'assert_selector on success' do
346
+ visit '/users'
347
+ assert_selector :xpath, "//div[@id='users']"
348
+ end
349
+
350
+ test 'refuse selector that does not exist' do
351
+ random_content = random_string
352
+
353
+ visit '/users'
354
+
355
+ assert_failure(/Expected to have selector/) do
356
+ assert_selector :xpath, "//div[@id='#{random_content}']"
357
+ end
358
+ end
359
+ end
360
+
361
+ context "#assert_no_selector" do
362
+ test 'assert_no_selector on success' do
363
+ random_content = random_string
364
+
365
+ visit '/users'
366
+
367
+ assert_no_selector "div##{random_content}"
368
+ end
369
+
370
+ test 'refuse selector that does exist' do
371
+ visit '/users'
372
+
373
+ assert_failure(/Expected to have no selector/) do
374
+ assert_no_selector "div#users"
375
+ end
376
+ end
377
+ end
378
+
379
+ context "#assert_table" do
380
+ test 'assert_table on success' do
381
+ visit '/users/new'
382
+
383
+ assert_table "Useless Table", :rows => table_rows
384
+ end
385
+
386
+ test 'refuse table that does not exist' do
387
+ random_content = random_string
388
+
389
+ visit '/users/new'
390
+
391
+ assert_failure(/Expected to have table/) do
392
+ assert_table random_content
393
+ end
394
+ end
395
+ end
396
+
397
+ context "#assert_no_table" do
398
+ test 'assert_no_table on success' do
399
+ random_content = random_string
400
+
401
+ visit '/users/new'
402
+
403
+ assert_no_table random_content
404
+ end
405
+
406
+ test 'refuse table that does exist' do
407
+ visit '/users/new'
408
+
409
+ assert_failure(/Expected to have no table/) do
410
+ assert_no_table "Useless Table", :rows => table_rows
411
+ end
412
+ end
413
+ end
414
+
415
+ context "#assert_mail_deliveries" do
416
+ teardown do
417
+ ActionMailer::Base.deliveries = []
418
+ end
419
+
420
+ test 'verify deliveries size with 1 new email' do
421
+ assert_mail_deliveries do
422
+ ActionMailer::Base.deliveries << '123'
423
+ end
424
+ end
425
+
426
+ test 'refuse verification with different deliveries' do
427
+ msg = %Q("ActionMailer::Base.deliveries.size" didn't change by 1.\n) <<
428
+ "<1> expected but was\n<2>."
429
+
430
+ assert_failure(msg) do
431
+ assert_mail_deliveries do
432
+ 2.times { ActionMailer::Base.deliveries << '123' }
433
+ end
434
+ end
435
+ end
436
+
437
+ test 'verify deliveries with custom size' do
438
+ assert_mail_deliveries(3) do
439
+ 3.times { ActionMailer::Base.deliveries << '123' }
440
+ end
441
+ end
442
+
443
+ test 'refuse verification with custom size' do
444
+ msg = %Q("ActionMailer::Base.deliveries.size" didn't change by 2.\n) <<
445
+ "<2> expected but was\n<3>."
446
+
447
+ assert_failure(msg) do
448
+ assert_mail_deliveries(2) do
449
+ 3.times { ActionMailer::Base.deliveries << '123' }
450
+ end
451
+ end
452
+ end
453
+ end
454
+
455
+ context "#assert_link_to" do
456
+ setup do
457
+ Rails.application.routes.default_url_options[:host] = 'www.example.com'
458
+ visit '/users'
459
+ end
460
+
461
+ test 'assert when link exists, with path' do
462
+ assert_link_to new_user_path
463
+ end
464
+
465
+ test 'assert when link exists, with url' do
466
+ assert_link_to new_user_url
467
+ end
468
+
469
+ test 'assert when link does not exists' do
470
+ assert_failure(/Expected to have link to \//) do
471
+ assert_link_to '/'
472
+ end
473
+ end
474
+ end
475
+
476
+ private
477
+ def assert_failure(msg, &block)
478
+ assert_raise_with_message Test::Unit::AssertionFailedError, msg do
479
+ block.call
480
+ end
481
+ end
482
+
483
+ def random_string(length=20)
484
+ Array.new(length) { rand(36).to_s(36) }.join
485
+ end
486
+
487
+ def table_rows
488
+ [
489
+ ['Cuba Pete', 'King of the Ramba beat'],
490
+ ['Lou Bega', 'Mambo No. 5']
491
+ ]
492
+ end
493
+ end