środa, 24 sierpnia 2016

Extract method refactor and passing &block

Today I've tried to refactor code by extracting some part to a method. Spuriously it didn't work.

Problem was with passing block to a method. when you do that you pass block to method not the results.
In order to fix it we need to pass a block to find_each method by using &Proc.new as an extra argument. According to this article it is a fastest method.

środa, 24 lutego 2016

Take screenshot in IntegrationTest with capybara when it fails

This is about saving screenshot on failing tests in capybara. There are bunch of advices how to do this in rspec but none for ActionDispatch::IntegrationTest. There is also a gem for this capybara-screenshot but I haven't got luck with this at all.

Here is how to do this with rails 4 integration test. Under the hood it uses minitest that have bunch of hooks we can use.


Most of code stolen from http://vumanhcuongit.github.io/testing/2016/01/26/take-screenshot-when-cucumber-test-failed/ and https://github.com/mattheworiordan/capybara-screenshot