I am following a Rails tutorial, and we created a user model, then were testing it with RSpec. In the spec/model/user_spec.rb we have:
require 'spec_helper'
describe User do
before do
@user = User.new(name: "Example User", email: "user@example.com")
end
subject { @user }
it { should respond_to(:name) }
it { should respond_to(:email) }
it { should be_valid }
describe "when name is not present" do
before { @user.name = " " }
it { should_not be_valid }
end
end
When running the test it fails. When we add the following in the user model:
validates :name, presence: true
it passes. I understand that. What I don't understand is the use of this:
describe "when name is not present" do
before { @user.name = " " }
it { should_not be_valid }
end
Isn't the validate presence enough?