Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Why don't RSpec's methods, "get", "post", "put", "delete" work in a controller spec in a gem (or outside Rails)?Why don't RSpec's methods, "get", "post", "put", "delete" work in a controller spec in a gem (or outside Rails)?

Based off this question, you could try redefining process() in ActionController::TestCase from https://github.com/rails/rails/blob/32395899d7c97f69b508b7d7f9b7711f28586679/actionpack/lib/action_controller/test_case.rb.

Here is my workaround though.

describe FooController do let(:defaults) { {format: :json} } context 'GET index' do let(:params) { defaults } before :each do get :index, params end # ... end context 'POST create' do let(:params) { defaults.merge({ name: 'bar' }) } before :each do post :create, params end # ... end end 

Why don't RSpec's methods, "get", "post", "put", "delete" work in a controller spec in a gem (or outside Rails)?

Based off this question, you could try redefining process() in ActionController::TestCase from https://github.com/rails/rails/blob/32395899d7c97f69b508b7d7f9b7711f28586679/actionpack/lib/action_controller/test_case.rb.

Here is my workaround though.

describe FooController do let(:defaults) { {format: :json} } context 'GET index' do let(:params) { defaults } before :each do get :index, params end # ... end context 'POST create' do let(:params) { defaults.merge({ name: 'bar' }) } before :each do post :create, params end # ... end end 

Why don't RSpec's methods, "get", "post", "put", "delete" work in a controller spec in a gem (or outside Rails)?

Based off this question, you could try redefining process() in ActionController::TestCase from https://github.com/rails/rails/blob/32395899d7c97f69b508b7d7f9b7711f28586679/actionpack/lib/action_controller/test_case.rb.

Here is my workaround though.

describe FooController do let(:defaults) { {format: :json} } context 'GET index' do let(:params) { defaults } before :each do get :index, params end # ... end context 'POST create' do let(:params) { defaults.merge({ name: 'bar' }) } before :each do post :create, params end # ... end end 
Source Link

Why don't RSpec's methods, "get", "post", "put", "delete" work in a controller spec in a gem (or outside Rails)?

Based off this question, you could try redefining process() in ActionController::TestCase from https://github.com/rails/rails/blob/32395899d7c97f69b508b7d7f9b7711f28586679/actionpack/lib/action_controller/test_case.rb.

Here is my workaround though.

describe FooController do let(:defaults) { {format: :json} } context 'GET index' do let(:params) { defaults } before :each do get :index, params end # ... end context 'POST create' do let(:params) { defaults.merge({ name: 'bar' }) } before :each do post :create, params end # ... end end