On Wed, Aug 11, 2010 at 12:53 PM, Nadal <[email protected]> wrote:
> I posted a question on shoulda forum. It is under moderation so I
> don't have a link yet.
>
> To the people who do not use shoulda: How would you write a test for
> above case. I assume it would require set up a subject, set nil value,
> and then see if there is an error message. I still think that for such
> cases should macro is succint and does it job well unless I am missing
> some new feature of rspec2.
I don't yet use RSpec 2, but I don't think you're missing anything. Shoulda
may very well be a good fit for these kinds of examples.
Since you asked, here's how I currently write examples like the ones you
posted.
require 'spec_helper'
describe User, "being valid" do
it "requires an email" do
user = User.new(:email => nil)
user.should_not be_valid
user.should have(1).error_on(:email)
end
it "requires a name" do
user = User.new(:name => nil)
user.should_not be_valid
user.should have(1).error_on(:name)
end
end
Regards,
Craig
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users