2013-09-16 98 views
1

这是我的黄瓜脚本错误。虽然我明白,预期和价值观是不同的,我不知道如何解决这个问题。如何解决此ExpectationNotMetError错误

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 

calc.rb

print eval (ARGV[0]) 

回答

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 
+0

它的工作,谢谢。 – RubyNoobie