Skip to content

render_views is not working in latest #932

Closed
justin808 opened this Issue Feb 16, 2014 · 39 comments

10 participants

@justin808

I just synched up with the latest versions and I get this message

undefined local variable or method `render_views

Any advice?

rspec spec/controllers/registrations_controller_spec.rb                                                                                                                                                                     ✹ ✚ [16:22:06]
Loading environment test
WARNING: VCR's FakeWeb integration is deprecated and will be removed in VCR 3.0.
/Users/justin/j/blink/bpos/spec/controllers/registrations_controller_spec.rb:5:in `block in <top (required)>': undefined local variable or method `render_views' for RSpec::ExampleGroups::UsersRegistrationsController:Class (NameError)
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta1/lib/rspec/core/example_group.rb:253:in `module_eval'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta1/lib/rspec/core/example_group.rb:253:in `subclass'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta1/lib/rspec/core/example_group.rb:239:in `describe'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta1/lib/rspec/core/dsl.rb:18:in `describe'
    from /Users/justin/j/blink/bpos/spec/controllers/registrations_controller_spec.rb:4:in `<top (required)>'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `block in load'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta1/lib/rspec/core/configuration.rb:886:in `block in load_spec_files'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta1/lib/rspec/core/configuration.rb:886:in `each'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta1/lib/rspec/core/configuration.rb:886:in `load_spec_files'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta1/lib/rspec/core/command_line.rb:22:in `run'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta1/lib/rspec/core/runner.rb:90:in `run'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta1/lib/rspec/core/runner.rb:17:in `block in autorun'

