When your tests do should be_true
what is happening is the should call is being delegated to the subject object (see RSpec docs for implicit receiver). In this case, your subject object is a User instance that has not yet been saved to the database. If your user_spec.rb file starts with describe User do
, RSpec is automatically providing this default subject of User.new (see RSpec docs for implicit subject).
What this means is that your tests are essentially doing User.new.should be_true
and User.new.should be_false
. Since a User object will always evaluate to true, the should be_true
test will always pass (although probably not for the reason you wanted it to) and the should be_false will always fail.
Based on the way your tests are written, maybe you meant something more like this:
describe "roles" do
before(:each) do
@user = FactoryGirl.create(:user)
end
it "should not approve incorrect roles" do
@user.add_role :moderator
@user.has_role?(:admin).should be_false
end
it "should approve correct roles" do
@user.add_role :moderator
@user.has_role?(:moderator).should be_true
end
end