public
Rubygem
Description: Makes tests easy on the fingers and the eyes
Homepage: http://www.thoughtbot.com/projects/shoulda
Clone URL: git://github.com/thoughtbot/shoulda.git
Added some methods

git-svn-id: https://svn.thoughtbot.com/plugins/shoulda/trunk@181 
7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
tsaleh (author)
Wed Aug 22 09:14:21 -0700 2007
commit  51acf5633eac9b691bb20fffb9e47623dfa98217
tree    93e8e25cd17d170a15bc4f5fee24e409e1735943
parent  e579513034afbbb953a87a90388f3bff115dcc83
...
377
378
379
 
 
 
 
 
 
 
380
381
382
...
377
378
379
380
381
382
383
384
385
386
387
388
389
0
@@ -377,6 +377,13 @@ module ThoughtBot # :nodoc:
0
             end
0
           end
0
         end
0
+
0
+ # Macro that creates a test asserting that the rendered view contains a <form> element.
0
+ def should_render_a_form
0
+ should "display a form" do
0
+ assert_select "form", true, "The template doesn't contain a <form> element"
0
+ end
0
+ end
0
       end
0
 
0
       module InstanceMethods # :nodoc:
...
47
48
49
50
 
51
52
53
54
55
56
57
58
59
60
...
95
96
97
98
99
100
101
 
102
103
104
...
47
48
49
 
50
51
52
53
 
 
 
 
54
55
56
...
91
92
93
 
 
 
 
94
95
96
97
0
@@ -47,14 +47,10 @@ module ThoughtBot # :nodoc:
0
                 should_respond_with :success
0
                 should_render_template :edit
0
                 should_not_set_the_flash
0
-
0
+ should_render_a_form
0
                 should "set @#{res.object} to requested instance" do
0
                   assert_equal @record, assigns(res.object)
0
                 end
0
-
0
- should "display a form" do
0
- assert_select "form", true, "The template doesn't contain a <form> element"
0
- end
0
               end
0
             end
0
           end
0
@@ -95,10 +91,7 @@ module ThoughtBot # :nodoc:
0
                 should_assign_to res.object
0
                 should_not_set_the_flash
0
                 should_render_template :new
0
-
0
- should "display a form" do
0
- assert_select "form", true, "The template doesn't contain a <form> element"
0
- end
0
+ should_render_a_form
0
               end
0
             end
0
           end
...
95
96
97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
99
100
...
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
0
@@ -95,6 +95,25 @@ module ThoughtBot # :nodoc:
0
       def assert_valid(obj)
0
         assert obj.valid?, "Errors: #{obj.errors.full_messages.join('; ')}"
0
       end
0
+
0
+ # Asserts that the block uses ActionMailer to send emails
0
+ #
0
+ # assert_sends_email(2) { Mailer.deliver_messages }
0
+ def assert_sends_email(num = 1, &blk)
0
+ ActionMailer::Base.deliveries.clear
0
+ blk.call
0
+ msg = "Sent #{ActionMailer::Base.deliveries.size} emails, when #{num} expected:\n"
0
+ ActionMailer::Base.deliveries.each { |m| msg << " '#{m.subject}' sent to #{m.to.to_sentence}\n" }
0
+ assert(num == ActionMailer::Base.deliveries.size, msg)
0
+ end
0
+
0
+ # Asserts that the block does not send emails thorough ActionMailer
0
+ #
0
+ # assert_does_not_send_email { # do nothing }
0
+ def assert_does_not_send_email(&blk)
0
+ assert_sends_email 0, &blk
0
+ end
0
+
0
     end
0
   end
0
 end

Comments

    No one has commented yet.