Commands:
rake db:test:prepare command to prepare test database for testing also whenever new migration added or changed
Test Case:
Note: you don’t need to define Stub method if it is not already exists.
describe User
describe ‘get stubed method’ do
before{ User.stub(:abc).and_return(‘it is not method’) }# User.abc does not existed
specify {User.abc.should eq ‘it is not method’}
end
end
Use before(:each)
, not before(:all)
Stubs in before(:all)
are not supported. The reason is that all stubs and mocks get cleared out after each example, so any stub that is set in before(:all)
would work in the first example that happens to run in that group, but not for any others.
Instead of before(:all)
, use before(:each)
.
Advertisements
Leave a Reply