I have the first example passing after modifying the shared examples spec
as follows:
>
> #spec/shared/json_response.rb
require 'rails_helper'
RSpec.shared_examples 'JSON Responsive controller' do
let(:instance) { described_class.new }
describe '#json_response' do
it 'should respond with JSON response' do
expect(instance).to respond_to(:json_response)
end
it 'returns correct JSON with default status' do
model = double(:model)
json = instance.json_response(model)
puts json.inspect
end
end
end
The problem is the failing 2d example where I mock a model to pass in
the json_response method:
Module::DelegationError:
ActionController::Metal#status= delegated to @_response.status=, but
@_response is nil: #<FakeController:0x00007ff2f2013758 @_routes=nil,
@_request=nil, @_response=nil, @_config={}, @_db_runtime=216.53>
Shared Example Group: "JSON Responsive controller" called from
./spec/controllers/concerns/fake_controller_spec.rb:7
# ./app/controllers/concerns/response.rb:6:in `json_response'
# ./spec/shared/json_response.rb:13:in `block (3 levels) in <main>'
# ------------------
# --- Caused by: ---
# NoMethodError:
# undefined method `status=' for nil:NilClass
# ./app/controllers/concerns/response.rb:6:in `json_response'
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/2bc2be48-bfc7-4518-979e-a91cafd79b26%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.