rails-controller-testing: Adding rails-controller-testing** gem does not fix NoMethodError message

Adding rails-controller-testing gem to my Rails 5 fork of codeforatlanta’s show-me-the-food5 (https://github.com/jasnow/show-me-the-food5) repo’s Gemfile does not fix the following message:

  • NoMethodError:assigns has been extracted to a gem. To continue using it, add gem 'rails-controller-testing' to your Gemfile.

Appears to not be the only one: http://stackoverflow.com/questions/30605868/rails-controller-testing-gem


If you run “rake” before upgrading to the most recent version of Rails 5, no tests break.

After adding the gem rails-controller-testing, running “bundle update”, and then running “rake,” you get:

Failures:

  1) LocationsController#index assigns @locations
     Failure/Error: subject{ assigns(:locations) }
     NoMethodError:
       assigns has been extracted to a gem. To continue using it,
               add `gem 'rails-controller-testing'` to your Gemfile.
     # /home/jasnow/.rvm/gems/ruby-2.2.2/bundler/gems/rails-7220ffcffd00/
       actionpack/lib/action_dispatch/testing/test_process.rb:8:in `assigns'
     # ./spec/controllers/locations_controller_spec.rb:5:in `block
       (3 levels) in <top (required)>'
     # ./spec/controllers/locations_controller_spec.rb:9:in `block
       (3 levels) in <top (required)>'

Finished in 0.29375 seconds (files took 3.41 seconds to load)
1 example, 1 failure

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 44 (5 by maintainers)

Commits related to this issue

Most upvoted comments

This issue still seems to be active with Rails 5.1.6, RSpec 3.7.2, and rails-controller-testing 1.0.2.

I’ve tried all the solutions here, and nothing has worked. Here’s my spec_helper.rb:

...

require 'rails-controller-testing'
require "rails/controller/testing/test_process"
require "rails/controller/testing/integration"
require "rails/controller/testing/template_assertions"

...

RSpec.configure do |config|
  config.include Rails::Controller::Testing::TestProcess, type: :controller
  config.include Rails::Controller::Testing::Integration, type: :controller
  config.include Rails::Controller::Testing::TemplateAssertions, type: :controller
end

...

Still I get the following error:

NoMethodError:
       assigns has been extracted to a gem. To continue using it,
               add `gem 'rails-controller-testing'` to your Gemfile.

Help!

This worked for me:

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'rails-controller-testing'
end

Rails 6.0.0.rc1, Ruby 2.6.0p0, still the error persists after adding rails-controller-testing gem

NoMethodError: assigns has been extracted to a gem. To continue using it,
add `gem 'rails-controller-testing'` to your Gemfile.

+1

On my project it works fine with controller tests, but when I try to use it within a request spec I get:

NoMethodError:
       assigns has been extracted to a gem. To continue using it,
               add `gem 'rails-controller-testing'` to your Gemfile.

Versions: rails 5.1.4, rspec-rails 3.7.2, rails-controller-testing 1.0.2

In case anyone else runs into this issue, the README file’s section about usage with RSpec has since been modified, so the note that @tgxworld is alluding to no longer exists. It can be found, however, in this commit: https://github.com/rails/rails-controller-testing/commit/f756b33c138c593eabe37f6085f8bac477b99bfe