0
兩個例子都是STDOUT,但黃瓜只能看到第一個。第二個方案失敗:爲什麼黃瓜與阿魯巴沒有看到我的程序輸出?
Then the stdout should contain "test" # aruba-0.4.11/lib/aruba/cucumber.rb:82
expected "" to include "test" (RSpec::Expectations::ExpectationNotMetError)
features/test.feature:13:in `Then the output should contain "test"'
特點:
Scenario: echo test
Given a blank slate
When I run `echo "test"`
The stdout should contain "test"
Scenario: puts test
Given a blank slate
When I start the program
The stdout should contain "test"
步驟定義:
When /^I start the program$/ do
TestModule::Main.new.start
end
代碼:
module TestModule
class Main
def initialize
end
def start
$stdout.puts "test"
end
end
end
謝謝。這個建議遵循RSpec Book的模式。我仍然不明白「它自己開始的過程」和「你自己調用的代碼」之間的區別是什麼。是不是在第一個斷言中,黃瓜大概是分叉進程來運行echo,但是一個新的類實例在同一個黃瓜進程中運行?無論如何,我認爲在* nix中,只有一個STDOUT。黃瓜怎麼知道它們的區別? – jordanpg 2012-08-01 16:33:14
看起來好像Aruba正在使用[childprocess](https://github.com/jarib/childprocess)gem來處理運行流程,這可能有助於瞭解發生了什麼 - 頭版上的文檔當然暗示消費者可以選擇如何處理新流程的標準輸出。我認爲'只有一個STDOUT'不必適用於分叉進程,所以Aruba可以自由地只查看對它感興趣的輸出。 – 2012-08-01 18:25:11
現在我明白了。 Aruba使用'ChildProcess'在echo命令的情況下創建一個新進程,並使用'ChildProcess'方法來檢查新進程的標準輸出。在後一種情況下,它正在查看不存在的子進程的標準輸出。 – jordanpg 2012-08-01 18:46:32