我通过执行Cucumber::Cli::Main.new(args).execute!
你怎么知道什么时候黄瓜:: Cli时:: Main.new(参数).execute执行完毕
但是Ruby移到下一行运行黄瓜脚本,并开始从读文件。但文件是空的,因为黄瓜需要时间来处理
如何使执行停止,直到Cucumber完成执行脚本并完成使用HTML填充文件。谢谢
这里是源代码的链接:https://github.com/cucumber/cucumber-ruby/blob/master/lib/cucumber/cli/main.rb
require 'cucumber'
require 'tempfile'
require 'securerandom'
filename = "#{SecureRandom.urlsafe_base64}"
file = Tempfile.new(filename)
filepath = "#{file.path}"
features = "features/login.feature"
args = features.split.concat %w(--format html --out)
args << "#{filepath}.html"
begin
Cucumber::Cli::Main.new(args).execute!
@value = file.read
ensure
file.close
file.unlink
end
编辑:
当Cucumber::Cli::Main.new(args).execute!
执行完毕后,它抛出一个SystemExit异常,并出现状态0
执行良好时退出代码为0
Cucumber在完成时总是抛出SystemExit异常。
这里是黄瓜源代码的链接:https://github.com/cucumber/cucumber-ruby/blob/master/lib/cucumber/cli/main.rb
如何处理在轨SystemExit例外,所以它不会跳跃执行的下一行。
def run
filename = "#{SecureRandom.urlsafe_base64}"
file = Tempfile.new(filename)
filepath = "#{file.path}"
features = "features/login.feature"
args = features.split.concat %w(-f html -o)
args << "#{filepath}.html"
Cucumber::Cli::Main.new(args).execute! # throws SystemExit Exception Status 0
@output = file.read
file.close
file.unlink
# More Code Below
# # # # # # # # #
end
我在黄瓜里看不到任何异步的东西,所以不应该发生。 '执行!'应该阻止 – Anthony
@Anthony黄瓜执行!抛出一个状态为0的SystemExit,所以发生异常并且下一行不会被执行。 –