Rspec Lesson 2


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

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

StackOverFlow
Categories
Archives
%d bloggers like this: