-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Look in rails helper for factory girl syntax methods. #118
Conversation
(with-temp-buffer | ||
(insert-file-contents | ||
(expand-file-name "spec/spec_helper.rb" rspec-project-root)) | ||
(re-search-forward "include +FactoryGirl::Syntax::Methods" nil t)))))) |
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.
Could you try to avoid duplication here?
Maybe use cl-find-if
and a list with both filenames.
@dgutov just updated. i'm a little unfamiliar with the syntax here, so apologies if i've made any blunders! |
(with-temp-buffer | ||
(insert-file-contents path) | ||
(re-search-forward "include +FactoryGirl::Syntax::Methods" nil t)))) | ||
'((expand-file-name "spec/rails_helper.rb" rspec-project-root) |
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.
Have you tried running this? It won't work:
rspec-project-root
is a function, not a variable.- The quote before the list will stop the elements from being evaluated (so they're strings, not forms). Instead of rectifying that, though, it will be better to move the
expand-file-name
call inside the lambda too (with a let-binding). Or let-binddefault-directory
there instead.
@dgutov thanks for your feedback. I've just updated and confirmed that it did work as expected with the rails_helper. One thing I did notice is that this function will wrongly return truthy if the |
I wouldn't mind it being in this PR. Here's a snippet to check if you're in a comment: |
Oh, and you'd need to enter |
@dgutov thanks! that does the trick. let me know if i need to do anything else before squashing. |
Looks good to me, thanks! |
More recent versions of rspec-rails create/recommend creating both a `rails_helper.rb` and `spec_helper.rb` file, with the intention of putting rails-specific configuration in the former. Given that a rails project is set up in this way, including the syntax methods for factory girl would be expected to go into the rails helper. This change looks in the rails helper if it exists first before searching the spec helper for the inclusion of this module. pezra#117
In the case that 'include FactoryGirl::Syntax::Methods' can be found in the rails/spec helper, it will now check to ensure that it is not commented out.
01c6e2c
to
be9646a
Compare
@dgutov done. thanks for your help! |
Look in rails helper for factory girl syntax methods.
More recent versions of rspec-rails create/recommend creating both a
rails_helper.rb
andspec_helper.rb
file, with the intention ofputting rails-specific configuration in the former. Given that a rails
project is set up in this way, including the syntax methods for factory
girl would be expected to go into the rails helper.
This change looks in the rails helper if it exists first before
searching the spec helper for the inclusion of this module.
#117