public
Description: Behaviour Driven Development framework for Ruby
Homepage: http://rspec.info
Clone URL: git://github.com/dchelimsky/rspec.git
Click here to lend your support to: rspec and make a donation at www.pledgie.com !
added ability to stub multiple methods in one stub! call
pat-maddox (author)
Fri Jul 25 09:05:21 -0700 2008
commit  5fd78361039d069449f91dc506ae2bf3d9d616de
tree    498c5e97c890a7d6150ba6ab41e9f9dcc1291af5
parent  dc359c78147166bc9688ea49a5ebf237478e6f24
...
9
10
11
12
13
 
 
 
 
 
 
14
15
16
...
9
10
11
 
 
12
13
14
15
16
17
18
19
20
0
@@ -9,8 +9,12 @@ module Spec
0
         __mock_proxy.add_negative_message_expectation(caller(1)[0], sym.to_sym, &block)
0
       end
0
       
0
-      def stub!(sym, opts={})
0
-        __mock_proxy.add_stub(caller(1)[0], sym.to_sym, opts)
0
+      def stub!(sym_or_hash, opts={})
0
+        if Hash === sym_or_hash
0
+          sym_or_hash.each {|method, value| stub!(method).and_return value }
0
+        else
0
+          __mock_proxy.add_stub(caller(1)[0], sym_or_hash.to_sym, opts)
0
+        end
0
       end
0
       
0
       def received_message?(sym, *args, &block) #:nodoc:
...
44
45
46
 
 
 
 
 
 
47
48
49
...
44
45
46
47
48
49
50
51
52
53
54
55
0
@@ -44,6 +44,12 @@ module Spec
0
           @instance.rspec_verify
0
         end.should_not raise_error
0
       end
0
+
0
+      it "should handle multiple stubbed methods" do
0
+        @instance.stub!(:msg1 => 1, :msg2 => 2)
0
+        @instance.msg1.should == 1
0
+        @instance.msg2.should == 2
0
+      end
0
       
0
       it "should clear itself when verified" do
0
         @instance.stub!(:this_should_go).and_return(:blah)

Comments

bmabey Wed Jul 30 09:17:11 -0700 2008

Very nice feature, thanks!