Skip to content

Commit

Permalink
Merge pull request #2686 from rspec/allow-locals-for-default-render
Browse files Browse the repository at this point in the history
Allow view specs to use implicit `render locals: {...}` calls.
  • Loading branch information
JonRowe committed Jun 28, 2023
2 parents a9ae00b + 8e94043 commit 5ca2b8e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions features/view_specs/view_spec.feature
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,28 @@ Feature: View specs
When I run `rspec spec/views`
Then the examples should all pass

Scenario: View specs can render a template with locals
Given a file named "spec/views/widgets/_widget.html.erb_spec.rb" with:
"""ruby
require "rails_helper"
RSpec.describe "widgets/index" do
it "displays the widget" do
widget = Widget.create!(:name => "slicer")
render :locals => {:widget => widget}
expect(rendered).to match /slicer/
end
end
"""
And a file named "app/views/widgets/index.html.erb" with:
"""
<h3><%= widget.name %></h3>
"""
When I run `rspec spec/views`
Then the examples should all pass

Scenario: View specs can render locals in a partial
Given a file named "spec/views/widgets/_widget.html.erb_spec.rb" with:
"""ruby
Expand Down
1 change: 1 addition & 0 deletions lib/rspec/rails/example/view_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module ExampleMethods
# end
def render(options = {}, local_assigns = {}, &block)
options = _default_render_options if Hash === options && options.empty?
options = options.merge(_default_render_options) if Hash === options && options.keys == [:locals]
super(options, local_assigns, &block)
end

Expand Down

0 comments on commit 5ca2b8e

Please sign in to comment.