-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Warn on context fixture helper #1442
Comments
Reproduction case is put a file called require 'rails_helper'
RSpec.describe Widget, type: :model do
fixtures :widgets
describe 'fixture loaded in a before context' do
before :context do
widgets :a
end
it 'works' do
end
end
end |
@cupakromer I have a sketch of a fix for this. I'm going to clean it up a little and PR it tomorrow. |
fables-tales
pushed a commit
that referenced
this issue
Dec 8, 2015
Fixes #1442. The basic approach here is to capture the addition of the fixture methods to the example group instance and then monkeypatch them. The monkeypatch checks to see if we're currently in a before(:context) hook and if we are then it prints a warning and doesn't invoke the method. The warning here is a little sparse at the moment, and I'd like to make it more clear. One thing that's a little gross about this implementation is that it uses the inspect string of the example group to determine if we're in a before(:context) hook. As far as I can tell there isn't a better way to make that determination, but maybe someone's got a clever trick.
fables-tales
pushed a commit
that referenced
this issue
Dec 10, 2015
Fixes #1442. The basic approach here is to capture the addition of the fixture methods to the example group instance and then monkeypatch them. The monkeypatch checks to see if we're currently in a before(:context) hook and if we are then it prints a warning and doesn't invoke the method. The warning here is a little sparse at the moment, and I'd like to make it more clear. One thing that's a little gross about this implementation is that it uses the inspect string of the example group to determine if we're in a before(:context) hook. As far as I can tell there isn't a better way to make that determination, but maybe someone's got a clever trick.
fables-tales
pushed a commit
that referenced
this issue
Dec 14, 2015
Fixes #1442. The basic approach here is to capture the addition of the fixture methods to the example group instance and then monkeypatch them. The monkeypatch checks to see if we're currently in a before(:context) hook and if we are then it prints a warning and doesn't invoke the method. The warning here is a little sparse at the moment, and I'd like to make it more clear. One thing that's a little gross about this implementation is that it uses the inspect string of the example group to determine if we're in a before(:context) hook. As far as I can tell there isn't a better way to make that determination, but maybe someone's got a clever trick.
fables-tales
pushed a commit
that referenced
this issue
Dec 15, 2015
Fixes #1442. The basic approach here is to capture the addition of the fixture methods to the example group instance and then monkeypatch them. The monkeypatch checks to see if we're currently in a before(:context) hook and if we are then it prints a warning and doesn't invoke the method. The warning here is a little sparse at the moment, and I'd like to make it more clear. One thing that's a little gross about this implementation is that it uses the inspect string of the example group to determine if we're in a before(:context) hook. As far as I can tell there isn't a better way to make that determination, but maybe someone's got a clever trick.
sebjacobs
pushed a commit
to futurelearn/rspec-rails
that referenced
this issue
Mar 15, 2019
Fixes rspec#1442. The basic approach here is to capture the addition of the fixture methods to the example group instance and then monkeypatch them. The monkeypatch checks to see if we're currently in a before(:context) hook and if we are then it prints a warning and doesn't invoke the method. The warning here is a little sparse at the moment, and I'd like to make it more clear. One thing that's a little gross about this implementation is that it uses the inspect string of the example group to determine if we're in a before(:context) hook. As far as I can tell there isn't a better way to make that determination, but maybe someone's got a clever trick.
sebjacobs
pushed a commit
to futurelearn/rspec-rails
that referenced
this issue
Mar 15, 2019
Closes rspec#1442 [ci skip]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixtures are controlled by the underlying
ActiveRecord::TestFixtures
code. Which sets up fixtures before each example. While the database may have fixture data in it before this point, that data will be reset once the test fixture code runs.When the
fixtures
message is sent in an example group, or global fixtures are defined, the Active Record test fixtures register the accessors in an anonymous module. That module is included in the example group's ancestors.Which means the accessor helpers are available in any example group instance; thus they are available in
before(:context)
andafter(:context)
. However, the internal fixture setup and cache has not been performed yet. Attempting to call a fixture helper prior to the fixtures being setup, raises an undefined method onNilClass
error.Related: #1201 and #1208
The text was updated successfully, but these errors were encountered: