Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
adamniedzielski opened this issue Aug 30, 2017 · 1 comment

Comments

@adamniedzielski
Copy link

#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.

fables-tales pushed a commit that referenced this issue Sep 14, 2017
The problem here is that rails calls `#method_name` on the example a
number of times in order to correctly generate the screenshot and then
manipulate it. Given that we were randomising the integer that was
generated on every call, this didn't work.

This patch solves the problem by memoizing the generated method name so
that the screenshot path is generated once per example and then
correctly accessed on subsequent method calls.
@adamniedzielski
Copy link
Author

Thanks a lot for fixing this @samphippen 馃挌 馃

11factory pushed a commit to 11factory/rspec-rails that referenced this issue Oct 18, 2017
The problem here is that rails calls `#method_name` on the example a
number of times in order to correctly generate the screenshot and then
manipulate it. Given that we were randomising the integer that was
generated on every call, this didn't work.

This patch solves the problem by memoizing the generated method name so
that the screenshot path is generated once per example and then
correctly accessed on subsequent method calls.
sebjacobs pushed a commit to futurelearn/rspec-rails that referenced this issue Mar 15, 2019
The problem here is that rails calls `#method_name` on the example a
number of times in order to correctly generate the screenshot and then
manipulate it. Given that we were randomising the integer that was
generated on every call, this didn't work.

This patch solves the problem by memoizing the generated method name so
that the screenshot path is generated once per example and then
correctly accessed on subsequent method calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant