Topic: The Cucumber book test 1

i am doing this tutorial on the "The Cucumber book"  and my test is failing

features/step_definitions/calculator_steps.rb

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

features/adding.feature

Feature: Adding

  Scenario: Add two numbers
    Given the input "2+2"
    When the calculator is run
    Then the output should be "4"

calc.rb

print "4"

TEST OUTPUT

cucumber
Feature: Adding

  Scenario: Add two numbers       # features/adding.feature:3
    Given the input "2+2"         # features/step_definitions/calculator_steps.rb:9
    When the calculator is run    # features/step_definitions/calculator_steps.rb:13
    Then the output should be "4" # features/step_definitions/calculator_steps.rb:18
      undefined method `should' for "4":String (NoMethodError)
      ./features/step_definitions/calculator_steps.rb:19:in `/^the output should be "([^"]*)"$/'
      features/adding.feature:6:in `Then the output should be "4"'

Failing Scenarios:
cucumber features/adding.feature:3 # Scenario: Add two numbers

1 scenario (1 failed)
3 steps (1 failed, 2 passed)
0m0.019s

Re: The Cucumber book test 1

If should is not a method then rspec is not being loaded properly for some reason.

Last edited by themusicman (2012-05-23 23:53:13)

Re: The Cucumber book test 1

i am still not able to just output "4" on the calc.rb file

Re: The Cucumber book test 1

i am still getting

cucumber
Feature: Adding

  Scenario: Add two numbers       # features/adding.feature:3
    Given the input "2+2"         # features/step_definitions/calculator_steps.rb:9
    When the calculator is run    # features/step_definitions/calculator_steps.rb:13
    Then the output should be "4" # features/step_definitions/calculator_steps.rb:18
      undefined method `should' for "4\n":String (NoMethodError)
      ./features/step_definitions/calculator_steps.rb:19:in `/^the output should be "([^"]*)"$/'
      features/adding.feature:6:in `Then the output should be "4"'

Failing Scenarios:
cucumber features/adding.feature:3 # Scenario: Add two numbers

in the calc.rb file i had tried

puts 4
puts "4"
4
echo(4)
echo("4")


but i cant seem to get the cucumber to pass this test

Re: The Cucumber book test 1

i installed rvm by adding a .rvmrc file with this code

#!/usr/bin/env bash

environment_id="ruby 1.9.3-p194@calculator"

if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
  && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then
  \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
else
  # If the environment file has not yet been created, use the RVM CLI to select.
  rvm --create  "$environment_id"
fi

and added a Gemfile

source 'https://rubygems.org'

  # Build stuff
  gem 'watchr'
  gem 'bcat'
  # General stuff
  gem 'aruba'
  gem 'cucumber'
  gem 'rspec'
  # Rails stuff
  gem 'activerecord'
  gem 'capybara'
  gem 'coffee-rails'
  gem 'cucumber-rails'
  gem 'database_cleaner'
  gem 'factory_girl'
  gem 'jquery-rails'
  gem 'launchy'
  gem 'rails'
  gem 'rspec-rails'
  gem 'sass-rails'
  gem 'sqlite3'
  gem 'uglifier'
  # Non Rails stuff
  gem 'childprocess'
  gem 'httparty'
  gem 'json'
  gem 'rack-test'
  gem 'service_manager'
  gem 'sinatra'