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

Look in rails helper for factory girl syntax methods. #118

Merged
merged 2 commits into from
Apr 29, 2015

Conversation

imtayadeway
Copy link
Contributor

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.

#117

(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))))))
Copy link
Collaborator

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.

@imtayadeway
Copy link
Contributor Author

@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)
Copy link
Collaborator

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-bind default-directory there instead.

@imtayadeway
Copy link
Contributor Author

@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 include is found but commented out, but I don't know if addressing that is in the scope of this PR. Any thoughts?

@dgutov
Copy link
Collaborator

dgutov commented Apr 28, 2015

I wouldn't mind it being in this PR.

Here's a snippet to check if you're in a comment: (nth 4 (syntax-ppss))

@dgutov
Copy link
Collaborator

dgutov commented Apr 29, 2015

Oh, and you'd need to enter ruby-mode before that.

@imtayadeway
Copy link
Contributor Author

@dgutov thanks! that does the trick. let me know if i need to do anything else before squashing.

@dgutov
Copy link
Collaborator

dgutov commented Apr 29, 2015

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.
@imtayadeway
Copy link
Contributor Author

@dgutov done. thanks for your help!

dgutov added a commit that referenced this pull request Apr 29, 2015
Look in rails helper for factory girl syntax methods.
@dgutov dgutov merged commit 07d6e8f into pezra:master Apr 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants