Rspec Lession 1


Commands


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 :

https://github.com/rspec/rspec-rails

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

it ‘should be empty when created’ do
Hash.new.should == {}
end

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

end

Note:

: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

http://betterspecs.org/

Advertisements

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:

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: