Sha256: f54f9c478a8f808a335864215782103f2c05c8624b5972c4e1bee3d7d4e31bc1

Contents?: true

Size: 1.63 KB

Versions: 134

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'

describe "expection set on previously stubbed method" do
  it "fails if message is not received after expectation is set" do
    double = double(:msg => nil)
    double.msg
    double.should_receive(:msg)
    lambda { double.rspec_verify }.should raise_error(RSpec::Mocks::MockExpectationError)
  end

  it "outputs arguments of similar calls" do
    double = double('double', :foo => true)
    double.should_receive(:foo).with('first')
    double.foo('second')
    double.foo('third')
    lambda do
      double.rspec_verify
    end.should raise_error(%Q|Double "double" received :foo with unexpected arguments\n  expected: ("first")\n       got: ("second"), ("third")|)
    double.rspec_reset
  end

  context "with argument constraint on stub" do
    it "matches any args if no arg constraint set on expectation" do
      double = double("mock")
      double.stub(:foo).with(3).and_return("stub")
      double.should_receive(:foo).at_least(:once).and_return("expectation")
      double.foo
      double.rspec_verify
    end

    it "matches specific args set on expectation" do
      double = double("mock")
      double.stub(:foo).with(3).and_return("stub")
      double.should_receive(:foo).at_least(:once).with(4).and_return("expectation")
      double.foo(4)
      double.rspec_verify
    end

    it "fails if expectation's arg constraint is not met" do
      double = double("mock")
      double.stub(:foo).with(3).and_return("stub")
      double.should_receive(:foo).at_least(:once).with(4).and_return("expectation")
      double.foo(3)
      expect { double.rspec_verify }.to raise_error(/expected: \(4\)\s+got: \(3\)/)
    end
  end
end

Version data entries

134 entries across 83 versions & 13 rubygems

Version Path
classiccms-0.5.17 vendor/bundle/gems/rspec-mocks-2.9.0/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.17 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.16 vendor/bundle/gems/rspec-mocks-2.9.0/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.16 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.15 vendor/bundle/gems/rspec-mocks-2.9.0/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.15 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.14 vendor/bundle/gems/rspec-mocks-2.9.0/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.14 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.13 vendor/bundle/gems/rspec-mocks-2.9.0/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.13 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/stubbed_message_expectations_spec.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/rspec-mocks-2.11.1/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.12 vendor/bundle/gems/rspec-mocks-2.9.0/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.12 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.11 vendor/bundle/gems/rspec-mocks-2.9.0/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.11 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.10 vendor/bundle/gems/rspec-mocks-2.9.0/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.10 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.9 vendor/bundle/gems/rspec-mocks-2.9.0/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.9 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/stubbed_message_expectations_spec.rb
classiccms-0.5.8 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/stubbed_message_expectations_spec.rb