-
-
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
Bug when using to_s
as a subject name
#2478
Comments
Your example spec doesn't actually use Subjects however, are methods, |
That's the thing. From my understanding If you look at the sample spec I added, if you change the name of the subject to |
@JonRowe Here is an example screenshot of a See how If I change the subject name to |
We have a germinal concept of reserved memoized helper variable names here https://github.com/rspec/rspec-core/blob/ea8554afd1a2b63677c6593059fa8f2476181deb/lib/rspec/core/memoized_helpers.rb#L311 I suggest extending the list from just What's being left out is the check for names passed as RSpec.describe 'A' do
let('initialize') { 1 }
it { expect(initialize).to eq(1) }
end does not result in a sensible error,
but rather
Would you like to fix those two problems with a small PR, @corroded ?
|
I think this is solved pretty well by just adding a nice error message about reserved names. The main problem is how difficult it is to debug, and an error message will make it easy. |
What Ruby, Rails and RSpec versions are you using?
Ruby version: 2.6.6
Rails version: 6.0.3.5
RSpec version: 3.10.1
Observed behaviour
We have dependabot and the recent upgrade failed some of our specs. Particularly specs that specifically test the method
to_s
on an object. An example:AR Object
Spec
Expected behaviour
The expected behaviour is for the spec to pass seeing it's very simple. This spec fails with the new code because
name
is blank in the beginning and is somehow being memoised already.Can you provide an example app?
The above already shows the example. Further more, we already have an idea on what the bug is but not sure how to fix it.
This is the specific commit that breaks it: https://github.com/rspec/rspec-rails/pull/2461/files
More specifically this change:
The issue is when the
subject
is namedto_s
(as insubject(:to_s) { something.to_s }
),uses_transaction
somehow uses the actual active record object - instead of the RSpec example.This is the "offending line": https://github.com/rails/rails/blob/df41acdad93783dcac49f03036c3f34cb1c6c667/activerecord/lib/active_record/test_fixtures.rb#L96
I have added an example spec to the existing spec for name collision - I think it's related there. Here is the sample:
main...corroded:main
Final note
You don't actually need to inherit from AR for this to happen - but you do need to have included
include ActiveRecord::TestFixtures
since it's that method that is the problem. Not sure if it's an rspec-rails issue or a bug with active-record fixtures (or both!)The text was updated successfully, but these errors were encountered: