Jezen Thomas
Jezen Thomas

Reputation: 13800

View specs have no render method

I’m trying to write some view specs that test some template logic. I’m following the instructions in the RSpec book, and also checking other online references. I don’t seem to have access to render or assign.

require "spec_helper"

describe "projects/index.html.erb" do

  it "displays an entry for each project" do
    projects = 5.times { FactoryGirl.create :project }
    render
    expect(all(".project-index-entry").count).to eq 5
  end

end

When I run the above, I get:

 Failure/Error: render
 NameError:
   undefined local variable or method `render' for #<RSpec::ExampleGroups::ProjectsIndexHtmlErb:0x007fa2950d4140>
 # ./spec/views/projects/index.html.erb_spec.rb:7:in `block (2 levels) in <top (required)>'

The same thing happens if I try to use assign. I know I could use visit, but then I would have to simulate the act of the user signing in before each spec. I may be misunderstood, but I think the render method is meant to be more isolated, allowing me to skip the authentication check I have in the controller.

So, why don’t I have the view spec methods I was expecting?

Versions:
 - capybara 2.4.1
 - rails 4.1.0
 - rspec-core 3.1.3
 - rspec-expectations 3.1.1
 - rspec-mocks 3.1.0
 - rspec-rails 3.1.0

Upvotes: 0

Views: 131

Answers (1)

Jezen Thomas
Jezen Thomas

Reputation: 13800

As it turns out, I updated rspec some time ago and the previous version used a significantly different spec_helper. After the update, the logic was split into spec_helper and rails_helper, so to fix this problem I had to rerun rails generate rspec:install.

Upvotes: 1

Related Questions