Sha256: 1fca94efd6fe28d11a7c866da6d033a6174e8a5e87cefb128ba43ce18394ec1e

Contents?: true

Size: 1.82 KB

Versions: 21

Compression:

Stored size: 1.82 KB

Contents

require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")

module RR
  module Expectations
    describe TimesCalledExpectation do
      context "when using an IntegerMatcher" do
        include_examples "RR::Expectations::TimesCalledExpectation"

        before do
          stub(subject).foobar.times(2)
        end

        describe "verify" do
          it "passes after attempt! called 2 times" do
            subject.foobar
            subject.foobar
            RR.verify
          end

          it "fails after attempt! called 1 time" do
            subject.foobar
            expect { RR.verify }.to raise_error(
              RR::Errors::TimesCalledError,
              "foobar()\nCalled 1 time.\nExpected 2 times."
            )
          end

          it "can't be called when attempt! is called 3 times" do
            subject.foobar
            subject.foobar
            expect {
              subject.foobar
            }.to raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 2 times.")
            expect {
              RR.verify
            }.to raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 2 times.")
          end

          it "has a backtrace to where the TimesCalledExpectation was instantiated on failure" do
            error = nil
            begin
              RR.verify
            rescue RR::Errors::TimesCalledError => e
              error = e
            end
            expect(e.backtrace.join("\n")).to include(__FILE__)
          end

          it "has an error message that includes the number of times called and expected number of times" do
            expect {
              RR.verify
            }.to raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 0 times.\nExpected 2 times.")
          end
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rr-3.1.1 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-3.1.0 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-3.0.9 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-3.0.8 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-3.0.7 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-3.0.6 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-3.0.5 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-3.0.4 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-3.0.3 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-3.0.2 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-3.0.1 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-3.0.0 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-1.2.1 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-1.2.0 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-1.1.2 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-1.1.2.rc1 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-1.1.1.rc1 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-1.1.0 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-1.1.0.rc3 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb
rr-1.1.0.rc2 spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb