2
나는 내 레일 모델 중 하나에 대한 테스트 방법을 시도하고 있습니다. URL에서 HTTP 상태를 반환하고 다른 반환 코드를 테스트하여 리턴 코드를 다른 상황에 적용 할 수 있는지 알 수 없습니다.Testing Net :: HTTP.get_Response()
response = Net::HTTP.get_response(URI.parse(self.url))
나는 Net:HTTP.get_response
가 내 사양에있는 각 테스트에 대해 특정 HttpResponse에를 반환하고 싶지 :
는 여기에 내가 조롱 할 코드 줄입니다.
describe Site do
before :each do
FactoryGirl.build :site
end
context "checking site status" do
it "should be true when 200" do
c = FactoryGirl.build :site, url:"http://www.example.com/value.html"
#something to mock the Net::HTTP.get_response to return and instance of Net::HTTPOK
c.ping.should == true
end
it "should be false when 404" do
c = FactoryGirl.build :site, url:"http://www.example.com/value.html"
#something to mock the Net::HTTP.get_response to return and instance of Net::HTTPNotFound
c.ping.should == false
end
end
end
get_response에서 반환 값을 어떻게 내 보냅니다.