Sha256: 83e8366c35bd70c354b31ea9572f499b98449536416cc1a2012815d10033880d

Contents?: true

Size: 1.89 KB

Versions: 40

Compression:

Stored size: 1.89 KB

Contents

require 'spec_helper'

module RSpec
  module Mocks
    describe "#twice" do
      before(:each) do
        @double = double("test double")
      end

      it "passes when called twice" do
        @double.should_receive(:do_something).twice
        @double.do_something
        @double.do_something
        verify @double
      end

      it "passes when called twice with specified args" do
        @double.should_receive(:do_something).twice.with("1", 1)
        @double.do_something("1", 1)
        @double.do_something("1", 1)
        verify @double
      end

      it "passes when called twice with unspecified args" do
        @double.should_receive(:do_something).twice
        @double.do_something("1")
        @double.do_something(1)
        verify @double
      end

      it "fails fast when call count is higher than expected" do
        @double.should_receive(:do_something).twice
        @double.do_something
        @double.do_something
        expect {
          @double.do_something
        }.to raise_error(RSpec::Mocks::MockExpectationError)
      end

      it "fails when call count is lower than expected" do
        @double.should_receive(:do_something).twice
        @double.do_something
        expect {
          verify @double
        }.to raise_error(RSpec::Mocks::MockExpectationError)
      end

      it "fails when called wrong args on the first call" do
        @double.should_receive(:do_something).twice.with("1", 1)
        expect {
          @double.do_something(1, "1")
        }.to raise_error(RSpec::Mocks::MockExpectationError)
        reset @double
      end

      it "fails when called with wrong args on the second call" do
        @double.should_receive(:do_something).twice.with("1", 1)
        @double.do_something("1", 1)
        expect {
          @double.do_something(1, "1")
        }.to raise_error(RSpec::Mocks::MockExpectationError)
        reset @double
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 8 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/twice_counts_spec.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/twice_counts_spec.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/twice_counts_spec.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/twice_counts_spec.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/twice_counts_spec.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/twice_counts_spec.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/twice_counts_spec.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/twice_counts_spec.rb
rspec-mocks-2.99.4 spec/rspec/mocks/twice_counts_spec.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-mocks-2.14.6/spec/rspec/mocks/twice_counts_spec.rb
rspec-mocks-2.99.3 spec/rspec/mocks/twice_counts_spec.rb
rspec-mocks-2.99.2 spec/rspec/mocks/twice_counts_spec.rb
dxruby_rp5-0.0.4 spec/vendor/rspec-mocks-2.14.4/spec/rspec/mocks/twice_counts_spec.rb
rspec-mocks-2.99.1 spec/rspec/mocks/twice_counts_spec.rb
rspec-mocks-2.99.0 spec/rspec/mocks/twice_counts_spec.rb
rspec-mocks-2.99.0.rc1 spec/rspec/mocks/twice_counts_spec.rb
rspec-mocks-2.14.6 spec/rspec/mocks/twice_counts_spec.rb
rspec-mocks-3.0.0.beta2 spec/rspec/mocks/twice_counts_spec.rb
rspec-mocks-2.99.0.beta2 spec/rspec/mocks/twice_counts_spec.rb
rspec-mocks-2.14.5 spec/rspec/mocks/twice_counts_spec.rb