-
-
Notifications
You must be signed in to change notification settings - Fork 910
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
Fix exception raised by ActiveSupport Object#in? #1405
Fix exception raised by ActiveSupport Object#in? #1405
Conversation
Oops, it seems that the command that I used to run the migration in this new acceptance test is not working when the Rails version is below 5_2. I'll take a look at that ASAP. |
6b08b2a
to
158f6d5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, nice job figuring this out! Aside from the test-related thing you noticed, I just had two suggestions.
write_file 'spec/spec_helper.rb', <<-FILE | ||
require 'shoulda/matchers' | ||
|
||
RSpec.configure do |config| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like if people are wanting to integrate with ActiveRecord, that we should support/document using Shoulda::Matchers.configure
(which will add include
s for the right libraries) to set this up. What do you think about changing this to:
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.library :active_record
with.test_framework :rspec
end
end
Alternatively, when you call add_shoulda_matchers_to_project
you can specify the configuration which will add the Shoulda::Matchers.configure
line automatically, so what do you think about:
add_shoulda_matchers_to_project(
libraries: [:active_record]
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
I tried to make it work with the second option, but the problem is that the shoulda matches configuration is being added to the rails_helper.rb
instead of spec_helper.rb
.
I think I found the problem, but I'm not sure how to fix it. I'll keep trying.
FWIW, the problem is that is finding rspec-rails
in the Gemfile because it's checking on the wrong Gemfile - gemfiles/rails_6_0.
shoulda-matchers/spec/support/acceptance/adds_shoulda_matchers_to_project.rb
Lines 101 to 108 in bf850fa
if integrates_with_rspec?(test_framework) | |
files << | |
if bundle.includes?('rspec-rails') | |
'spec/rails_helper.rb' | |
else | |
'spec/spec_helper.rb' | |
end | |
end |
Values obtained in the file above using pry-byebug:
[1] pry(#<AcceptanceTests::AddsShouldaMatchersToProject>)> bundle
=> #<Tests::Bundle:0x0000555b8b6bf800 @already_updating=false, @fs=#<Tests::Filesystem:0x0000555b8b6bf7d8>>
[2] pry(#<AcceptanceTests::AddsShouldaMatchersToProject>)> bundle.includes?('rspec-rails')
=> true
[3] pry(#<AcceptanceTests::AddsShouldaMatchersToProject>)> ENV['BUNDLE_GEMFILE']
=> "<path-to>/shoulda-matchers/gemfiles/rails_6_0.gemfile"
[4] pry(#<AcceptanceTests::AddsShouldaMatchersToProject>)>
Correct me if I'm wrong, please, does the value of BUNDLE_GEMFILE need to be equal to / tmp / shoulda-matchers-accept / test-project / Gemfile
at that point in the code, or not?
EDIT: I tried to change the environment variable, but it did not work. I'll keep looking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a "normal" app, yes, it would make sense for BUNDLE_GEMFILE to be the same as the application's Gemfile. For the tests we do a sort of hack where we force it to be the Appraisal gemfile instead. The reason we do that is because we want the Appraisal to dictate the list of gems that are loaded, as that is something we can control. As far as how BUNDLE_GEMFILE gets set, that comes from Appraisal. The 6.0 gemfile is the default because that's the latest one, but you You can override the Gemfile being used by using the appraisal
command:
bundle exec appraisal rails_5_2 rspec ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get it. Thanks!
I am thinking of using the first approach you suggested. I couldn't get it to work with the second.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's fine to use the first option! I didn't realize it only added to rails_helper
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Merging!
158f6d5
to
183ac64
Compare
Closes #1291
Thanks for this comment on the PR #1291, @mcmire! Helped a lot.