Rspec Lesson 2


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’) }

# does not existed

specify { eq ‘it is not method’}




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).


I am Senior Software Engineer. I love reading, writing, sharing,developing, hiking, movies, trips, mountains, brooks, hills etc.

Tagged with:
Posted in RSpec and Cucumber

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: