Sha256: 7b014e78c8e63e6a07920855f5ed4630fc150b6f8f7ef8ff905939ae534293fe

Contents?: true

Size: 1.98 KB

Versions: 26

Compression:

Stored size: 1.98 KB

Contents

require 'spec_helper'

module RSpec::Matchers::BuiltIn
  describe BaseMatcher do
    describe "#match_unless_raises" do
      let(:matcher) do
        Class.new(BaseMatcher).new
      end

      it "returns true if there are no errors" do
        expect(matcher.match_unless_raises {}).to be_true
      end

      it "returns false if there is an error" do
        expect(matcher.match_unless_raises { raise }).to be_false
      end

      it "returns false if the only submitted error is raised" do
        expect(matcher.match_unless_raises(RuntimeError){ raise "foo" }).to be_false
      end

      it "returns false if any of several errors submitted is raised" do
        expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise "foo" }).to be_false
        expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise ArgumentError.new('') }).to be_false
        expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise NameError.new('') }).to be_false
      end

      it "re-raises any error other than one of those specified" do
        expect do
          matcher.match_unless_raises(ArgumentError){ raise "foo" }
        end.to raise_error
      end

      it "stores the rescued exception for use in messages" do
        matcher.match_unless_raises(RuntimeError){ raise "foo" }
        expect(matcher.rescued_exception).to be_a(RuntimeError)
        expect(matcher.rescued_exception.message).to eq("foo")
      end

    end

    describe "#==" do
      it "responds the same way as matches?" do
        matcher = Class.new(BaseMatcher) do
          def initialize(expected)
            @expected = expected
          end

          def matches?(actual)
            (@actual = actual) == @expected
          end
        end

        expect(matcher.new(3).matches?(3)).to be_true
        expect(matcher.new(3)).to eq(3)

        expect(matcher.new(3).matches?(4)).to be_false
        expect(matcher.new(3)).not_to eq(4)
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 10 rubygems

Version Path
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-expectations-2.13.0/spec/rspec/matchers/base_matcher_spec.rb
dxruby_rp5-0.0.4 spec/vendor/rspec-expectations-2.14.4/spec/rspec/matchers/base_matcher_spec.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rspec-expectations-2.14.4/spec/rspec/matchers/base_matcher_spec.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/rspec-expectations-2.14.4/spec/rspec/matchers/base_matcher_spec.rb
dxruby_rp5-0.0.3 spec/vendor/rspec-expectations-2.14.4/spec/rspec/matchers/base_matcher_spec.rb
tuktuk-rails-0.0.10 vendor/bundle/ruby/2.0.0/gems/rspec-expectations-2.14.4/spec/rspec/matchers/base_matcher_spec.rb
tuktuk-rails-0.0.9 vendor/bundle/ruby/2.0.0/gems/rspec-expectations-2.14.4/spec/rspec/matchers/base_matcher_spec.rb
tuktuk-rails-0.0.8 vendor/bundle/ruby/2.0.0/gems/rspec-expectations-2.14.4/spec/rspec/matchers/base_matcher_spec.rb
tuktuk-rails-0.0.7 vendor/bundle/ruby/2.0.0/gems/rspec-expectations-2.14.4/spec/rspec/matchers/base_matcher_spec.rb
dxruby_rp5-0.0.2 spec/vendor/rspec-expectations-2.14.4/spec/rspec/matchers/base_matcher_spec.rb
dxruby_rp5-0.0.1 spec/vendor/rspec-expectations-2.14.4/spec/rspec/matchers/base_matcher_spec.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/rspec-expectations-2.14.4/spec/rspec/matchers/base_matcher_spec.rb
rspec-expectations-2.14.4 spec/rspec/matchers/base_matcher_spec.rb
rspec-expectations-2.14.3 spec/rspec/matchers/base_matcher_spec.rb
clickable_link-0.0.2 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.14.2/spec/rspec/matchers/base_matcher_spec.rb
syllable_counter-1.0.0 vendor/bundle/gems/rspec-expectations-2.14.2/spec/rspec/matchers/base_matcher_spec.rb
rspec-expectations-2.14.2 spec/rspec/matchers/base_matcher_spec.rb
rspec-expectations-2.14.1 spec/rspec/matchers/base_matcher_spec.rb
rspec-expectations-2.14.0 spec/rspec/matchers/base_matcher_spec.rb
sshp-0.0.2 vendor/ruby/1.9.1/gems/rspec-expectations-2.13.0/spec/rspec/matchers/base_matcher_spec.rb