You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RSpec::Its provides the its method as a short-hand to specify the expected value of an attribute.
Installation
Add this line to your application's Gemfile:
gem'rspec-its'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rspec-its
And require it as:
require'rspec/its'
Usage
Use the its method to generate a nested example group with a single example that specifies the expected value
of an attribute of the subject using is_expected. The its method can also specify the block expectations of
an attribute of the subject using will or will_not.
its accepts a symbol or a string, and a block representing the example.
The following should-style method is also available:
its(:size){shouldeq(1)}
as is an alias of is_expected for pluralized use:
its(:keys){are_expected.toeq([:key1,:key2])}
The following block expect-style method is also available:
its(:size){will_notraise_error}
as is this alias for pluralized use:
its(:keys){willraise_error(NoMethodError)}
When the subject implements the [] operator, you can pass in an array with a single key to
refer to the value returned by that operator when passed that key as an argument.
its([:key]){is_expected.toeq(value)}
For hashes, multiple keys within the array will result in successive accesses into the hash. For example: