这两个示例都将发送到STDOUT,但cucumber只看到第一个。第二个场景失败了,原因是:
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发布于 2012-08-01 14:18:09
我对Aruba不是很熟悉,但快速浏览一下它的source code就会发现,它针对STDOUT (或任何输出)所做的断言只适用于它自己启动的进程,并不是所有写入STDOUT的内容。在第二个场景中,您自己调用的代码不在Aruba的控制范围内,因此它的输出将不会被跟踪。
如果你仔细想想,它不可能以其他方式工作--如果Aruba捕获了断言的所有STDOUT,那么它也会包含Cucumber自己的测试输出……
看起来您正在尝试在进程内测试您的程序,而不使用Aruba调用单独的Ruby进程。如果是这种情况,我建议修改程序,使其可以传递一个STDOUT替代。
def initialize(output=$stdout)然后,当您启动代码时:
When /^I start the program$/ do
TestModule::Main.new(@output).start
end你可以改变你的断言:
Then the stdout should contain "(.+)" do |string|
@output.should include string
endhttps://stackoverflow.com/questions/11747007
复制相似问题