-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix noisy log error #1831
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 noisy log error #1831
Conversation
We've been seeing this error in our test logs: Could not log "render_template.action_view" event. NoMethodError: undefined method `example_group' for nil:NilClass .../rspec-rails-3.6.0/lib/rspec/rails/view_rendering.rb:67:in `current_example_group' .../rspec-rails-3.6.0/lib/rspec/rails/view_rendering.rb:71:in `render_template' ... This is while running an rspec rails feature spec using capybara, so this is a separate thread running webrick. This was also during a before block. In any case, this should probably fail gracefully when there is no example. While updating this code I got an "ExampleGroup doesn't respond to render_views?", so built in that case too.
Thank you for the patch!
I'm a little confused as to what expected behaviour is here. With your change, it will log the "views not rendered" message, but seems like that would be just as confusing in your use case? |
This is related to #1800, but doesn't link to it. Now it does. |
@xaviershay Sorry, I think this might be tricky with some double negatives! With this change in my case it no longer logs a stack trace, and does not log the "views not rendered" message because it returns early because the example is nil so This is correct in my case. I'm running a feature spec which does indeed render views, hooked up to capybara and poltergeist. I inverted the name and logic of that method so that it describes whether the noteworthy behavior change is in effect, allowing us to shortcut an answer in the cases where an example or group etc is missing, or is not configured for view suppression at all. That may have made it more confusing! I also didn't want to rock the boat and change this too much, or try mocking especially internals in a way which might interfere with running the test suite itself, either. But we could try this if it wouldn't be a problem and would illustrate and exercise the cases better? |
oh yes you are right, I mis-read it :) LGTM! |
As per #1827 I think this fix masks the problem (in the case of no |
@JonRowe yeah, it did seem like the global state was a bit fragile, but I didn't want to rock the boat too much. I did take a look, though. Afaict there's no So in lieu of that rabbit hole I opted for fixing the immediate error and leaving the caveats as-is. Perhaps there should be a follow up issue/PR? |
So I did look into this a little more. As an alternative we could just throw away the subscriber and instead log within the empty template renderer: sj26/rspec-rails@fix-log-subscriber-outside-current-example...sj26:or-just-log-it-here I have no idea how to test this in the current rspec-rails test suite. The current template renderer has no unit tests in the spec suite, it all seems integration tested with Cucumber. It would be easiest with a verifying proxy or something in these integration tests, but I don't want to litter the nice clean relish docs with logger mocks. Or if there were a step for asserting log output? Not sure. |
I'd be ok with that solution, we don't test this log currently as far as I can tell so I'm unsure what to do about that. |
I've pulled that commit onto this branch. I've verified manually that this behaves as expected by running an example from the cucumber suite and then removing the "render_views" and ran it again and made sure the logs worked as expected: There are no tests for the log output at the moment and again I'm not sure how to add them. Maybe this is enough? |
Thanks @sj26 I'm happy with it as is, if this solves the problem and doesn't fail the build its better in my eyes. |
Thanks @JonRowe, @xaviershay! |
We have this problem in our suite. I was wondering - is there a way I can use this commit without having to monkey patch our codebase? I tried adding rspec-rails to our Gemfile specifying this ref (ac759a3) but I see the error
I'm not too familiar with the rspec ecosystem versioning policy, but is there any chance this PR could be released as a 3.6 maintenance release? eg 3.6.1 Thanks! |
In the mean time if you add |
@JonRowe OK I see - thank you. |
@JonRowe Is there any reason not to release a patch version for this? |
It's too minor to release on its own so no ones had time to do it, happy
for you to do it if you have the time Yuji
|
@JonRowe I think this issue is not so minor, since the noisy errors really annoy users when checking the log (actually I'm experiencing it). Could you give me the release permission on rubygems? |
@yujinakayama This would be fantastic if you have time to do a patch release. As another data point, in our case it has caused the log file to go from 6MB to 96MB for the test tranche I was looking at. We have about 40 test tranches per build, although I'm not sure if they are all affected as severely. |
@yujinakayama you should be able to release it now |
* Fix noisy log error We've been seeing this error in our test logs: Could not log "render_template.action_view" event. NoMethodError: undefined method `example_group' for nil:NilClass .../rspec-rails-3.6.0/lib/rspec/rails/view_rendering.rb:67:in `current_example_group' .../rspec-rails-3.6.0/lib/rspec/rails/view_rendering.rb:71:in `render_template' ... This is while running an rspec rails feature spec using capybara, so this is a separate thread running webrick. This was also during a before block. In any case, this should probably fail gracefully when there is no example. While updating this code I got an "ExampleGroup doesn't respond to render_views?", so built in that case too. * Throw away the LogSubscriber and just log explicitly
The problem with trying to use |
@ianks Hey - there is now a 3.6 maintenance branch (https://github.com/rspec/rspec-rails/tree/3-6-maintenance) you can reference in your gemfile which includes this fix, but doesn't depend on |
I've just released rspec-rails 3.6.1 👍 |
* Fix noisy log error We've been seeing this error in our test logs: Could not log "render_template.action_view" event. NoMethodError: undefined method `example_group' for nil:NilClass .../rspec-rails-3.6.0/lib/rspec/rails/view_rendering.rb:67:in `current_example_group' .../rspec-rails-3.6.0/lib/rspec/rails/view_rendering.rb:71:in `render_template' ... This is while running an rspec rails feature spec using capybara, so this is a separate thread running webrick. This was also during a before block. In any case, this should probably fail gracefully when there is no example. While updating this code I got an "ExampleGroup doesn't respond to render_views?", so built in that case too. * Throw away the LogSubscriber and just log explicitly
We've been seeing this error in our test logs:
This is while running an rspec rails feature spec using capybara, so this is a separate thread running webrick. This was also during a before block. In any case, this should probably fail gracefully when there is no example.
While updating this code I got an "ExampleGroup doesn't respond to render_views?", so built in that case too.