Sha256: 3eccc470fdd2bbb68263d0d8c448b2fcf08729a373dd096f2a2d4a416b074fd6

Contents?: true

Size: 1.38 KB

Versions: 11

Compression:

Stored size: 1.38 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' }
      expect(obj.foo).to 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 }
      expect(obj.foo).to be(return_value)
    end
  end

  describe "stub" do
    it "returns the value of executing the block" do
      obj = Object.new
      obj.stub(:foo) { 'bar' }
      expect(obj.foo).to 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' }
      expect(obj.foo('baz')).to 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' }
        expect(obj.foo).to 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' }
      expect(obj.foo('baz')).to eq('bar')
    end
  end
end

Version data entries

11 entries across 11 versions & 6 rubygems

Version Path
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-mocks-2.13.0/spec/rspec/mocks/block_return_value_spec.rb
sshp-0.0.2 vendor/ruby/1.9.1/gems/rspec-mocks-2.13.1/spec/rspec/mocks/block_return_value_spec.rb
sshp-0.0.1 vendor/ruby/1.9.1/gems/rspec-mocks-2.13.1/spec/rspec/mocks/block_return_value_spec.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/rspec-mocks-2.13.1/spec/rspec/mocks/block_return_value_spec.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/rspec-mocks-2.13.1/spec/rspec/mocks/block_return_value_spec.rb
rspec-mocks-2.13.1 spec/rspec/mocks/block_return_value_spec.rb
vagrant-actionio-0.0.9 vendor/bundle/gems/rspec-mocks-2.13.0/spec/rspec/mocks/block_return_value_spec.rb
rspec-mocks-2.13.0 spec/rspec/mocks/block_return_value_spec.rb
remq-0.0.4 vendor/bundle/gems/rspec-mocks-2.12.2/spec/rspec/mocks/block_return_value_spec.rb
remq-0.0.3 vendor/bundle/gems/rspec-mocks-2.12.2/spec/rspec/mocks/block_return_value_spec.rb
rspec-mocks-2.12.2 spec/rspec/mocks/block_return_value_spec.rb