问题描述
我有一些ruby测试调用不同的模块,在那里他们详细说明他们在执行过程中用puts命令做什么。
在控制台中运行这些测试,然后在控制台中看到puts命令的输出,但如果使用以下选项运行测试:
ruby --format html --output file.html
丢失。有没有办法在HTML报告中记录简单的字符串消息?
#features / support / env.rb
$ world = self
end
然后在你的支持类和模块外面你可以使用puts作为:
$ world.puts'something'
您还可以获取/设置Cucumber实例变量为:
$ world.instance_variable_get(:@ user)
$ world.instance_variable_set(:@ user,user)
我也喜欢提取这两种方法来帮助更好的可见性:
模块助手
def get_scenario_variable(symbol)
$ world.instance_variable_get(symbol)
end
def set_scenario_variable(symbol,value)
$ world.instance_variable_set $ b end
end
然后,您可以将此模块包含在需要这些方法的地方
I've got some ruby tests that are calling different modules, classes where they detail what they're doing with some "puts" commands during execution.
If you run those tests in the console then you will see the output of the "puts" command in the console but if you run the tests with the option:
ruby --format html --output file.html
then all that information is lost. Is there a way to log simple string messages inside the HTML report?
You can remember World in Before hook of each scenario:
# features/support/env.rb
Before do |scenario|
$world = self
end
Then in your support classes and modules outside world you can use puts as:
$world.puts 'something'
Also you can get/set Cucumber instance variables as:
$world.instance_variable_get(:@user)
$world.instance_variable_set(:@user, user)
I also prefer to extract those 2 methods to helpers for better visibility:
module Helpers
def get_scenario_variable(symbol)
$world.instance_variable_get(symbol)
end
def set_scenario_variable(symbol, value)
$world.instance_variable_set(symbol, value)
end
end
Then you can include this module where you need those methods
这篇关于黄瓜/红宝石:可能输出“puts”到一个--format html文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!