Sha256: 0fc032e38450dacd1ac736819aecc9837aa6a12943de3afa04896059471579f4

Contents?: true

Size: 1.92 KB

Versions: 16

Compression:

Stored size: 1.92 KB

Contents

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
        matcher.match_unless_raises {}.should be_true
      end

      it "returns false if there is an error" do
        matcher.match_unless_raises { raise }.should be_false
      end

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

      it "returns false if any of several errors submitted is raised" do
        matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise "foo" }.should be_false
        matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise ArgumentError.new('') }.should be_false
        matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise NameError.new('') }.should 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" }
        matcher.rescued_exception.should be_a(RuntimeError)
        matcher.rescued_exception.message.should 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

        matcher.new(3).matches?(3).should be_true
        matcher.new(3).should eq(3)

        matcher.new(3).matches?(4).should be_false
        matcher.new(3).should_not eq(4)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 6 rubygems

Version Path
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/spec/rspec/matchers/base_matcher_spec.rb
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/spec/rspec/matchers/base_matcher_spec.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/rspec-expectations-2.12.1/spec/rspec/matchers/base_matcher_spec.rb
remq-0.0.4 vendor/bundle/gems/rspec-expectations-2.12.1/spec/rspec/matchers/base_matcher_spec.rb
remq-0.0.3 vendor/bundle/gems/rspec-expectations-2.12.1/spec/rspec/matchers/base_matcher_spec.rb
librarian-puppet-0.9.8 vendor/gems/ruby/1.9.1/gems/rspec-expectations-2.12.1/spec/rspec/matchers/base_matcher_spec.rb
rspec-expectations-2.12.1 spec/rspec/matchers/base_matcher_spec.rb
rspec-expectations-2.12.0 spec/rspec/matchers/base_matcher_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/spec/rspec/matchers/base_matcher_spec.rb
gem_repackager-0.1.0 support/gems/rspec-expectations-2.11.2/spec/rspec/matchers/base_matcher_spec.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/rspec-expectations-2.11.2/spec/rspec/matchers/base_matcher_spec.rb
rspec-expectations-2.11.3 spec/rspec/matchers/base_matcher_spec.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/rspec-expectations-2.11.2/spec/rspec/matchers/base_matcher_spec.rb
rspec-expectations-2.11.2 spec/rspec/matchers/base_matcher_spec.rb
rspec-expectations-2.11.1 spec/rspec/matchers/base_matcher_spec.rb
rspec-expectations-2.11.0 spec/rspec/matchers/base_matcher_spec.rb