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

WrongScopeError exception with edge rails #37783

Closed
jasnow opened this issue Nov 23, 2019 · 7 comments
Closed

WrongScopeError exception with edge rails #37783

jasnow opened this issue Nov 23, 2019 · 7 comments

Comments

@jasnow
Copy link

jasnow commented Nov 23, 2019

This morning (11/23/2019) I'm getting a new error with 3 repos. Here is an example repo.

Steps to reproduce

  1. Clone this repo: https://github.com/jasnow/show-me-the-food5edge.git
  2. Run "rake" and it will cleanly:
Finished in 0.95708 seconds (files took 3.19 seconds to load)
1 example, 0 failures
  1. Run "bundle update" to get latest edge rails code.
  2. Run "rake" and get WrongScopeError exception. See details:
    https://gist.github.com/jasnow/2edc53d905d26870bb2e77221c71ab29
  3. This error did not occur on 11/22/2019.

Expected behavior

Expect "rake" to run with no errors/exceptions. See step 2 above.

Actual behavior

See step 4 above.

System configuration

Rails version: 6.1.0.alpha

Ruby version: ruby 2.7.0preview2 (2019-10-22 master 02aadf1032) [x86_64-darwin16]

@geetfun
Copy link

geetfun commented Nov 27, 2019

Last working commit: 3f14733

Temporary workaround if you must use edge rails and rspec:

  • Add to your test group in your Gemfile: gem 'database_cleaner', '~> 1.7'
  • Modify your rails_helper.rb and add:
  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:truncation)
  end

  config.around(:each) do |example|
    DatabaseCleaner.cleaning do
      example.run
    end
  end
  • Comment out:

config.fixture_path = "#{::Rails.root}/spec/fixtures" and config.use_transactional_fixtures = true in rails_helper.rb

I'm not well versed enough on rspec's or the rails test framework internal workings to diagnose this further, but this seemed to have helped in the interim for me.

@jasnow
Copy link
Author

jasnow commented Nov 29, 2019

@Edouard-chin - This appears to be your commit that introduced the "name" variable that is mentioned in this issue's gist. d4367eb I would appreciate it if you would check this out. Thanks.

@Edouard-chin
Copy link
Member

ACK, let me think of a way to fix it. Didn't know RSpec used method_name :(

@jasnow
Copy link
Author

jasnow commented Nov 29, 2019

@Edouard-chin - Rspec might be using "name" as a variable.

@Edouard-chin
Copy link
Member

Attempted a fix in rspec-rails rspec/rspec-rails#2215 as I don't think the fix should be in Rails itself.

@jasnow
Copy link
Author

jasnow commented Dec 2, 2019

@Edouard-chin - Thanks for following up on this issue.

@eugeneius
Copy link
Member

This has been addressed in rspec/rspec-rails#2215.

alexcameron89 added a commit to alexcameron89/awesome-controller that referenced this issue Apr 20, 2020
Related errors below.

== Test WrongScopeError

Error:
```
Failures:

  1) Posts API (Custom Controller) GET /posts returns a list of posts
     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)."

       `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).
     # /Users/alexkitchens/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:742:in `method_missing'
     # /Users/alexkitchens/fun/journey/dependencies/rails/actionpack/lib/action_dispatch/testing/assertions/routing.rb:188:in `method_missing'
     # /Users/alexkitchens/fun/journey/dependencies/rails/actionpack/lib/action_dispatch/testing/integration.rb:422:in `method_missing'
     # /Users/alexkitchens/fun/journey/dependencies/rails/activerecord/lib/active_record/test_fixtures.rb:101:in `run_in_transaction?'
     # /Users/alexkitchens/fun/journey/dependencies/rails/activerecord/lib/active_record/test_fixtures.rb:115:in `setup_fixtures'
     # /Users/alexkitchens/fun/journey/dependencies/rails/activerecord/lib/active_record/test_fixtures.rb:8:in `before_setup'
     # /Users/alexkitchens/fun/journey/dependencies/rails/actionpack/lib/action_dispatch/testing/integration.rb:331:in `before_setup'
     # /Users/alexkitchens/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rspec-rails-3.8.2/lib/rspec/rails/adapters.rb:126:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
     # /Users/alexkitchens/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:447:in `instance_exec'
     # /Users/alexkitchens/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:447:in `instance_exec'
     # /Users/alexkitchens/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:373:in `execute_with'
     #
     #   Showing full backtrace because every line was filtered out.
     #   See docs for RSpec::Configuration#backtrace_exclusion_patterns and
     #   RSpec::Configuration#backtrace_inclusion_patterns for more information.
```

Bisect led to d4367eb72601f6e5bba3206443e9d141e9753af8

Issue opened here: rails/rails#37783
Fix in Rspec Rails here: rspec/rspec-rails#2215
The fix is not in a full release yet, so I've pinned to the latest beta release.

```
commit d4367eb72601f6e5bba3206443e9d141e9753af8
Author: Edouard CHIN <edouard.chin@shopify.com>
Date:   Thu Nov 21 18:39:54 2019 +0100

    Modify ActiveRecord::TestFixtures to not rely on AS::TestCase:

    - ### Problem

      If one wants to use ActiveRecord::TestFixtures it is mandatory for
      the test suite to inherit from `ActiveSupport::TestCase`.
      TestFixtures makes use of specific method from AS::TestCase
      (`file_fixture_path` and `method_name`).

      ### Solution

      This PR fixes that by not making use of method_name and file_fixture_path.
```

== Time Issue

Error:
```
Failure/Error: require File.expand_path('../../config/environment', __FILE__)

NoMethodError:
  undefined method `hour' for 1:Integer
Run options: include {:locations=>{"./spec/requests/api/posts_spec.rb"=>[10]}}
```

Bisect led to commit 12959dee0f19a8e050dd1236b031c2c690729905

Issue open at rails/rails#37391
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants