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

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/features/method_stubs/simple_return_value_with_allow.feature
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/features/method_stubs/simple_return_value_with_allow.feature
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/features/method_stubs/simple_return_value_with_allow.feature
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/method_stubs/simple_return_value_with_allow.feature
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/method_stubs/simple_return_value_with_allow.feature
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/method_stubs/simple_return_value_with_allow.feature
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/method_stubs/simple_return_value_with_allow.feature
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/method_stubs/simple_return_value_with_allow.feature
rspec-mocks-2.99.4 features/method_stubs/simple_return_value_with_allow.feature
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-mocks-2.14.6/features/method_stubs/simple_return_value_with_allow.feature
rspec-mocks-2.99.3 features/method_stubs/simple_return_value_with_allow.feature
rspec-mocks-2.99.2 features/method_stubs/simple_return_value_with_allow.feature
dxruby_rp5-0.0.4 spec/vendor/rspec-mocks-2.14.4/features/method_stubs/simple_return_value_with_allow.feature
rspec-mocks-2.99.1 features/method_stubs/simple_return_value_with_allow.feature
rspec-mocks-2.99.0 features/method_stubs/simple_return_value_with_allow.feature
rspec-mocks-2.99.0.rc1 features/method_stubs/simple_return_value_with_allow.feature
rspec-mocks-2.14.6 features/method_stubs/simple_return_value_with_allow.feature
rspec-mocks-3.0.0.beta2 features/method_stubs/simple_return_value_with_allow.feature
rspec-mocks-2.99.0.beta2 features/method_stubs/simple_return_value_with_allow.feature
rspec-mocks-2.14.5 features/method_stubs/simple_return_value_with_allow.feature