Assert About An Object's Attributes With RSpec
When testing an object that gets created as the result of some process, it can be useful to assert about the attributes of that object. Not all of the attributes are relevant and some can be hard to reliably test. Rather than asserting about the result of calling #attributes
or #to_h
on an object, we can focus in with the have_attributes
matcher provided by RSpec.
In this example we were able to assert about all or just a subset of the attributes on both an ActiveRecord
object and a Struct
.
See the docs for more details.
Last updated