Sha256: 839cc9d8ba85d5c6c4f80d7ee62292b8fe54a6f4771fd01b6a5d363be2b073fb
Contents?: true
Size: 1.5 KB
Versions: 39
Compression:
Stored size: 1.5 KB
Contents
Feature: allow with a simple return value Use the `allow` method with the `receive` matcher 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 allow(collaborator).to receive(:message) expect(collaborator.message).to 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") allow(collaborator).to receive(:message) { :value } expect(collaborator.message).to eq(:value) end end context "specified with #and_return" do it "returns the specified value" do collaborator = double("collaborator") allow(collaborator).to receive(:message).and_return(:value) expect(collaborator.message).to eq(:value) end end end """ When I run `rspec example_spec.rb` Then the examples should all pass
Version data entries
39 entries across 39 versions & 8 rubygems