MikeAndr MikeAndr - 4 months ago 25
Ruby Question

Rspec 3. undefined local variable or method `response' for #<RSpec::ExampleGroups::ConfigsAPI::GETApiConfig:0x007f84d93fbb90>

I want to test API controller with rspec.
So here is the simple piece of code:

require 'rails_helper'
describe "GET /api/config" do

it 'routes GET to /api/config to Api::V1::ConfigsController#show' do
get '/api/config.json'
expect(response).to be_success


But I've got an error:

1) Configs API GET /api/config routes GET to /api/config to Api::V1::ConfigsController#show
Failure/Error: expect(response).to be_success
undefined local variable or method `response' for #<RSpec::ExampleGroups::ConfigsAPI::GETApiConfig:0x007f84d93fbb90>
# ./spec/routing/api/v1/devise/configs_routing_spec.rb:13:in `block (3 levels) in <top (required)>'


In RSpec 3 you would do:

get '/api/config.json'
expect(response.status).to be(200)