반응형
Using RSpec to check if something is an instance of another object
I need a way to check if an object is an instance of another object using RSpec. For example:
describe "new shirt" do
it "should be an instance of a Shirt object"
# How can i check if it is an instance of a shirt object
end
end
The preferred syntax is:
expect(@object).to be_a Shirt
The older syntax is:
@object.should be_an_instance_of Shirt
Note that there is a very subtle difference between the two. If Shirt were to inherit from Garment then both of these expectations will pass:
expect(@object).to be_a Shirt
expect(@object).to be_a Garment
If you do and @object is a Shirt, then the second expectation will fail:
@object.should be_an_instance_of Shirt
@object.should be_an_instance_of Garment
You mean you want to check if an object is an instance of a class? If so, that's easy, just use class
:
@object.class.should == Shirt
ReferenceURL : https://stackoverflow.com/questions/13548375/using-rspec-to-check-if-something-is-an-instance-of-another-object
반응형
'programing' 카테고리의 다른 글
Select all where [first letter starts with B] (0) | 2021.01.17 |
---|---|
What are good alternatives to UITextAlignmentCenter in iOS 6? (0) | 2021.01.17 |
How to set include path in xcode project (0) | 2021.01.17 |
Spring Bean Scopes (0) | 2021.01.17 |
Cannot checkout, file is unmerged (0) | 2021.01.17 |