Skip to content
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

Allow view specs to use implicit render locals: {...} calls. #2686

Merged
merged 1 commit into from Jun 28, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions features/view_specs/view_spec.feature
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
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