Sha256: 1a14d69ea881bbe9666f09f6781f365069f7f8aeefee0d6a761043992cec0c0f

Contents?: true

Size: 1.74 KB

Versions: 4

Compression:

Stored size: 1.74 KB

Contents

require 'spec_helper'

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

      it "fails when exactly n times method is called less than n times" do
        @mock.should_receive(:random_call).exactly(3).times
        @mock.random_call
        @mock.random_call
        lambda do
          @mock.rspec_verify
        end.should raise_error(RSpec::Mocks::MockExpectationError)
      end

      it "fails when exactly n times method is never called" do
        @mock.should_receive(:random_call).exactly(3).times
        lambda do
          @mock.rspec_verify
        end.should raise_error(RSpec::Mocks::MockExpectationError)
      end

      it "passes if exactly n times method is called exactly n times" do
        @mock.should_receive(:random_call).exactly(3).times
        @mock.random_call
        @mock.random_call
        @mock.random_call
        @mock.rspec_verify
      end

      it "returns the value given by a block when the exactly once method is called" do
        @mock.should_receive(:to_s).exactly(:once) { "testing" }
        @mock.to_s.should == "testing"
        @mock.rspec_verify
      end

      it "passes multiple calls with different args and counts" do
        @mock.should_receive(:random_call).twice.with(1)
        @mock.should_receive(:random_call).once.with(2)
        @mock.random_call(1)
        @mock.random_call(2)
        @mock.random_call(1)
        @mock.rspec_verify
      end

      it "passes mutiple calls with different args" do
        @mock.should_receive(:random_call).once.with(1)
        @mock.should_receive(:random_call).once.with(2)
        @mock.random_call(1)
        @mock.random_call(2)
        @mock.rspec_verify
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rspec-mocks-2.6.0 spec/rspec/mocks/precise_counts_spec.rb
rspec-mocks-2.6.0.rc6 spec/rspec/mocks/precise_counts_spec.rb
rspec-mocks-2.6.0.rc4 spec/rspec/mocks/precise_counts_spec.rb
rspec-mocks-2.6.0.rc2 spec/rspec/mocks/precise_counts_spec.rb