testing - How to test model defaults in Rails with Rspec -


i want test new user when signed up, not admin (as set default: false in migration). here's user_spec.rb far:

require 'spec_helper'  describe user      before { @user = factorygirl.build(:user) }      subject { @user }    { should respond_to(:username) }   { should respond_to(:email) }   { should respond_to(:admin) }    describe "when username short"     before { @user.username = 'ab' }     { should_not be_valid }   end    describe "when username long"     before { @user.username = 'a' * 26 }     { should_not be_valid }   end    describe "username present"     before { @user.username = " " }     { should_not be_valid }   end end 

i've tried

it "should not admin"   expect { @user.admin }.to be_false end 

but returns:

   expected: false value         got: #<proc:0x007ffc4b544a58@" 

i suspect because i'm running tests based off factory defeat purpose of testing default value if explicitly put 'admin false' factory.

how can test default model values? should run through sign capybara , test user?

you need pass @user.admin expect parameter, not within block, in:

expect(@user.admin).to be(false) 

passing block intended cases want evaluate side effects of operation, such updating database, raising error, etc.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -