Skip to content

Commit 5ca2b8e

Browse files
authored
Merge pull request #2686 from rspec/allow-locals-for-default-render
Allow view specs to use implicit `render locals: {...}` calls.
2 parents a9ae00b + 8e94043 commit 5ca2b8e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

features/view_specs/view_spec.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,28 @@ Feature: View specs
153153
When I run `rspec spec/views`
154154
Then the examples should all pass
155155

156+
Scenario: View specs can render a template with locals
157+
Given a file named "spec/views/widgets/_widget.html.erb_spec.rb" with:
158+
"""ruby
159+
require "rails_helper"
160+
161+
RSpec.describe "widgets/index" do
162+
it "displays the widget" do
163+
widget = Widget.create!(:name => "slicer")
164+
165+
render :locals => {:widget => widget}
166+
167+
expect(rendered).to match /slicer/
168+
end
169+
end
170+
"""
171+
And a file named "app/views/widgets/index.html.erb" with:
172+
"""
173+
<h3><%= widget.name %></h3>
174+
"""
175+
When I run `rspec spec/views`
176+
Then the examples should all pass
177+
156178
Scenario: View specs can render locals in a partial
157179
Given a file named "spec/views/widgets/_widget.html.erb_spec.rb" with:
158180
"""ruby

lib/rspec/rails/example/view_example_group.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module ExampleMethods
6565
# end
6666
def render(options = {}, local_assigns = {}, &block)
6767
options = _default_render_options if Hash === options && options.empty?
68+
options = options.merge(_default_render_options) if Hash === options && options.keys == [:locals]
6869
super(options, local_assigns, &block)
6970
end
7071

0 commit comments

Comments
 (0)