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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 7.1 raise WrongScopeError on take_failed_screenshot #2707

Closed
senid231 opened this issue Oct 28, 2023 · 3 comments
Closed

Rails 7.1 raise WrongScopeError on take_failed_screenshot #2707

senid231 opened this issue Oct 28, 2023 · 3 comments

Comments

@senid231
Copy link

I see the additional error WrongScopeError: metadata is not available from within an example when the system test failed

What Ruby, Rails and RSpec versions are you using?

ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
Rails 7.1.1
RSpec 3.12
  - rspec-core 3.12.2
  - rspec-expectations 3.12.3
  - rspec-mocks 3.12.5
  - rspec-rails 6.0.3
  - rspec-support 3.12.0

Observed behaviour

4.2) Failure/Error:
            raise WrongScopeError,
                  "`#{name}` is not available from within an example (e.g. an " \
                  "`it` block) or from constructs that run in the scope of an " \
                  "example (e.g. `before`, `let`, etc). It is only available " \
                  "on an example group (e.g. a `describe` or `context` block)."

            `metadata` is not available from within an example (e.g. an `it` block) or from constructs that run in the scope of an example (e.g. `before`, `let`, etc). It is only available on an example group (e.g. a `describe` or `context` block).

          [Screenshot Image]: /home/runner/work/senid231/test_project/tmp/capybara/....png

          [Screenshot HTML]: /home/runner/work/senid231/test_project/tmp/capybara/....html


          # /home/runner/work/senid231/test_project/vendor/bundle/ruby/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/example_group.rb:760:in `method_missing'
          # /home/runner/work/senid231/test_project/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.1/lib/active_record/test_fixtures.rb:278:in `method_missing'
          # /home/runner/work/senid231/test_project/vendor/bundle/ruby/3.2.0/gems/actionpack-7.1.1/lib/action_dispatch/testing/assertions/routing.rb:195:in `method_missing'
          # /home/runner/work/senid231/test_project/vendor/bundle/ruby/3.2.0/gems/actionpack-7.1.1/lib/action_dispatch/testing/integration.rb:440:in `method_missing'
          # /home/runner/work/senid231/test_project/vendor/bundle/ruby/3.2.0/gems/actionpack-7.1.1/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb:48:in `take_failed_screenshot'
          # /home/runner/work/senid231/test_project/vendor/bundle/ruby/3.2.0/gems/actionpack-7.1.1/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb:8:in `before_teardown'
          # /home/runner/work/senid231/test_project/vendor/bundle/ruby/3.2.0/gems/rspec-rails-6.0.3/lib/rspec/rails/example/system_example_group.rb:110:in `call'
          # /home/runner/work/senid231/test_project/vendor/bundle/ruby/3.2.0/gems/rspec-rails-6.0.3/lib/rspec/rails/example/system_example_group.rb:110:in `block (2 levels) in <module:SystemExampleGroup>'

broken due to changes in ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper#take_failed_screenshot added here

        def take_failed_screenshot
          return unless failed? && supports_screenshot? && Capybara::Session.instance_created?

          take_screenshot
          metadata[:failure_screenshot_path] = relative_image_path if Minitest::Runnable.method_defined?(:metadata)
        end

Expected behaviour

No additional exception

Can you provide an example app?

reproduces on any failed system test with rails 7.1

@senid231
Copy link
Author

temporary fix:

spec/rspec_screenshot_helper_patch.rb

module RspecScreenshotHelperPatch
  def take_failed_screenshot
    return unless failed? && supports_screenshot? && Capybara::Session.instance_created?

    take_screenshot
  end
end

spec/rails_helper.rb

require_relative 'rspec_screenshot_helper_patch'
# ...
RSpec.configure do |config|
  # ...
  config.include RspecScreenshotHelperPatch, type: :system
end

@pirj
Copy link
Member

pirj commented Oct 28, 2023

Same as #2690? Do you want to contribute a fix? Does #2704 fix the issue for you?

@senid231
Copy link
Author

thanks @pirj

yes, looks like my issues same as #2690, will close this one

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

2 participants