Permalink
Browse files

align the feature READMEs for stubs and message expectations

  • Loading branch information...
1 parent f1a2682 commit e2826c61d280503df466cbea666caa4611986f82 @dchelimsky dchelimsky committed Aug 5, 2012
Showing with 32 additions and 17 deletions.
  1. +24 −13 features/message_expectations/README.md
  2. +8 −4 features/method_stubs/README.md
@@ -7,7 +7,30 @@
obj.should_receive(:message)
# specify a return value
- obj.should_receive(:message) { 'this is the value to return' }
+ obj.should_receive(:message) { :value }
+ obj.should_receive(:message => :value)
+ obj.should_receive(:message).and_return(:value)
+
+These forms are somewhat interchangeable. The difference is that the
+block contents are evaluated lazily when the `obj` receives the
+`message` message, whereas the others are evaluated as they are read.
+
+### Fake implementation
+
+ obj.should_receive(:message) do |arg1, arg2|
+ # set expectations about the args in this block
+ # and set a return value
+ end
+
+### Raising/Throwing
+
+ obj.should_receive(:message).and_raise("this error")
+ obj.should_receive(:message).and_throw(:this_symbol)
+
+You can also use the block format:
+
+ obj.should_receive(:message) { raise "this error" }
+ obj.should_receive(:message) { throw :this_symbol }
### Argument constraints
@@ -40,19 +63,7 @@
obj.should_receive(:message).at_most(:twice)
obj.should_receive(:message).at_most(n).times
-### Raising/Throwing
-
- obj.should_receive(:message) { raise "this error" }
- obj.should_receive(:message) { throw :this_symbol }
-
### Ordering
obj.should_receive(:one).ordered
obj.should_receive(:two).ordered
-
-### Arbitrary handling
-
- obj.should_receive(:message) do |arg1, arg2|
- # set expectations about the args in this block
- # and set a return value
- end
@@ -1,12 +1,16 @@
### Stub return values
+ # create a double
+ obj = double()
+
+ # specify a return value
obj.stub(:message) { :value }
obj.stub(:message => :value)
obj.stub(:message).and_return(:value)
-These forms are somewhat interchangeable. The difference is that the block
-contents are evaluated lazily when the `obj` receives the `message` message,
-whereas the others are evaluated as they are read.
+These forms are somewhat interchangeable. The difference is that the
+block contents are evaluated lazily when the `obj` receives the
+`message` message, whereas the others are evaluated as they are read.
### Fake implementation
@@ -20,7 +24,7 @@ whereas the others are evaluated as they are read.
obj.stub(:message).and_raise("this error")
obj.stub(:message).and_throw(:this_symbol)
-You can also use the block format, for consistency with other stubs:
+You can also use the block format:
obj.stub(:message) { raise "this error" }
obj.stub(:message) { throw :this_symbol }

0 comments on commit e2826c6

Please sign in to comment.