-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Log a message when view rendering is intercepted #1732
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
Conversation
8f20e94
to
ee0cb7d
Compare
|
||
def render_template(event) | ||
unless current_example_group.render_views? | ||
info " Template rendering was prevented by rspec-rails. Use `render_views` to verify rendered view contents if necessary." |
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 add parentheses here?
end | ||
end | ||
|
||
LogSubscriber.attach_to :action_view |
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.
Also could you add parentheses here?
end | ||
|
||
def render_template(event) | ||
unless current_example_group.render_views? |
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.
Our rubocop configuration would like you to change this to
return if current_example.render_views?
and then flatten the conditional. Could you do that?
RSpec.current_example.example_group | ||
end | ||
|
||
def render_template(event) |
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.
Can you change this to _event
to pass the rubocop review?
@andymorris thanks for submitting this! Looks like a good solution to the problem. I've left you some review comments, if you address those, I'd love to merge this in ✨ |
ee0cb7d
to
938095a
Compare
Changes made, and rubocop no longer shows any issues. Let me know if there is anything else. |
LGTM |
This is an attempt at #1332, to clarify test logs when view rendering is prevented. Without calling
render_views
, logs currently look something like:...even though the template was not actually rendered. With this change the logs look like:
I struggled a little bit with how to write the specs for this. The LogSubscriber is attached and created independent of any examples/groups, but still needs to know the current example group's
render_views?
to decide whether or not to log the message, though whenrspec-rails
specs are running the current example is in therspec-rails
suite and not a controller spec. I'd be happy to take a different approach if someone points me in the right direction.