Sha256: 40ad5364e0c27f07d6a88e26c49f4cb8cc4de8eab557f0378c11e07e1b57cf20

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'
require 'mspec/expectations/expectations'
require 'mspec/matchers'

module BeAnInOfSpecs
  class A
  end

  class B < A
  end

  class C < B
  end
end

describe BeAnInstanceOfMatcher do
  it "matches when actual is an instance_of? expected" do
    a = BeAnInOfSpecs::A.new
    BeAnInstanceOfMatcher.new(BeAnInOfSpecs::A).matches?(a).should be_truthy

    b = BeAnInOfSpecs::B.new
    BeAnInstanceOfMatcher.new(BeAnInOfSpecs::B).matches?(b).should be_truthy
  end

  it "does not match when actual is not an instance_of? expected" do
    a = BeAnInOfSpecs::A.new
    BeAnInstanceOfMatcher.new(BeAnInOfSpecs::B).matches?(a).should be_falsey

    b = BeAnInOfSpecs::B.new
    BeAnInstanceOfMatcher.new(BeAnInOfSpecs::A).matches?(b).should be_falsey

    c = BeAnInOfSpecs::C.new
    BeAnInstanceOfMatcher.new(BeAnInOfSpecs::A).matches?(c).should be_falsey
    BeAnInstanceOfMatcher.new(BeAnInOfSpecs::B).matches?(c).should be_falsey
  end

  it "provides a useful failure message" do
    matcher = BeAnInstanceOfMatcher.new(Numeric)
    matcher.matches?("string")
    matcher.failure_message.should == [
      "Expected \"string\" (String)", "to be an instance of Numeric"]
  end

  it "provides a useful negative failure message" do
    matcher = BeAnInstanceOfMatcher.new(Numeric)
    matcher.matches?(4.0)
    matcher.negative_failure_message.should == [
      "Expected 4.0 (Float)", "not to be an instance of Numeric"]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mspec-1.9.1 spec/matchers/be_an_instance_of_spec.rb
mspec-1.9.0 spec/matchers/be_an_instance_of_spec.rb