Sha256: 50b163f3cda8c6e415d08be72c5c92bdd819da1ba076a8c64fb9238e6f5df7ce

Contents?: true

Size: 1.93 KB

Versions: 3

Compression:

Stored size: 1.93 KB

Contents

require "spec/spec_helper"

module RR
  module Expectations
    describe TimesCalledExpectation, ' with AtMostMatcher' do
      it_should_behave_like "RR::Expectations::TimesCalledExpectation"
      attr_reader :times, :at_most

      before do
        @times = 3
        @at_most = TimesCalledMatchers::AtMostMatcher.new(times)
        @expectation = TimesCalledExpectation.new(scenario, at_most)
      end

      describe "#verify!" do
        it "returns true when times called == times" do
          3.times {expectation.attempt!}
          expectation.verify!
        end

        it "raises error when times called < times" do
          2.times {expectation.attempt!}
          expectation.verify!
        end
      end

      describe "#attempt?" do
        it "returns true when attempted less than expected times" do
          2.times {expectation.attempt!}
          expectation.should be_attempt
        end

        it "returns false when attempted expected times" do
          3.times {expectation.attempt!}
          expectation.should_not be_attempt
        end

        it "raises error before attempted more than expected times" do
          3.times {expectation.attempt!}
          proc {expectation.attempt!}.should raise_error(
          Errors::TimesCalledError
          )
        end
      end

      describe "#attempt!" do
        it "fails when times called more than times" do
          3.times {expectation.attempt!}
          proc do
            expectation.attempt!
          end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 4 times.\nExpected at most 3 times.")
        end

        it "passes when times called == times" do
          3.times {expectation.attempt!}
        end

        it "passes when times called < times" do
          expectation.attempt!
        end
      end

      describe "#terminal?" do
        it "returns true" do
          expectation.should be_terminal
        end
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rr-0.4.2 spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb
rr-0.4.0 spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb
rr-0.4.1 spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb