On 9/4/07, Geoffrey Wiseman <[EMAIL PROTECTED]> wrote:
> Having used JUnit and Test::Unit, I'm quite used to having the ability to
> insert a failure message, which helps when tests fail.
>
> For instance, the example RSpec that is generated for a model class
> specifies that the model class is valid.  Assuming this were supposed to be
> true, and it failed, I've now got to duplicate the code in the test in order
> to find out why it wasn't valid.
>
> Whereas if I were writing the same code in Test::Unit, I might write:
>   assert model.valid?, "Expected model to be valid, but found these errors:
> #{model.errors}"
>
> This means that when the model validation fails, I know /why/.  I don't see
> an easy way to include these sorts of messages in RSpec, which seems likely
> to cause me to waste time on test failures.  Am I missing something?  How
> are experienced RSpec users resolving this?

I come from the same background as you, so I hear where you're coming
from. We made a conscious decision, however, not to support custom
messages almost two years ago and I'm not sure if its ever even come
up before. If it has, it was a long time ago.

If you follow the conventions of one expectation per example, and your
example is well named, this is less of a problem. Here's a common
idiom:

describe Person do
  def valid_attributes
    {:name => 'joe smith'}
  end
  before(:each) do
    @person = Person.new(valid_attributes)
  end
  it "should be valid with valid attributes" do
    @person.should be_valid
  end
  it "should be invalid with no name" do
    @person.name = nil
    @person.should_not be_valid
  end
end

Together, these different examples help to tell the whole story, and
when one example fails you know why it's failing - its just that the
message is in the example's name instead of a custom assertion
message.

Make sense?

>
> Thanks,
>
>   - Geoffrey
> --
> Geoffrey Wiseman
>
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to