I have been using rails 5.0.0.1, am new to automation testing and using rspec-rails-3.5.2 for writing automation.
I want to test some basic controller rendering functionality and instance variable assignments. Wrote a controller test case which will check whether get_structure template is rendered and required instance variables are assigned.
describe 'GET #get_structure' do
context 'get attributes to build tree structure' do
let(:plan) { FactoryGirl.create(:plan) }
it 'expects all keys to build structure' do
get :get_structure, params: { id: 6, school_subdomain: 'chrys' }
expect(response).to render_template(:get_structure)
expect(assigns.keys.include?('collection')).to be true
expect(assigns.keys.include?('structure')).to be true
expect(assigns.keys.include?('config')).to be true
end
end
end
Once i ran the test cases i realized assert_template is no longer supported due to some security reasons.
NoMethodError: assert_template has been extracted to a gem. To continue using it, add
gem 'rails-controller-testing'
to your Gemfile.
Since its mentioned in rspec-rails documentation that using rails-controller-testing gem will add back the functionality, i did add it.
In Rails 5.x, controller testing has been moved to its own gem which is rails-controller-testing. Using assigns in your controller specs without adding this gem will no longer work.
I have added rails-controller-testing-1.0.1 gem. Also in the rails-controller-testing gem documentation it is mentioned that
rspec-rails automatically integrates with this gem since version 3.5.0. Adding the gem to your Gemfile is sufficient.
But even after adding, it still throws the same error.
How to resolve this issue? Is there any other way of doing controller tests. I have been banging my head over this for quite sometime. Any help would be appreciated. Thanks in advance.