-
-
Notifications
You must be signed in to change notification settings - Fork 358
/
simple_return_value_with_stub.feature
64 lines (57 loc) · 2.16 KB
/
simple_return_value_with_stub.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Feature: stub with a simple return value
Use the `stub` method on a test double or a real object to tell the object to
return a value (or values) in response to a given message. Nothing happens if
the message is never received.
Scenario: stub with no return value
Given a file named "example_spec.rb" with:
"""ruby
describe "a stub with no return value specified" do
let(:collaborator) { double("collaborator") }
it "returns nil" do
collaborator.stub(:message)
collaborator.message.should be(nil)
end
end
"""
When I run `rspec example_spec.rb`
Then the examples should all pass
Scenario: stubs with return values
Given a file named "example_spec.rb" with:
"""ruby
describe "a stub with a return value" do
context "specified in a block" do
it "returns the specified value" do
collaborator = double("collaborator")
collaborator.stub(:message) { :value }
collaborator.message.should eq(:value)
end
end
context "specified with #and_return" do
it "returns the specified value" do
collaborator = double("collaborator")
collaborator.stub(:message).and_return(:value)
collaborator.message.should eq(:value)
end
end
context "specified with a hash passed to #stub" do
it "returns the specified value" do
collaborator = double("collaborator")
collaborator.stub(:message_1 => :value_1, :message_2 => :value_2)
collaborator.message_1.should eq(:value_1)
collaborator.message_2.should eq(:value_2)
end
end
context "specified with a hash passed to #double" do
it "returns the specified value" do
collaborator = double("collaborator",
:message_1 => :value_1,
:message_2 => :value_2
)
collaborator.message_1.should eq(:value_1)
collaborator.message_2.should eq(:value_2)
end
end
end
"""
When I run `rspec example_spec.rb`
Then the examples should all pass