Sha256: 742f379248512057881baad40d19d341d0731232df77c76f89307c68717f014c

Contents?: true

Size: 1.74 KB

Versions: 12

Compression:

Stored size: 1.74 KB

Contents

Feature: Returning a value

  Use `and_return` to specify a return value. Pass `and_return` multiple values to specify
  different return values for consecutive calls. The final value will continue to be returned if
  the message is received additional times.

  Scenario: Nil is returned by default
    Given a file named "returns_nil_spec.rb" with:
      """ruby
      RSpec.describe "The default response" do
        it "returns nil when no response has been configured" do
          dbl = double
          allow(dbl).to receive(:foo)
          expect(dbl.foo).to be_nil
        end
      end
      """
     When I run `rspec returns_nil_spec.rb`
     Then the examples should all pass

  Scenario: Specify a return value
    Given a file named "and_return_spec.rb" with:
      """ruby
      RSpec.describe "Specifying a return value" do
        it "returns the specified return value" do
          dbl = double
          allow(dbl).to receive(:foo).and_return(14)
          expect(dbl.foo).to eq(14)
        end
      end
      """
     When I run `rspec and_return_spec.rb`
     Then the examples should all pass

  Scenario: Specify different return values for multiple calls
    Given a file named "multiple_calls_spec.rb" with:
      """ruby
      RSpec.describe "When the method is called multiple times" do
        it "returns the specified values in order, then keeps returning the last value" do
          dbl = double
          allow(dbl).to receive(:foo).and_return(1, 2, 3)

          expect(dbl.foo).to eq(1)
          expect(dbl.foo).to eq(2)
          expect(dbl.foo).to eq(3)
          expect(dbl.foo).to eq(3)
          expect(dbl.foo).to eq(3)
        end
      end
      """
     When I run `rspec multiple_calls_spec.rb`
     Then the examples should all pass

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
opal-rspec-1.1.0.alpha3 rspec-mocks/upstream/features/configuring_responses/returning_a_value.feature
opal-rspec-1.1.0.alpha2 rspec-mocks/upstream/features/configuring_responses/returning_a_value.feature
opal-rspec-1.1.0.alpha1 rspec-mocks/upstream/features/configuring_responses/returning_a_value.feature
opal-rspec-1.0.0 rspec-mocks/upstream/features/configuring_responses/returning_a_value.feature
opal-rspec-1.0.0.alpha1 rspec-mocks/upstream/features/configuring_responses/returning_a_value.feature
opal-rspec-0.8.0 rspec-mocks/upstream/features/configuring_responses/returning_a_value.feature
opal-rspec-0.8.0.alpha3 rspec-mocks/upstream/features/configuring_responses/returning_a_value.feature
opal-rspec-0.8.0.alpha2 rspec-mocks/upstream/features/configuring_responses/returning_a_value.feature
opal-rspec-0.8.0.alpha1 rspec-mocks/upstream/features/configuring_responses/returning_a_value.feature
opal-rspec-0.7.1 rspec-mocks/upstream/features/configuring_responses/returning_a_value.feature
opal-rspec-0.7.0 rspec-mocks/upstream/features/configuring_responses/returning_a_value.feature
opal-rspec-0.7.0.rc.2 rspec-mocks/upstream/features/configuring_responses/returning_a_value.feature