small medium large xlarge

18 Sep 2013, 12:56
Laurie Whelan (1 post)

Could someone please help? I am new to programming and my developers want me to start automating our tests using Cucumber. I have been trying to work through the examples in the book and am hung up on Chapter 7. I have entered all of the information in the Step Definitions that the book shows but it is still saying the “When section” is undefined. I have gone back and read over everything three times and can’t find what is wrong. PLEASE HELP! This is what I get when I run cucumber:

Scenario: Successful withdrawal from an account in credit # features\cash_withdrawal.feature:3 Given I have deposited $100 in my account # features/Step_definitions/steps.rb:46 When I request $20 # features\cash_withdrawal.feature:5 Then $20 should be dispensed # features/Step_definitions/steps.rb:62

1 scenario (1 undefined) 3 steps (1 skipped, 1 undefined, 1 passed) 0m0.040s

You can implement step definitions for undefined steps with these snippets:

When(/^I request $(\d+)$/) do |arg1| pending # express the regexp above with the code you wish you had end

This is the code I have in my steps.rb file. Can someone please tell me what I’m doing wrong? I have done this and redone this and it still fails in step 2.

class Account def deposit(amount) @balance = amount end

def balance @balance end end

class Teller def withdraw_from(account, amount) end end

class CashSlot def contents raise(“I’m empty!”) end end

module KnowsMyAccount def my_account @my_account ||= end end


“module KnowsTheDomain def my_account @my_account ||= end

def cash_slot @cash_slot ||= end end


CAPTURE_CASH_AMOUNT = Transform /^$(\d+)$/ do |digits| digits.to_i end

Given /^I have deposited (#{CAPTURE_CASH_AMOUNT}) in my account$/ do |amount| my_account.deposit(amount) my_account.balance.should eq(amount), “Expected the balance to be #{amount} but it was #{my_account.balance}” end

“When /^I withdraw (#{CAPTURE_CASH_AMOUNT})$/ do |amount| teller = teller.withdraw_from(my_account, amount) end”

When /^I withdraw (#{CAPTURE_CASH_AMOUNT})$/ do |amount| teller = teller.withdraw_from(my_account, amount) end

Then /^(#{CAPTURE_CASH_AMOUNT}) should be dispensed$/ do |amount| “cash_slot.contents.should == amount” end

29 Jan 2014, 06:43
Don Dalenberg (1 post)

I think you may need to add the following under KnowsTheDomain:

def teller

@teller ||=