BDD with PageObject

Add step definitions to support feature files

Create "step_definitions" folder using:

mkdir step_definitions

alt text

Create "calculator_steps" to support calculator features:

cd step_definitions

touch calculator_steps.rb

alt text

Edit "calculator_steps.rb" to contain following content:

# encoding: utf-8
begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end
require 'cucumber/formatter/unicode'
$:.unshift(File.dirname(FILE) + '/../../lib')
require 'calculator'

Before do @calc = Calculator.new end

After do end

Given /I have entered (\d+) into the calculator/ do |n| @calc.push n.to_i end

When /I press (\w+)/ do |op| @result = @calc.send op end

Then /the result should be (.*) on the screen/ do |result| @result.should == result.to_f end

alt text