small medium large xlarge

Generic-user-small
01 Mar 2016, 03:17
HF (1 post)

I’m working through Chapter 2 and have just gotten all three steps to pass, the problem is that I haven’t implemented my calc.rb method yet. I created the file, but it is empty, yet when I run cucumber it Passes all three steps.

Here is what the code looks like

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| 
expect(output) == output
end

RESULT

Feature: Adding

  Scenario: Add two numbers       # features/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
    Then the output should be "4" # features/step_definitions/calculator_steps.rb:10

1 scenario (1 passed)
3 steps (3 passed)
0m0.086s

Also, when I try adding the “Print 4” statement to the calc.rb file, it prints the character (4) BEFORE my results, please see below: (notice the 4 is the first character in the results)

4Feature: Adding

  Scenario: Add two numbers       # features/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
    Then the output should be "4" # features/step_definitions/calculator_steps.rb:10

1 scenario (1 passed)
3 steps (3 passed)
0m0.082s
Generic-user-small
07 Jul 2016, 05:07
Tim O'Connor (3 posts)

I see the same answer. I’ve done a diff on my version of the file vs. the source code. I get an error about .should being an undefined function. Once I remove that, then the scenario and all the steps pass regardless of what is in calc.rb.

Has cucumber behavior changed since this example was written?

Generic-user-small
07 Jul 2016, 05:20
Tim O'Connor (3 posts)

Nevermind, I found the answer by digging around more. Another forum post mentioned that .should is deprecated in RSPEC and we should substitute .expect for .should

Once I did that, the example works as the book illustrates.

Side Note: not sure if I installed incorrectly, but for some reason cucumber didn’t install RSPEC gem. I had to manually install that before expect would work.

You must be logged in to comment