我正在努力學習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
?