Sha256: 275f03637290138fc11d03f4787d0a684f0e8762c726f737aaefaf6e6e8e9b32

Contents?: true

Size: 1.93 KB

Versions: 11

Compression:

Stored size: 1.93 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
        @double.rspec_verify
      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)
        @double.rspec_verify
      end

      it "passes when called twice with unspecified args" do
        @double.should_receive(:do_something).twice
        @double.do_something("1")
        @double.do_something(1)
        @double.rspec_verify
      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 {
          @double.rspec_verify
        }.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)
        @double.rspec_reset
      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)
        @double.rspec_reset
      end
    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/twice_counts_spec.rb
sshp-0.0.2 vendor/ruby/1.9.1/gems/rspec-mocks-2.13.1/spec/rspec/mocks/twice_counts_spec.rb
sshp-0.0.1 vendor/ruby/1.9.1/gems/rspec-mocks-2.13.1/spec/rspec/mocks/twice_counts_spec.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/rspec-mocks-2.13.1/spec/rspec/mocks/twice_counts_spec.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/rspec-mocks-2.13.1/spec/rspec/mocks/twice_counts_spec.rb
rspec-mocks-2.13.1 spec/rspec/mocks/twice_counts_spec.rb
vagrant-actionio-0.0.9 vendor/bundle/gems/rspec-mocks-2.13.0/spec/rspec/mocks/twice_counts_spec.rb
rspec-mocks-2.13.0 spec/rspec/mocks/twice_counts_spec.rb
remq-0.0.4 vendor/bundle/gems/rspec-mocks-2.12.2/spec/rspec/mocks/twice_counts_spec.rb
remq-0.0.3 vendor/bundle/gems/rspec-mocks-2.12.2/spec/rspec/mocks/twice_counts_spec.rb
rspec-mocks-2.12.2 spec/rspec/mocks/twice_counts_spec.rb