It seems that a relatively simple monkey patch will allow you to search for what you are looking for.
Look at the source of your version of gspec-core gem. I am on 2.10.1. In the file lib/rspec/core/subject.rb I see its method.
Here is my revised version - I changed the def line and the line after that.
Caution - this most likely depends on the version! Copy the method from your version and change it the same way I do. Please note that if rspec-core developers are doing a major restructuring of the code, the patch may need to be completely different.
module RSpec module Core module Subject module ExampleGroupMethods # accept an optional description to append def its(attribute, desc=nil, &block) describe(desc ? attribute.inspect + " #{desc}" : attribute) do example do self.class.class_eval do define_method(:subject) do if defined?(@_subject) @_subject else @_subject = Array === attribute ? super()[*attribute] : _nested_attribute(super(), attribute) end end end instance_eval(&block) end end end end end end end
This patch can probably be placed in your spec_helper.rb .
Now use:
its("foo", "is not nil") do should_not be_nil end
Error output:
rspec ./attrib_example_spec.rb:10 # attr example "foo" is not nil
If you omit the second arg argument, the behavior will be the same as the failed method.
source share