First Test Case Cucumber

For Cucumber We have to create a sample project and on project root we will create features and spec direcotries.
In features directory create a file greeter_says_hello.feature and place this code inside that file.

Feature: greeter says hello
  In order to start learning RSpec and Cucumber
  As a reader of The RSpec Book
  I want a greeter to say Hello

Scenario: greeter says hello
  Given a greeter
  When I send it the greet message
  Then I should see "Hello Cucumber!"

after this when you run this command in project root


It will fail as Given, When and Then are not defined in step definitions.

To get this scenario to pass, we need to store step definitions in a file
that Cucumber can load. So create a step_definitions directory inside features directory.

Step Definition:
A step definition is a method that creates a step. Examples of step definitions are Given, When and Then etc.
Each of which takes a Regexp and a block. Cucumber will read the first step in the scenario look for a step definition whose regular expression matches that step; and then execute that step definition’s block.

Create greeter_steps.rb file in step_definitions directory and place this code

class CucumberGreeter
 def greet
  "Hello Cucumber!"

Given /^a greeter$/ do
  @greeter =

When /^I send it the greet message$/ do
  @message = @greeter.greet

Then /^I should see "([^"]*)"$/ do |greeting|
  @message.should == greeting

run this command to run test case

cucumber features/

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

Tagged with: , ,
Posted in TDD & BDD

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: