rspec / rspec-rails

RSpec for Rails 6+
https://rspec.info
MIT License
5.16k stars 1.03k forks source link

Wrong screenshot path when attempting to render screenshot in system tests #1865

Closed adamniedzielski closed 7 years ago

adamniedzielski commented 7 years ago

https://github.com/rspec/rspec-rails/pull/1813 introduced support for Rails 5.1 system tests. Thank you for that! 🎉 We're already using it (living on the edge 😄).

We encountered an issue with automatic screenshots that are created when a spec fails. Apart from the actual failure message (for example Failure/Error: expect(page).to have_content("Details zu Sendunggg")) we also get an error message that screenshot cannot be displayed (No such file or directory @ rb_sysopen).

The screenshot is correctly saved to tmp/screenshots, but it cannot be displayed.

See:

  1.1) Failure/Error: expect(page).to have_content("Details zu Sendunggg")
            expected to find text "Details zu Sendunggg" in "Custom CSS test Status der Sendung: E5UPV Details zu Sendung E5UPV Wir werden zwischen 19 und 20 Uhr bei dir sein! Kurier"

          # ./spec/system/landing_page_spec.rb:16:in `block (2 levels) in <top (required)>'

     1.2) Failure/Error: image = inline_base64(File.read(image_path))

          Errno::ENOENT:
            No such file or directory @ rb_sysopen - tmp/screenshots/failures_r_spec_example_groups_landing_page_displays_the_page_with_shipment_information_428.png

          # /Users/adam/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.1.1/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb:73:in `read'
          # /Users/adam/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.1.1/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb:73:in `display_image'
          # /Users/adam/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.1.1/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb:25:in `take_screenshot'
          # /Users/adam/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.1.1/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb:36:in `take_failed_screenshot'

After looking at the rspec-rails code, it seems that rspec-rails implements method_name method here. Rails uses this method to generate the screenshot path here.

The thing is that method_name generates a random number and Rails seems to call it twice, so we get two different paths and reading the image fails.

Please let me know if I can provide any more details to help you identify the problem.

adamniedzielski commented 7 years ago

Thanks a lot for fixing this @samphippen 💚 🥇