Contents

This page comes from RSpec Expectations 2.3.0. It is not part of the 3.12.2 docs. See the latest RSpec Expectations docs.

attribute of subject

In order to get more meaningful failure messages As a spec author I want RSpec to tell me what attribute a matcher applies to when using the its(:attribute) technique

Scenario: eq matcher fails

  • Given a file named "example_spec.rb" with:
    ruby
    describe "an array" do
      subject { [] }
      its(:size) { should eq(1) } # intentionally fail
    end
  • When I run "rspec example_spec.rb -fdoc"
  • Then the output should contain "Failure/Error: its(:size) { should eq(1) }"
  • And the output should contain "expected 1"

Source: features/expectations/attribute_of_subject.feature at v2.3.0, RSpec Expectations (MIT license).