Search code examples
ruby-on-railsrspec-railsruby-on-rails-6

rspec rails 6 controllers


I have created a new project using rails 6 and I can't test many controllers with rspec 3.8 or 3.9.0.pre, for example this test:

it 'OK' do
  get :index
  expect(response).to be_ok
end

raises

Failure/Error: render template: 'rig_masters/index'

     ActionView::Template::Error:
       wrong number of arguments (given 2, expected 1)

if I have a controller that renders json it passes, for example if the controller is

def index
  @components = Component.recent
  render json: @components
end

test passes

but if I try to render a view like

def index
  @components = Component.recent
end

or even

def index
  @components = Component.recent
  render template: 'components/index'
end

raises the ActionView::Template::Error: wrong number of arguments (given 2, expected 1) error

Any help to make these tests pass would be greatly appreciated.


Solution

  • RSpec isn't compatible with Rails 6 yet. However, you can use rspec-rails 4.0.0.beta2, which will fix this particular issue!

    Link: https://github.com/rspec/rspec-rails/issues/2155