4

我想在失败的场景后输出页面的屏幕截图。

我正在使用 capybara、rspec 和 launchy - 我的 gemfile 有

group :development, :test do
    gem 'rspec-rails'
    gem 'capybara'
    gem 'launchy'
end 

我看过各种建议,其中包括以下代码

After do |scenario|
  save_and_open_page if scenario.failed?
end

所以,我创建了一个 spec\support\env.rb 文件,我在其中放入了这段代码(仅此而已,该文件中没有其他内容)。现在当我跑

bundle exec rspec

我明白了

C:/Working/x/spec/support/env.rb:1:in `<top (required)>': undefined method `After' for main:Object (NoMethodError)

如果我注释掉 env.rb 中的行,那么测试会按我的预期运行。

我错过了什么?

谢谢

版本:

  • 导轨 4
  • rspec 2.14.1
  • 水豚 2.1.0
  • 启动 2.3.0
4

3 回答 3

3

@ejosafat - 额外的“示例”。在你的回答中,所以我使用它如下:

RSpec.configure do |config|
  config.after { |example_group| save_and_open_page if example_group.exception }
end
于 2016-10-07T11:37:52.303 回答
2

尝试将其包装在 Rspec.configure 块中,例如:

RSpec.configure do |config|
  config.after { |example_group| save_and_open_page if example_group.exception }
end
于 2013-10-30T11:29:30.900 回答
1

有一个 gem,你只需要把它添加到你的 Gemfile 中:

gem 'capybara-screenshot', :group => :test

所有说明都可以在这里找到:- https://github.com/mattheworiordan/capybara-screenshot

于 2014-05-28T12:53:35.437 回答