I have a controller that i want to write rspec for
results_controller.rb
class Api::V1::ResultsController < Api::V1::ApplicationController
before_action :devices
include DataHelper
def show
results = get_dr_results
render json: { data: results }
end
private
def get_dr_results
program_ids = method_defined_in_crucible_helper
end
end
module DataHelper
include Cruciblehelper
def method_missing(method_name, *args, &block)
if condition
do_something
else
super.method_missing(method_name, *args, &block)
end
end
def respond_to_missing?
true
end
end
module CrucibleHelper
def method_defined_in_crucible_helper
end
end
Now in my rspec, I try to mock the method method_defined_in_crucible_helper.
describe Api::V1::DrResultsController, type: :controller do
describe 'GET #show' do
before do
allow_any_instance_of(CrucibleHelper).to receive(:method_defined_in_crucible_helper) { [utility_program.id, utility_program2.id] }
end
context 'returns data' do
context 'returns expected events' do
it 'should return success response with expected events' do
get :show
expect(JSON.parse(response.body)).to eq(expected_response)
end
end
I am getting
Failure/Error:
def respond_to_missing?
true
end
ArgumentError:
wrong number of arguments (given 2, expected 0)
# ./app/helpers/data_helper.rb:72:in `respond_to_missing?'
If I comment out respond_to_missing? method, then my specs are executing OK. Can someone help me in fixing this error?