私はRSpecを学ぶための探求をしています。現在、私はbuilt-in matchersを勉強しています。RSpec kind_of?戻り値が間違っています
私はrelishapp siteオンexpect(actual).to be_kind_of(expected)
に少し混乱しています、それは
obj.should be_kind_of(タイプ)であることを
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
を返す必要がありますか?