[rspec-users] Failure Messages in RSpec

Wincent Colaiuta win at wincent.com
Wed Sep 5 04:25:30 EDT 2007


El 4/9/2007, a las 22:51, Geoffrey Wiseman escribió:

> Using this as an example, if a new validation rule is added, this  
> test will
> fail without indicating /why/.  Sure, I can get that answer in  
> other ways,
> but I'd hate to discover things like:
>
> it "should be valid with valid attributes" do
>   # puts @person.errors if !@person.valid
>   @person.should be_valid
> end
>
> (Which I've seen when people have to repeatedly diagnose issues in  
> a test;
> I'd prefer a failure message to the above)

My personal approach when a spec fails and I can't figure out *why*  
just by looking at it is to run the spec under the debugger and set a  
breakpoint on the line where the corresponding spec fails.

In this way I can get as much information as I want about the problem  
and its context. The suggestion of using a custom matcher is a good  
one, but I personally don't find it general enough.

I actually *like* the way that RSpec doesn't provide a mechanism for  
specifying error messages; it's one of the things that makes the  
specs so easy to read. It's difficult to imagine a syntax that would  
provide what you're asking for without sacrificing readability.

Cheers,
Wincent



More information about the rspec-users mailing list