Using RSpec to check if something is an instance of another object

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)