I learn Ruby on Rails, so I treat me like a complete neophyte, because I am.
I have a User model with some related RSpec tests, and the following test fails:
require 'spec_helper'
describe User do
it 'should require a password' do
User.new({:email => 'valid_email@example.com', :password => '', :password_confirmation => ''}).should_not be_valid
end
end
The relevant part of the model is Useras follows:
class User < ActiveRecord::Base
...
validates :password, :presence => true,
:confirmation => true,
:length => { :minimum => 6 }
...
end
Here's the catch: if I started User.new(...).valid?from the Rails console using the above arguments, it returns false as expected and shows the correct errors (password is empty).
I used spork / autotest and I restarted both to no avail, but this test also does not allow to run it directly with rspec. What am I doing wrong here?
EDIT
I tried a few more things with the test. This fails:
u = User.new({:email => 'valid_email@example.com', :password => '', :password_confirmation => ''})
u.should_not be_valid
So does it:
u = User.new({:email => 'valid_email@example.com', :password => '', :password_confirmation => ''})
u.valid?
u.errors.should_not be_empty
, , :password :
u = User.new({:email => 'valid_email@example.com', :password => '', :password_confirmation => ''})
u.password.should == ''