Rspec 3 Views Spec Undefined Local Variable or Method Render

ruby

If you’re using rspec 3, you might run into the following error when you try to run a views spec with the rake spec command:

1
2
3
Failure/Error: render
NameError:
  undefined local variable or method 'render' for #<RSpec::ExampleGroups::ViewNameHere>

If so, try two things: first, make sure that your spec has require 'rails_helper', not require 'spec_helper'. Additionally, make sure you specify type: :view in the RSpec definition, e.g. RSpec.describe 'view.html.erb', type: :view do.


I'm looking for better ways to build software businesses. Find out if I find something.