I have a controller which contains a method and some conditional statements. the following is a sample of that controller.
class <controllername> < ApplicationController
def method
if params["c"]
http = Net::HTTP.new(uri.host, uri.port)
req = Net::HTTP::Post.new("api_url_here")
response = http.request(req)
array = JSON.parse(response.body)
url = params["s"]
.....
elsif params["e"]
.....
else
.....
end
end
end
I wrote rspec for the above controller
it "should do something" do
array ="some array values"
get :method, {"c" => "value for c", "s" => "value for s"}
expect(response).to have_http_status(200)
end
I know the above rspec method is completely wrong. when this case runs the value for array and response are obtained by post call inside method and the response is HTTPBADREQUEST as expected.
What I want is
To stub those values for array and response in the spec case(these values will be needed for later operations) and my spec case to not call HTTP::POST inside the method