johnnybutler7
2010-Jul-07 12:31 UTC
[rspec-users] Remarkable Rails validations not working
Hi, Ive installed the remarkable_rails plugin(3.1.13) so i can use the macros to test the model associations and validations. For my model user i have: validates_presence_of :title, :message => ''cannot be blank!'' validates_length_of :title, :within => 2..40, :too_short => ''is too short!'', :too_long => ''is too long!'' For my user_spec file i have: describe "validations" do subject { Factory.build(:user) } it { should_validate_presence_of :title } it { should validate_length_of(:title, :within => 2..40) } end But when i run my specs i get errors: 1) ''validations should require title to be set'' FAILED Expected User to require title to be set 2) ''validations should ensure length of title is within 2..40 characters'' FAILED Expected User to be invalid when title length is less than 2 characters I cant understand why this isnt working? If i write regualr rspec code it works, see below but i dont want to have to do this for every validation. it "should be invalid without a title" do @user.title = nil @user.should_not be_valid @user.errors.on(:title).size.should == 2 @user.errors.on(:title).should include("cannot be blank!") @user.errors.on(:title).should include("is too short!") end Has anyone got any ideas why the remarkable rails plugin is not validating correctly? JB