我正在努力学习RSpec。目前我正在研究built-in matchers。RSpec kind_of?返回错误结果
我对expect(actual).to be_kind_of(expected)
在relishapp site有点糊涂了,它说的be_kind_of
行为是
obj.should be_kind_of(类型):调用obj.kind_of(型),其中如果type在obj的类层次结构中或者是一个模块并且包含在obj类层次结构中的类中,则返回true。
APIdock状态this example:
module M; end
class A
include M
end
class B < A; end
class C < B; end
b.kind_of? A #=> true
b.kind_of? B #=> true
b.kind_of? C #=> false
b.kind_of? M #=> true
然而,当我测试RSpec的,则返回false当我这样做:
module M; end
class A
include M
end
class B < A; end
class C < B; end
describe "RSpec expectation" do
context "comparisons" do
let(:b) {B.new}
it "test types/classes/response" do
expect(b).to be kind_of?(A)
expect(b).to_not be_instance_of(A)
end
end
end
1) RSpec expectation comparisons test types/classes/response
Failure/Error: expect(b).to be kind_of?(A)
expected false
got #<B:70361555406320> => #<B:0x007ffca7081be0>
为什么我的RSpec返回false当例子说它应该返回true
?