blob: 7c74249d24592baa569f4fc8a3d5ac8ff7b58275 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
require 'spec_helper'
require 'mspec/expectations/expectations'
require 'mspec/matchers'
module BeAnInOfSpecs
class A
end
class B < A
end
class C < B
end
end
RSpec.describe BeAnInstanceOfMatcher do
it "matches when actual is an instance_of? expected" do
a = BeAnInOfSpecs::A.new
expect(BeAnInstanceOfMatcher.new(BeAnInOfSpecs::A).matches?(a)).to be_truthy
b = BeAnInOfSpecs::B.new
expect(BeAnInstanceOfMatcher.new(BeAnInOfSpecs::B).matches?(b)).to be_truthy
end
it "does not match when actual is not an instance_of? expected" do
a = BeAnInOfSpecs::A.new
expect(BeAnInstanceOfMatcher.new(BeAnInOfSpecs::B).matches?(a)).to be_falsey
b = BeAnInOfSpecs::B.new
expect(BeAnInstanceOfMatcher.new(BeAnInOfSpecs::A).matches?(b)).to be_falsey
c = BeAnInOfSpecs::C.new
expect(BeAnInstanceOfMatcher.new(BeAnInOfSpecs::A).matches?(c)).to be_falsey
expect(BeAnInstanceOfMatcher.new(BeAnInOfSpecs::B).matches?(c)).to be_falsey
end
it "provides a useful failure message" do
matcher = BeAnInstanceOfMatcher.new(Numeric)
matcher.matches?("string")
expect(matcher.failure_message).to eq([
"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)
expect(matcher.negative_failure_message).to eq([
"Expected 4.0 (Float)", "not to be an instance of Numeric"])
end
end
|