small medium large xlarge

Generic-user-small
31 Jul 2014, 09:15
Richard Donovan (1 post)

According to 2.7 Adding an Assertion I need to create a blank calc.rb file (which I have put in the calculator dir. When I run cucumber again I get the same output as before -

C:\Users\466368\calculator>cucumber Feature: Adding

Scenario: Add two numbers # features\feature_file_adding.feature:3 Given the input “2+2” # features/step_definitions/calculator_steps.rb:1 When the calculator is run # features/step_definitions/calculator_steps.rb:5 undefined method success?' for nil:NilClass (NoMethodError) ./features/step_definitions/calculator_steps.rb:7:in /^the calculator is run$/’ features\feature_file_adding.feature:6:in `When the calculator is run’ Then the outut should be “4” # features/step_definitions/calculator_steps.rb:10

Failing Scenarios: cucumber features\feature_file_adding.feature:3 # Scenario: Add two numbers

1 scenario (1 failed) 3 steps (1 failed, 1 skipped, 1 passed) 0m0.120s

And when I run it as cucumber –format progress, I get this -

C:\Users\466368\calculator>cucumber –format progress .F-

(::) failed steps (::)

undefined method success?' for nil:NilClass (NoMethodError) ./features/step_definitions/calculator_steps.rb:7:in /^the calculator is run$/’ features\feature_file_adding.feature:6:in `When the calculator is run’

Failing Scenarios: cucumber features\feature_file_adding.feature:3 # Scenario: Add two numbers

1 scenario (1 failed) 3 steps (1 failed, 1 skipped, 1 passed) 0m0.101s

C:\Users\466368\calculator>

At this point I should have 2 tests pass and 1 pending. What have I done wrong..?

Avatar_pragsmall
01 Sep 2014, 20:39
Matt Wynne (91 posts)

Hi,

Can you show me the code for your file features/step_definitions/calculator_steps.rb please?

It sounds as though you have a typo in there somewhere.

Generic-user-small
02 Oct 2015, 01:29
Aya Seit (1 post)

Oh, I’m stuck on the same issue, could please anyone help me to go further?

Given(/^the input "([^"]*)"$/) do |input|
  @input = input
end

When(/^the calculator is run$/) do
  @output = 'ruby calc.rb #{input}'
  raise('Command failed!') unless $?.success?
end

Then(/^the output should be "([^"]*)"$/) do |expected_output|
  @output.should == expected_output
end

Generic-user-small
02 Nov 2015, 22:36
Alan D. Frank (1 post)

Hi Matt, I have the same issue trying to step through the calculator example in chapter 2.

Generic-user-small
23 Feb 2016, 14:42
Paul Kmecak (3 posts)

Hi, Matt.

I’ve got the same problem, too. Here’s my code:

Given(/^the input “([^”]*)”$/) do |input| @input = input end

When(/^the calculator is run$/) do @output = ‘ruby calc.rb #{@input}’ raise(‘Command Failed!!’) unless $?.success? end

Then(/^the oputput should be “([^”]*)”$/) do |arg1| pending # Write code here that turns the phrase above into concrete actions end

I checked the Errata, figuring there would be an update “so either just create an empty text file named calc.rb IN THIS DIRECTORY”. Nope.

I placed an empty calc.rb file in each directory in the calculator project, one at a time, and the second step definition still failed each time.

Does ANYBODY know where the calc.rb file is supposed to go?

Generic-user-small
23 Feb 2016, 21:15
Paul Kmecak (3 posts)

I finally got the 2nd step to work.

calc.rb goes in the top folder for the project, the same folder as the “features” folder is in.

Here’s the working code:

Given /^the input “([^”]*)”$/ do |input| @input = input end

When /^the calculator is run$/ do @output = ruby calc.rb #{@input} raise(‘Command failed!’) unless $?.success? end

Then /^the output should be “([^”]*)”$/ do |expected_output| pending # express the regexp above with the code you wish you had end

I downloaded the source code for the book. The correc code is in ..\hwcuc-code\code\first_taste\06\features\step_definitions.

Please note the structure of the source code directory corresponds with the little grey strips.

You must be logged in to comment