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.
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!" end end Given /^a greeter$/ do @greeter = CucumberGreeter.new end When /^I send it the greet message$/ do @message = @greeter.greet end Then /^I should see "([^"]*)"$/ do |greeting| @message.should == greeting end
run this command to run test case