Sha256: d0bbee61aad7f448ca908805628f18ec699cb57106076bc561c6640d18284078

Contents?: true

Size: 1.39 KB

Versions: 37

Compression:

Stored size: 1.39 KB

Contents

Feature: stub with substitute implementation

  You can stub an implementation of a method (a.k.a. fake) by passing a block
  to the `stub` method.

  Scenario: stub implementation using `expect` syntax
  Given a file named "stub_implementation_spec.rb" with:
    """ruby
    describe "a stubbed implementation" do
      it "works" do
        object = Object.new
        allow(object).to receive(:foo) do |arg|
          if arg == :this
            "got this"
          elsif arg == :that
            "got that"
          end
        end

        expect(object.foo(:this)).to eq("got this")
        expect(object.foo(:that)).to eq("got that")
      end
    end
    """
  When I run `rspec stub_implementation_spec.rb`
  Then the output should contain "1 example, 0 failures"

  Scenario: stub implementation using `should` syntax
    Given a file named "stub_implementation_spec.rb" with:
      """ruby
      describe "a stubbed implementation" do
        it "works" do
          object = Object.new
          object.stub(:foo) do |arg|
            if arg == :this
              "got this"
            elsif arg == :that
              "got that"
            end
          end

          object.foo(:this).should eq("got this")
          object.foo(:that).should eq("got that")
        end
      end
      """
    When I run `rspec stub_implementation_spec.rb`
    Then the output should contain "1 example, 0 failures"

Version data entries

37 entries across 37 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/stub_implementation.feature
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/features/method_stubs/stub_implementation.feature
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/features/method_stubs/stub_implementation.feature
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/method_stubs/stub_implementation.feature
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/method_stubs/stub_implementation.feature
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/method_stubs/stub_implementation.feature
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/method_stubs/stub_implementation.feature
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/method_stubs/stub_implementation.feature
rspec-mocks-2.99.4 features/method_stubs/stub_implementation.feature
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-mocks-2.14.6/features/method_stubs/stub_implementation.feature
rspec-mocks-2.99.3 features/method_stubs/stub_implementation.feature
rspec-mocks-2.99.2 features/method_stubs/stub_implementation.feature
dxruby_rp5-0.0.4 spec/vendor/rspec-mocks-2.14.4/features/method_stubs/stub_implementation.feature
rspec-mocks-2.99.1 features/method_stubs/stub_implementation.feature
rspec-mocks-2.99.0 features/method_stubs/stub_implementation.feature
rspec-mocks-2.99.0.rc1 features/method_stubs/stub_implementation.feature
rspec-mocks-2.14.6 features/method_stubs/stub_implementation.feature
rspec-mocks-2.99.0.beta2 features/method_stubs/stub_implementation.feature
rspec-mocks-2.14.5 features/method_stubs/stub_implementation.feature
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rspec-mocks-2.14.4/features/method_stubs/stub_implementation.feature