Skip to content

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

Merged
merged 2 commits into from
Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions lib/rspec/rails/view_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,6 @@ def self.nullify_template_rendering(templates)
end
end

# @private
class LogSubscriber < ::ActiveSupport::LogSubscriber
def current_example_group
RSpec.current_example.example_group
end

def render_template(_event)
return if current_example_group.render_views?
info(" Template rendering was prevented by rspec-rails. Use `render_views` to verify rendered view contents if necessary.")
end
end

LogSubscriber.attach_to(:action_view)

# Delegates all methods to the submitted resolver and for all methods
# that return a collection of `ActionView::Template` instances, return
# templates with modified source
Expand Down Expand Up @@ -117,6 +103,8 @@ def find_templates(*args)
# @private
class EmptyTemplateHandler
def self.call(_template)
::Rails.logger.info(" Template rendering was prevented by rspec-rails. Use `render_views` to verify rendered view contents if necessary.")

%("")
end
end
Expand Down
16 changes: 0 additions & 16 deletions spec/rspec/rails/view_rendering_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ def example.controller
group.render_views true
expect(group.new.render_views?).to be_truthy
end

it "does not log a message that rendering was prevented" do
subscriber = RSpec::Rails::ViewRendering::EmptyTemplateResolver::LogSubscriber.new
allow(subscriber).to receive(:current_example_group).and_return group
expect(subscriber).to_not receive(:info)
group.render_views true
subscriber.render_template(nil)
end
end

context "with false" do
Expand All @@ -68,14 +60,6 @@ def example.controller
group.render_views false
expect(group.new.render_views?).to be_falsey
end

it "logs a message that rendering was prevented" do
subscriber = RSpec::Rails::ViewRendering::EmptyTemplateResolver::LogSubscriber.new
allow(subscriber).to receive(:current_example_group).and_return group
expect(subscriber).to receive(:info).with /render_views/
group.render_views false
subscriber.render_template(nil)
end
end

it 'propogates to examples in nested groups properly' do
Expand Down