Ruby Can';我们无法得到一个场景';Cucumber 2.3.2中scenario.file的文件名

Ruby Can';我们无法得到一个场景';Cucumber 2.3.2中scenario.file的文件名,ruby,cucumber,hook,scenarios,Ruby,Cucumber,Hook,Scenarios,我在Rails app/features/support/hooks.rb中有以下代码: After do |scenario| if scenario.failed? filename = "#{FAILED_DIR_PATH}/failed--#{scenario.file.gsub("features/","").gsub("/","-")}--#{scenario.line}.html" Capybara.save_page filename end end 如

我在Rails app/features/support/hooks.rb中有以下代码:

After do |scenario|
  if scenario.failed?
    filename = "#{FAILED_DIR_PATH}/failed--#{scenario.file.gsub("features/","").gsub("/","-")}--#{scenario.line}.html"
    Capybara.save_page filename
  end
end
如果文件
/features/user\u features/user\u login.feature
中第
12行的场景失败,则使用默认的capybara页面转储文件名

tmp/capybara/capybara-5654648798738734.html
转储将使用更好的文件名保存:

tmp/capybara/failed--user_features-user_login.feature--12.html
因此,如果有许多失败,我立即知道哪个转储是正确的

这在Cucumber 1.3.2中起作用

今天我更新了gems,得到
cucumber2.3.2
,出现以下错误:

 undefined method `file' for #<Cucumber::RunningTestCase::Scenario:0x007f9598abb230>
我唯一能找到文件名的地方是
scenario.exception.backtrace
(深深埋藏在水豚文件下面)


现在是否有可能获取场景文件路径和场景开始的行号?

在Cucumber 2中,
文件和
行是
场景的
位置的属性,而不是
场景本身的属性。将
scenario.file
替换为
scenario.location.file
并将
scenario.line
替换为
scenario.location.line

感谢Dave对我的问题进行了难以置信的更正和改进。
Cucumber::RunningTestCase::Scenario#methods: 

accept_hook?  exception  failed?  outline?  passed?  skip_invoke!  source_tag_names  source_tags  status  title   with_result