Why and When Use of specify instead of it


Both it( ) and specify( ) are actually aliases of the example( ) method, which creates an example.

When used it


describe "A new chess board" do

 before(:each) do
  @board = Chess::Board.new
 end

 it "should have 32 pieces" do
  @board.should have(32).pieces
 end
end

This example uses the specify( ) method instead of it( ) because specify is more readable when there is no docstring.

When used Specify


describe "A new chess board" do
 before(:each) { @board = Chess::Board.new }
 specify { @board.should have(32).pieces }
end

When you run rspec command, both will output like this:


 A new chess board
  should have 32 pieces

If the example (or it or specify) method does not receive a docstring, it uses the last of these descriptions that it
receives. In this example, there is only one: “should have 32 pieces.”

Summerizing:
Sometimes your code will looks like example described, So you can rely on Rspec’s automatic name generation to produce name you are looking for.

Referenced from:
The Rspec Book

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, TDD & BDD

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: