How to test complex controller method with chained method ?
def update
# ...
user.propositions.call
# ...
end
# ...
def call
# ...
response = MyAPI::connect(object)
Object.create(params)
if SeviceObject.new().send
return true
else
# ...
end
# ...
end
Use classic receive and return method.
RSpec.describe "update" do
it "calls the call method" do
# ...
expect_any_instance_of(User).to receive_chain_message(:propositions, :call).and_return(true)
put :update, params
#...
end
end
it "calls the call method" do
# ...
propositions = double('Proposition', call: true)
expect_any_instance_of(User).to receive(:propositions).and_return(propositions)
put :update, params
#...
end