File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,21 @@ def self.nullify_template_rendering(templates)
61
61
end
62
62
end
63
63
64
+ # @private
65
+ class LogSubscriber < ::ActiveSupport ::LogSubscriber
66
+ def current_example_group
67
+ RSpec . current_example . example_group
68
+ end
69
+
70
+ def render_template ( event )
71
+ unless current_example_group . render_views?
72
+ info " Template rendering was prevented by rspec-rails. Use `render_views` to verify rendered view contents if necessary."
73
+ end
74
+ end
75
+ end
76
+
77
+ LogSubscriber . attach_to :action_view
78
+
64
79
# Delegates all methods to the submitted resolver and for all methods
65
80
# that return a collection of `ActionView::Template` instances, return
66
81
# templates with modified source
Original file line number Diff line number Diff line change @@ -47,6 +47,14 @@ def example.controller
47
47
group . render_views true
48
48
expect ( group . new . render_views? ) . to be_truthy
49
49
end
50
+
51
+ it "does not log a message that rendering was prevented" do
52
+ subscriber = RSpec ::Rails ::ViewRendering ::EmptyTemplateResolver ::LogSubscriber . new
53
+ allow ( subscriber ) . to receive ( :current_example_group ) . and_return group
54
+ expect ( subscriber ) . to_not receive ( :info )
55
+ group . render_views true
56
+ subscriber . render_template ( nil )
57
+ end
50
58
end
51
59
52
60
context "with false" do
@@ -60,6 +68,14 @@ def example.controller
60
68
group . render_views false
61
69
expect ( group . new . render_views? ) . to be_falsey
62
70
end
71
+
72
+ it "logs a message that rendering was prevented" do
73
+ subscriber = RSpec ::Rails ::ViewRendering ::EmptyTemplateResolver ::LogSubscriber . new
74
+ allow ( subscriber ) . to receive ( :current_example_group ) . and_return group
75
+ expect ( subscriber ) . to receive ( :info ) . with /render_views/
76
+ group . render_views false
77
+ subscriber . render_template ( nil )
78
+ end
63
79
end
64
80
65
81
it 'propogates to examples in nested groups properly' do
You can’t perform that action at this time.
0 commit comments