开发者

Releasing a Cucumber-* gem which uses the After blocks

开发者 https://www.devze.com 2023-04-12 07:59 出处:网络
I\'ve built a simple Gem to do screenshots for Capybara Webkit on scenario failure, and it also saves an HTML file of the current page regardless of which Capybara driver you are using. However, I am

I've built a simple Gem to do screenshots for Capybara Webkit on scenario failure, and it also saves an HTML file of the current page regardless of which Capybara driver you are using. However, I am experiencing a problem I can't see overcome whereby whenever the code in the Gem is called, page.body is empty. However, page.body is not empty when I use that exact same code within the Rails app.

The gem code is on Github at https://github.com/mattheworiordan/capybara-screenshot

If you take a look, you will see that I have a lib/capybara-screenshot/world.rb file which access page.body and saves the contents out. The problem is that when the Gem access page.body, page.body is empty and simply contains: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http:开发者_开发百科//www.w3.org/TR/REC-html40/loose.dtd"> I am including world.rb in the gem's lib root file, so I can't really see what I am doing wrong.

Strangely, if I put an after block into my sample Rails app env.js file accessing page.body has the correct HTML, so it seems that calling After { my code } in the Gem is being executed once the page has been released.

The gem code is at https://github.com/mattheworiordan/capybara-screenshot, and the gem is installed at https://rubygems.org/gems/capybara-screenshot. The sample Rails app which you can use to quickly recreate this issue by simply running cucumber is at https://github.com/mattheworiordan/capybara-screenshot-test

I feel like the answer to this is simple, but for some reason I can't see it. I appreciate any help you can offer.


Joe Ferris over at Thoughtbot pointed me in the right direction, and pointed out that you need to make sure that the After hook is loaded after capybara's, so I needed make sure to require whatever files I depend on. In this case, I needed to require capybara/cucumber.

You can see the working Gem at https://github.com/mattheworiordan/capybara-screenshot

0

精彩评论

暂无评论...
验证码 换一张
取 消