require File.join(File.dirname(__FILE__), "validation_matcher_spec_support") describe ValidationSpecHelper, "messages" do include ValidationSpecHelper # to catch the generated descriptions before(:each) do @desc = nil @callback = lambda { |desc| @desc = desc } Spec::Matchers.description_generated(@callback) end before(:each) { @it = Person.new } it "should generate correct description with acceptance for a field, using 'of' syntax'" do @it.should accept(:firstname).of("foobar") @desc.should == "should accept firstname of \"foobar\"" end it "should generate correct description with rejection for a field, using 'of' syntax'" do @it.should reject(:firstname).of(nil) @desc.should == "should reject firstname of nil" end it "should generate correct description with acceptance for a field, using 'for' syntax'" do @it.should accept("foobar").for(:firstname) @desc.should == "should accept \"foobar\" for firstname" end it "should generate correct description with rejection for a field, using 'for' syntax" do @it.should reject(nil).for(:firstname) @desc.should == "should reject nil for firstname" end it "should generate correct description with expection of a specific error message" do @it.should reject(nil).for(:firstname).with("can't be blank") @desc.should == "should reject nil for firstname with \"can't be blank\"" end it "should generate correct description with acceptance of multiple fields" do @it.should accept("firstname", "lastname").for(:firstname, :lastname) @desc.should == "should accept \"firstname\", \"lastname\" for firstname, lastname" end it "should report false acceptance of a single field with a single error message" do lambda do @it.should accept("").for(:firstname) end.should raise_error(Spec::Expectations::ExpectationNotMetError, <