Sha256: 247bb9d20543c1bf3ea9228074876fb973c4a4157e4c63af3a2105ca88246007

Contents?: true

Size: 1.87 KB

Versions: 61

Compression:

Stored size: 1.87 KB

Contents

module RSpec::Matchers::BuiltIn
  describe BaseMatcher do
    describe "#match_unless_raises" do
      let(:matcher) do
        Class.new do
          include BaseMatcher
        end.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 do
          include BaseMatcher
          def matches?(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

61 entries across 56 versions & 5 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.7.4 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.7.3 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.7.2 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.7.1 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.7.0 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.6.9 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.6.8 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.6.7 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.6.6 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.6.5 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.6.4 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.6.3 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.6.2 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.6.1 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.6.0 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.5.17 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.5.16 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb
classiccms-0.5.15 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/base_matcher_spec.rb