gem versions:

    rspec (3.0.0.beta1)
      rspec-core (= 3.0.0.beta1)
      rspec-expectations (= 3.0.0.beta1)
      rspec-mocks (= 3.0.0.beta1)
    rspec-collection_matchers (0.0.2)
      rspec-expectations (>= 2.99.0.beta1)
    rspec-core (3.0.0.beta1)
      rspec-support (= 3.0.0.beta1)
    rspec-expectations (3.0.0.beta1)
      diff-lcs (>= 1.1.3, < 2.0)
      rspec-support (= 3.0.0.beta1)
    rspec-instafail (0.2.4)
    rspec-its (1.0.0)
      rspec-core (>= 2.99.0.beta1)
      rspec-expectations (>= 2.99.0.beta1)
    rspec-mocks (3.0.0.beta1)
      rspec-support (= 3.0.0.beta1)
    rspec-rails (3.0.0.beta1)
      actionpack (>= 3.0)
      activemodel (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-collection_matchers
      rspec-core (= 3.0.0.beta1)
      rspec-expectations (= 3.0.0.beta1)
      rspec-mocks (= 3.0.0.beta1)
    rspec-retry (0.2.1)
      rspec
    rspec-support (3.0.0.beta1)
@thomas-holmes
RSpec member

What version were you using before and where within the tests are you trying to call the method render_views?

@justin808

Here are the old versions that worked:

   rspec (2.14.1)
      rspec-core (~> 2.14.0)
      rspec-expectations (~> 2.14.0)
      rspec-mocks (~> 2.14.0)
    rspec-core (2.14.7)
    rspec-expectations (2.14.4)
      diff-lcs (>= 1.1.3, < 2.0)
    rspec-instafail (0.2.4)
    rspec-mocks (2.14.4)
    rspec-rails (2.14.0)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-core (~> 2.14.0)
      rspec-expectations (~> 2.14.0)
      rspec-mocks (~> 2.14.0)
    rspec-retry (0.2.1)
      rspec
@thomas-holmes
RSpec member

Could you please provide an snippet to show how you're invoking it?

@justin808
require 'spec_helper'
describe Users::RegistrationsController do
  render_views

  describe "GET 'new'" do
    before(:each) do
      @user = FactoryGirl.create(:user)
    end

    it "returns http success" do
      get :new
      expect(response).to be_success
    end
@JonRowe
RSpec member
JonRowe commented Feb 16, 2014
@justin808

I just followed the steps to upgrade from 2.1 by going to 2.99 and removing all deprecation warnings. 2.99 works fine. I still get the render_views issue in 3.0.0.beta

@samphippen
RSpec member

Hi @justin808. @alindeman and I tried to reproduce this and had a little trouble. Would you mind pushing a minimal rails app that demonstrates the issue?

@justin808

Any ideas of something in my spec_helper.rb that could cause this method to not be found? The app I'm working on is quite large, so it might be a little work to recreate this.

@JonRowe
RSpec member
JonRowe commented Feb 16, 2014

Run rails new, slowly add your spec helper and Gems until you recreate, it won't be an application level issue.

@justin808

The work around for the issue is to include this in the gemfile:

 gem 'rspec', "3.0.0.beta1"

One of these caused the issue:

group :test do
  gem 'rspec', "3.0.0.beta1"
  gem 'simplecov', require: false
  gem 'database_cleaner'
  gem 'turn', require: false
  gem "factory_girl_rails"
  gem 'launchy' # this lets us call save_and_open_page to see what's on a page for debugging capybara tests
  gem 'capybara'
  gem 'capybara-screenshot', github: 'parndt/capybara-screenshot', branch: 'fix-rspec-3-0-0-deprecation'
  gem "show_me_the_cookies"
  gem 'rspec-instafail'
  gem "shoulda-matchers"
  gem "poltergeist"
  gem 'rspec-retry', github: 'justin808/rspec-retry', branch: 'justin808-rspec-299'
  gem 'resque_spec', github: 'justin808/resque_spec', branch: 'fix-for-resque-heroku'
  gem 'vcr'
  gem 'fakeweb'
  gem 'zeus', "~> 0.13.4.pre2"
end
@justin808

Maybe rspec-rails can specify a min version of rspec?

@justin808

Turns out that this was not the issue. I'm using Zeus, so I was mistaken in that I thought changing the gemfile did the trick.

I've created a branch new rails 4 project and added everything in my gemfile and spec_helper.rb and support files.

Yet I can't reproduce the issue.

However, I put some tracing code where render_views is called and in the case of the crash, ActiveSupport is loading the rspec file, per the stack trace below. Maybe this is related to this:
guard/guard-rspec#229

In the case of the test passing, ActiveSupport is not in the stack trace. Any idea how to fix this? or what could cause this?

/Users/justin/j/blink/bpos/spec/controllers/images_controller_spec.rb:12:in `block in <top (required)>': undefined local variable or method `render_views' for RSpec::ExampleGroups::ImagesController_2:Class (NameError)
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/example_group.rb:323:in `module_eval'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/example_group.rb:323:in `subclass'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/example_group.rb:287:in `example_group'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/example_group.rb:169:in `block in alias_example_group_to'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/dsl.rb:40:in `block in expose_example_group_alias'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/dsl.rb:74:in `block (2 levels) in expose_example_group_alias_globally'
    from /Users/justin/j/blink/bpos/spec/controllers/images_controller_spec.rb:6:in `<top (required)>'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:223:in `load'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:223:in `block in load'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:214:in `load_dependency'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:223:in `load'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `block in load_spec_files'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `each'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `load_spec_files'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/command_line.rb:21:in `run'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/runner.rb:100:in `run'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/runner.rb:31:in `invoke'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/exe/rspec:4:in `<top (required)>'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/bin/rspec:23:in `load'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/bin/rspec:23:in `<main>'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/bin/ruby_executable_hooks:15:in `eval'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/bin/ruby_executable_hooks:15:in `<main>'
@JonRowe JonRowe closed this Feb 19, 2014
@JonRowe JonRowe reopened this Feb 19, 2014
@justin808

@JonRowe Any ideas on how I can debug this one? It's super odd. I downgraded back to 2.99 for now, but I'd really like to get to the bottom of this.

@JonRowe
RSpec member
JonRowe commented Feb 19, 2014

Have you tried running it without zeus. It looks like you have mismatched gems, but I'm not sure

@justin808

Yes, I removed zeus completely and that is how I got the trace above. With Zeus, zeus shows in the stack trace.

@justin808

I just updated and I still get the same error.

The problem is that the specs are loaded before rspec, and this only happens with rspec 3, and not 2.99.

/Users/justin/j/blink/bpos/spec/controllers/images_controller_spec.rb:7:in `block in <top (required)>': undefined local variable or method `render_views' for RSpec::ExampleGroups::ImagesController_2:Class (NameError)
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/example_group.rb:323:in `module_eval'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/example_group.rb:323:in `subclass'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/example_group.rb:287:in `example_group'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/example_group.rb:169:in `block in alias_example_group_to'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/dsl.rb:40:in `block in expose_example_group_alias'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/dsl.rb:74:in `block (2 levels) in expose_example_group_alias_globally'
    from /Users/justin/j/blink/bpos/spec/controllers/images_controller_spec.rb:6:in `<top (required)>'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/zeus-0.13.4.pre2/lib/zeus/load_tracking.rb:50:in `load'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/zeus-0.13.4.pre2/lib/zeus/load_tracking.rb:50:in `load'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/zeus-0.13.4.pre2/lib/zeus/load_tracking.rb:43:in `load'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:223:in `block in load'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:214:in `load_dependency'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:223:in `load'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:934:in `block in load_spec_files'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `each'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `load_spec_files'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/command_line.rb:21:in `run'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/runner.rb:100:in `run'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/lib/rspec/core/runner.rb:31:in `invoke'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/gems/rspec-core-3.0.0.beta2/exe/rspec:4:in `<top (required)>'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/bin/rspec:23:in `load'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/bin/rspec:23:in `<main>'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/bin/ruby_executable_hooks:15:in `eval'
    from /Users/justin/.rvm/gems/ruby-2.0.0-p353@rails4/bin/ruby_executable_hooks:15:in `<main>'
@JonRowe
RSpec member
JonRowe commented Mar 2, 2014

Can you try to reproduce this in a seperate repo? If a plain repo with your spec won't produce it, slowly add bits of your spec helper and gem file to it until it causes it.

@justin808

I tried with no luck. The problem is that something is requiring the specs. Any idea where I could look or how I could debug this?

@JonRowe
RSpec member
JonRowe commented Mar 2, 2014

Can you make sure gem "rspec-rails", "3.0.0.beta2" is in your Gemfile and in your :test group, I can't see it mentioned in the snippet above...

If it definitely is try adding :type => :controller into the describe statements metadata...

Other than that as I said, start with a fresh rails app, a very basic skeleton of the spec, then slowly add in your gems and spec_helper until you reproduce it...

@joelcdoyle

I have the same issues as justin808 with rails 4.1.0.rc1 and rspec 3.0.0beta2.

    /Users/joeldoyle/dev/revunit/everview-api/spec/controllers/api/v1/trusted_circle_relationships_controller_spec.rb:5:in `block in <top (required)>': undefined local variable or method `render_views' for RSpec::ExampleGroups::ApiV1TrustedCircleRelationshipsController:Class (NameError)
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-3.0.0.beta2/lib/rspec/core/example_group.rb:323:in `module_eval'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-3.0.0.beta2/lib/rspec/core/example_group.rb:323:in `subclass'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-3.0.0.beta2/lib/rspec/core/example_group.rb:287:in `example_group'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-3.0.0.beta2/lib/rspec/core/example_group.rb:169:in `block in alias_example_group_to'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-3.0.0.beta2/lib/rspec/core/dsl.rb:40:in `block in expose_example_group_alias'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-3.0.0.beta2/lib/rspec/core/dsl.rb:74:in `block (2 levels) in expose_example_group_alias_globally'
from /Users/joeldoyle/dev/revunit/everview-api/spec/controllers/api/v1/trusted_circle_relationships_controller_spec.rb:3:in `<top (required)>'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/bundler/gems/rails-fdcab84a13f9/activesupport/lib/active_support/dependencies.rb:241:in `load'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/bundler/gems/rails-fdcab84a13f9/activesupport/lib/active_support/dependencies.rb:241:in `block in load'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/bundler/gems/rails-fdcab84a13f9/activesupport/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/bundler/gems/rails-fdcab84a13f9/activesupport/lib/active_support/dependencies.rb:241:in `load'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `block in load_spec_files'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `each'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `load_spec_files'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-3.0.0.beta2/lib/rspec/core/command_line.rb:21:in `run'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-3.0.0.beta2/lib/rspec/core/runner.rb:100:in `run'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-3.0.0.beta2/lib/rspec/core/runner.rb:31:in `invoke'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-3.0.0.beta2/exe/rspec:4:in `<top (required)>'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/bin/rspec:23:in `load'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/bin/rspec:23:in `<main>'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
from /Users/joeldoyle/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'
@cupakromer
RSpec member

@joelcdoyle can you provide more details. This works fine for me with the same setup. Can you show us a very small controller spec that has the issue? Please confine it to a single spec.

@joelcdoyle

Sure. This one is super simple. Is this enough info?

    require 'spec_helper'

    describe Api::V1::CollectionsController do
      render_views

      before(:each) do
        @user = FactoryGirl.create(:user)
      end

      context 'when creating a new collection' do
        it 'should create a valid collection' do
          # collection attributes
          collection = FactoryGirl.attributes_for(:collection)
          # moment attributes
          moment = FactoryGirl.attributes_for(:moment)
          collection[:moments] = [moment]

          sign_in @user
          post :create, user_id: @user.id, collection: collection
          response.status.should be 201
          collection_id = JSON.parse(response.body)["collection_id"]
          Collection.find(collection_id).should_not be nil
        end
      end
    end
@cupakromer
RSpec member

@joelcdoyle I'm still not seeing the issue. Below you can see my simple setup. Could you answer these additional questions?

  • What's the relative path, from your project root, of that spec file?
  • What's the output of rails -v?
  • What's the output of rspec -v?
  • What's the output of ruby -v?
  • Do you have something setup in the routes or controller differently?
  • If possible, can you provide a link to the repo? Or reproduce in a repo you can share?

Route

# config/routes.rb
Rails.application.routes.draw do
  namespace :api do
    namespace :v1 do
      resources :foos
    end
  end
end

Controller

# app/controllers/api/v1/foos_controller_spec.rb
class Api::V1::FoosController < ApplicationController
  respond_to :html

  def index
    respond_with @foos = Foo.all
  end
end

Spec

# spec/controllers/api/v1/foos_controller_spec.rb
require 'spec_helper'

describe Api::V1::FoosController do
  render_views

  context "testing issue 932" do
    it "works" do
      get :index
    end
  end

end

Environment

  • Ruby 2.1.0p0
  • RSpec 3.0.0.beta2
  • Rails 4.1.0.rc1
@cupakromer
RSpec member

@joelcdoyle I just noticed something interesting in your stack trace. Are you sure you're using the Rails 4.1.0.rc1 gem? I see a git commit as part of the folder name: gems/rails-fdcab84a13f9.

I should have seen it before, but I see you are on: Ruby ruby-2.0.0p247 and are using RSpec 3.0.0.beta2.

@cupakromer
RSpec member

If someone is still having this issue, could they please follow up by providing a sampe repository that produces the issue?

@justin808

I was having the problem with Rails 4.0. If there's been a fix since that could have addressed this, I'd be happy to try again.

@cupakromer
RSpec member

@justin808 there's been no fix, we've been unable to reproduce the issue as reported. If you could provide a simplified public repository which demonstrates the issue we'll happily look into it.

@Soliah
Soliah commented May 19, 2014

Changing describe SomeController to describe SomeController, type: :controller fixes it for me.

Here's a sample app with it failing https://github.com/Soliah/rspec-test. I just did a scaffold.

Should also mention that this wasn't an issue for me in beta2.

be rspec spec                                                                                                                                                                                                                                                       2.1.1 master 4aa0844
/Users/Chris/foo/spec/controllers/posts_controller_spec.rb:22:in `block in <top (required)>': undefined local variable or method `render_views' for RSpec::ExampleGroups::PostsController_2:Class (NameError)
        from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0.rc1/lib/rspec/core/example_group.rb:331:in `module_exec'
        from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0.rc1/lib/rspec/core/example_group.rb:331:in `subclass'
        from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0.rc1/lib/rspec/core/example_group.rb:227:in `block in define_example_group_method'
        from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0.rc1/lib/rspec/core/dsl.rb:41:in `block in expose_example_group_alias'
        from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0.rc1/lib/rspec/core/dsl.rb:79:in `block (2 levels) in expose_example_group_alias_globally'
        from /Users/Chris/foo/spec/controllers/posts_controller_spec.rb:21:in `<top (required)>'
        from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0.rc1/lib/rspec/core/configuration.rb:1051:in `load'
        from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0.rc1/lib/rspec/core/configuration.rb:1051:in `block in load_spec_files'
        from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0.rc1/lib/rspec/core/configuration.rb:1051:in `each'
        from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0.rc1/lib/rspec/core/configuration.rb:1051:in `load_spec_files'
        from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0.rc1/lib/rspec/core/runner.rb:97:in `setup'
        from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0.rc1/lib/rspec/core/runner.rb:85:in `run'
        from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0.rc1/lib/rspec/core/runner.rb:70:in `run'
        from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0.rc1/lib/rspec/core/runner.rb:38:in `invoke'
        from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0.rc1/exe/rspec:4:in `<top (required)>'
        from /usr/local/var/rbenv/versions/2.1.1/bin/rspec:23:in `load'
        from /usr/local/var/rbenv/versions/2.1.1/bin/rspec:23:in `<main>'
@cupakromer
RSpec member

@Soliah thanks for this update. That's a very interesting and useful insight. By default, we've turned off the auto-mixing in of spec types in RSpec 3. If you generate a new spec_helper.rb we add the following lines for you:

  # RSpec Rails can automatically mix in different behaviours to your tests
  # based on their file location, for example enabling you to call `get` and
  # `post` in specs under `spec/controllers`.
  #
  # You can disable this behaviour by removing the line below, and instead
  # explictly tag your specs with their type, e.g.:
  #
  #     describe UsersController, :type => :controller do
  #       # ...
  #     end
  #
  # The different available types are documented in the features, such as in
  # https://relishapp.com/rspec/rspec-rails/v/3-0/docs
  config.infer_spec_type_from_file_location!

However, if you do a straight upgrade, things won't be mixed in by default.

@cupakromer
RSpec member

Based on this latest information, I believe this is a non-issue. I"m going to close it as such. If someone still has the issue and can provide a working repo with steps to reproduce I'm happy to dig in further. For now, this looks like it's simply an issue of the proper spec type not being mixed in.

@cupakromer cupakromer closed this May 19, 2014
@Soliah
Soliah commented May 19, 2014

@cupakromer Yup adding that call to my spec_helper fixes this for me. I guess as part of the upgrade blog post or documentation this should be noted.

@JonRowe
RSpec member
JonRowe commented May 19, 2014

@Soliah if you run the full upgrade path 2.14 -> 2.99 -> fix warnings -> 3.0 you won't run into this issue, it's because you went from beta2 to rc1 directly that you suffered, sorry

@sekrett
sekrett commented Jul 2, 2014

@cupakromer, what does this mean?

/Users/sekrett/code/vioms/spec/spec_helper.rb:83:in `block in ': undefined method `infer_spec_type_from_file_location!' for # (NoMethodError)
@cupakromer
RSpec member

@sekrett it likely means that rspec rails isn't loaded in that file or you are not on RSpec 3. If you have further issues or questions, please open a new issue to track them.

@JonRowe
RSpec member
JonRowe commented Jul 2, 2014

@sekrett are you calling that method on a configuration object yielded by RSpec 3? As you must do that, you can't rely on it being evaluated against main / block context.

e.g

RSpec.configure do |config|
  config.infer_spec_type_from_file_location!
end

not

RSpec.configure do
  infer_spec_type_from_file_location!
end
@sekrett
sekrett commented Jul 3, 2014

I was calling it from spec_helper.rb, but it is already included in rails_helper.rb, I'm sorry. But still I get the error that render_view is undefined. Reverted to rspec 2.99, don't have time to inspect now.

@cupakromer
RSpec member

@sekrett when you do have time, please do open a new issue for this and I'll happily help look into it.

@chollier

I had the same issue, replacing spec_helper by rails_helper in .rspec fixed the issue

@heaven
heaven commented Oct 17, 2014

I am also seeing this issue.

UPD: adding config.infer_spec_type_from_file_location! fixed this for me. I think you should consider changing this default behavior in 3.*.

@tfausak tfausak added a commit to tfausak/think-200 that referenced this issue Jan 21, 2015
@tfausak tfausak Fix render_views error d1c3d76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.