Rspec Lession 1


cmd                                     Description

rspec spec/                        To run all test cases

Some key words:

describe    we use describe to describe the behavior of a class, Describe encapsulates some testing scenarios on different conditions

context     Sub block used in describe to differntiate different main scenarios, for instance use context to run different test scenarios for users having different roles like different behaviour for admin and public user.

it               used to encapsulate some specific scenario either used directly in describe or nested in context block.

specify     It is equivalent to it but it uses code block instead of text description.

subject    subject method tells Rspec what we are going to test

Gem used :

gem ‘rspec-rails’
gem ‘factory_girl_rails’

First Test Case:

describe Hash do
# before or after block it will have same effect.

before(:all) do
@hash = {:hello => ‘world’}

it ‘should be empty when created’ do == {}

it ‘should return correct value’ do
@hash[:hello].should == ‘world’



:each is default option for before/after block it will be executed before each scenario. If you passed :each or not specified any option in


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

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: