1

这是我的黄瓜脚本错误。虽然我知道期望值和得到的值是不同的,但我不知道如何解决这个问题。

Then my output should be:     # features/step_definitions/fourth_steps.rb:10
  | 4 |
  expected: ["4"]
       got: "[4]" (using ==) (RSpec::Expectations::ExpectationNotMetError)
  ./features/step_definitions/fourth_steps.rb:11:in `/^my output should be:$/'
  features\fourth.feature:6:in `Then my output should be:'

特征文件:fourth.feature

Feature: Cucumber Exercises
  Scenario: Try data table for the first exercises
  Given I have these numberic operations:
   |2+2|
  When calculator is run
  Then my output should be:
   | 4 |

步骤定义:fourth_steps.rb

Given(/^I have these numberic operations:$/) do |table|
  @input = table.raw.flatten
end

When(/^calculator is run$/) do
  @output = `ruby calc.rb #{@input}`
  raise ("calc.rb did not run properly.") unless $?.success?
end

Then(/^my output should be:$/) do |table|  
  @output.should == table.raw.flatten
end

计算器

print eval (ARGV[0]) 
4

1 回答 1

0

尝试这个。改变

When(/^calculator is run$/) do
  @output = `ruby calc.rb #{@input}`
  raise ("calc.rb did not run properly.") unless $?.success?
end

When(/^calculator is run$/) do
  @output = []
  @input.each { |i| @output << `ruby calc.rb #{i}`}  
  raise ("calc.rb did not run properly.") unless $?.success?    
end
于 2013-09-16T16:37:09.797 回答