Sha256: 5f5829053efd4271201059106b71b2c32ccb3efe3d0174d3cb4ec76faf952d50

Contents?: true

Size: 1.36 KB

Versions: 12

Compression:

Stored size: 1.36 KB

Contents

require "spec_helper"

describe "a double declaration with a block handed to:" do
  describe "should_receive" do
    it "returns the value of executing the block" do
      obj = Object.new
      obj.should_receive(:foo) { 'bar' }
      obj.foo.should eq('bar')
    end

    it "works when a multi-return stub has already been set" do
      obj = Object.new
      return_value = Object.new
      obj.stub(:foo).and_return(return_value, nil)
      obj.should_receive(:foo) { return_value }
      obj.foo.should be(return_value)
    end
  end

  describe "stub" do
    it "returns the value of executing the block" do
      obj = Object.new
      obj.stub(:foo) { 'bar' }
      obj.foo.should eq('bar')
    end
  end

  describe "with" do
    it "returns the value of executing the block" do
      obj = Object.new
      obj.stub(:foo).with('baz') { 'bar' }
      obj.foo('baz').should eq('bar')
    end
  end

  %w[once twice any_number_of_times ordered and_return].each do |method|
    describe method do
      it "returns the value of executing the block" do
        obj = Object.new
        obj.stub(:foo).send(method) { 'bar' }
        obj.foo.should eq('bar')
      end
    end
  end

  describe "times" do
    it "returns the value of executing the block" do
      obj = Object.new
      obj.stub(:foo).at_least(1).times { 'bar' }
      obj.foo('baz').should eq('bar')
    end
  end
end

Version data entries

12 entries across 12 versions & 5 rubygems

Version Path
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.11.3/spec/rspec/mocks/block_return_value_spec.rb
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.11.3/spec/rspec/mocks/block_return_value_spec.rb
rspec-mocks-2.12.1 spec/rspec/mocks/block_return_value_spec.rb
rspec-mocks-2.12.0 spec/rspec/mocks/block_return_value_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.11.3/spec/rspec/mocks/block_return_value_spec.rb
gem_repackager-0.1.0 support/gems/rspec-mocks-2.11.1/spec/rspec/mocks/block_return_value_spec.rb
rspec-mocks-2.11.3 spec/rspec/mocks/block_return_value_spec.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/rspec-mocks-2.11.1/spec/rspec/mocks/block_return_value_spec.rb
rspec-mocks-2.11.2 spec/rspec/mocks/block_return_value_spec.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/rspec-mocks-2.11.1/spec/rspec/mocks/block_return_value_spec.rb
rspec-mocks-2.11.1 spec/rspec/mocks/block_return_value_spec.rb
rspec-mocks-2.11.0 spec/rspec/mocks/block_return_value_spec.rb