2013-09-16 100 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