Sha256: ab817ff080924b0df5849146116283f109e2123d4cb319ea3b91537cfe57f600

Contents?: true

Size: 1.96 KB

Versions: 74

Compression:

Stored size: 1.96 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
        lambda do
          @double.do_something
        end.should 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
        lambda do
          @double.rspec_verify
        end.should 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)
        lambda do
          @double.do_something(1, "1")
        end.should 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)
        lambda do
          @double.do_something(1, "1")
        end.should raise_error(RSpec::Mocks::MockExpectationError)
        @double.rspec_reset
      end
    end
  end
end

Version data entries

74 entries across 69 versions & 9 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/twice_counts_spec.rb
classiccms-0.7.4 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/twice_counts_spec.rb
classiccms-0.7.3 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/twice_counts_spec.rb
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.11.3/spec/rspec/mocks/twice_counts_spec.rb
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.11.3/spec/rspec/mocks/twice_counts_spec.rb
classiccms-0.7.2 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/twice_counts_spec.rb
classiccms-0.7.1 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/twice_counts_spec.rb
classiccms-0.7.0 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/twice_counts_spec.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.10.1/spec/rspec/mocks/twice_counts_spec.rb
classiccms-0.6.9 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/twice_counts_spec.rb
rspec-mocks-2.12.1 spec/rspec/mocks/twice_counts_spec.rb
rspec-mocks-2.12.0 spec/rspec/mocks/twice_counts_spec.rb
classiccms-0.6.8 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/twice_counts_spec.rb
classiccms-0.6.7 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/twice_counts_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.11.3/spec/rspec/mocks/twice_counts_spec.rb
classiccms-0.6.6 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/twice_counts_spec.rb
classiccms-0.6.5 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/twice_counts_spec.rb
classiccms-0.6.4 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/twice_counts_spec.rb
classiccms-0.6.3 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/twice_counts_spec.rb
classiccms-0.6.2 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/twice_counts_spec.rb