1
在我的控制器中我與參數這個職位的要求和它完美Rails這樣嘲笑HTTP POST請求
parameters = {'email' => "email", 'password' => "password"}
response = Net::HTTP.post_form(URI.parse('http://example.com/unsubscriptions'), {'q'=>parameters})
if response.is_a?(Net::HTTPSuccess)
@msg = "You have successfully unsubscribed."
else
@msg = "Resource not found."
end
曾在規格控制器,這是我的代碼
it "should return success message on a successfull Post request to api" do
parameters = { "email" => 'email', "password" => "password" }
Net::HTTP.should_receive(:post_form).with(
URI.parse("http://example.com/unsubscriptions"), "q" => parameters
).and_return(Net::HTTPSuccess)
post :unsub_uk, parameters
#assigns(:msg).should eq("You have successfully unsubscribed.")
response.should be_success
end
不能嘲笑這個Net::HTTP.post_form
請求。任何想法或任何其他方式來完成這項任務? 在此先感謝。