[Rspec-devel] Failure messages - customize per "should" assertion

aslak hellesoy aslak.hellesoy at gmail.com
Sun May 28 01:50:03 EDT 2006


On 5/27/06, itsme213 <itsme213 at hotmail.com> wrote:
> Is there a way to customize the failure message for each "should" assertion?
>
> e.g. I have
>
>  specify 'every activity should have an output' do
>   Activity.instances.each {|a| a.outputs.should_not_be_empty }
>  end
>
> I get:
>
> 1)
> ExpectationNotMetError in 'MAp object graph every activity should have an
> output'
> [] should not be empty
>
>
> I would like to customize the failure message based on the activity |a|.
>

Each failure message consists of 2 parts:

part 1: This is the context name followed by the specification name.
This purpose is to communicate the high level information first
(assuming the programmer named the properly). This should read as a
sentence.

part 2: This is the failed should_*. The purpose is to communicate the
detailed information about it, such as why something failed and where
(line number).

> Is this possible? Should it be?
>

If you're referring to part 1 - yes. Just change the words.

If you're referring to part 2 - no.

Can you provide a code example of how you would like to customize
error messages? Why would you like to customize them?

Aslak

> Thanks!
> _______________________________________________
> Rspec-devel mailing list
> Rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel
>



More information about the Rspec-devel mailing list