[rspec-devel] [ rspec-Bugs-10594 ] Failing Custom Matcher show NAME NOT GENERATED description

noreply at rubyforge.org noreply at rubyforge.org
Fri May 4 20:40:17 EDT 2007


Bugs item #10594, was opened at 2007-05-04 19:34
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=10594&group_id=797

Category: None
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Luis Lavena (luislavena)
Assigned to: Aslak Hellesøy (aslak_hellesoy)
Summary: Failing Custom Matcher show NAME NOT GENERATED description

Initial Comment:
By request of aslak hellesoy:

Also, auto-generated names for the examples is very helpful, I'm
trying to take advantage of it.

Since I often prior code/define all the "examples", I have created a
few matchers to fulfill associations and validations of attributes.
Example:

describe "A User (in general)" do
 before(:each) do
   @user = User.new
 end

 it { @user.should have_many(:contest_public_votes) }
 it { @user.should have_many(:design_industry_user_interests) }
 it { @user.should have_one(:user_extension) }
end

That creates the following descriptions:

A User (in general)
- should has_many contest_public_votes
- should has_many design_industry_user_interests
- should has_one user_extension

A new User
- should not be valid without first_name
- should not be valid without last_name
- should not be valid without login
- should not be valid without email
- should not be valid without password
- should not be valid without password_confirmation
- should not be valid without city
- should not be valid without postal_code
- should not be valid without country
- should not be valid with duplicate login
- should not be valid with duplicate email

Anyway, the problem started with latest release, which if someone my
matcher shows a problem, NAME NOT GENERATED was put in the description
instead of my fancy, nicely done name ;-)

Attached I have included a faulty matcher that shows the issue.


----------------------------------------------------------------------

>Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2007-05-04 20:40

Message:
This is a little trickier to solve than I had first thought. Just so I understand you correctly: You want the automatic description to be set even when your matcher's #matches? method raises an exception?

Such behaviour is actually in violation of the general contract for matchers (which I admit is not clearly documented). #matches? is not allowed to raise exceptions - it must always return true or false. 

In addition to this it is recommended that #matches? creates an instance reference to the +actual+ argument so that it can be used later in the #description method (if appliccable). This is what happens in most of RSpec's built-in matchers.

RSpec can only assume that if #matches? raised an exception, then calling #description would most likely return gibberish (we must assume that @actual was never set), and it doesn't even try to call it. This happens in handler.rb.

This is why you don't get a generated description for your examples without names.

The solution should be simple - just add a rescue in your #matches? method and have it return false when something goes wrong.

Maybe David has something to add.

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=10594&group_id=797


More information about the rspec-devel mailing list