Sha256: ede8b23e99bfb922bf00549beadef50aa2bb1b3b4448fc38fbfb69e71509a36e

Contents?: true

Size: 971 Bytes

Versions: 16

Compression:

Stored size: 971 Bytes

Contents

module HTTParty
  module StubResponse
    def stub_http_response_with(filename)
      format = filename.split('.').last.intern
      data = file_fixture(filename)

      response = Net::HTTPOK.new("1.1", 200, "Content for you")
      response.stub!(:body).and_return(data)

      http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', :format => format)
      http_request.stub_chain(:http, :request).and_return(response)

      HTTParty::Request.should_receive(:new).and_return(http_request)
    end

    def stub_response(body, code = 200)
      @request.options[:base_uri] ||= 'http://localhost'
      unless defined?(@http) && @http
        @http = Net::HTTP.new('localhost', 80)
        @request.stub!(:http).and_return(@http)
      end

      response = Net::HTTPResponse::CODE_TO_OBJ[code.to_s].new("1.1", code, body)
      response.stub!(:body).and_return(body)

      @http.stub!(:request).and_return(response)
      response
    end
  end
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
nutshell-crm-0.0.6.alpha vendor/bundle/gems/httparty-0.8.1/spec/support/stub_response.rb
nutshell-crm-0.0.5 vendor/bundle/gems/httparty-0.8.1/spec/support/stub_response.rb
nutshell-crm-0.0.4 vendor/bundle/gems/httparty-0.8.1/spec/support/stub_response.rb
nutshell-crm-0.0.3 vendor/bundle/gems/httparty-0.8.1/spec/support/stub_response.rb
nutshell-crm-0.0.2 vendor/bundle/gems/httparty-0.8.1/spec/support/stub_response.rb
nutshell-crm-0.0.1 vendor/bundle/gems/httparty-0.8.1/spec/support/stub_response.rb
httparty-0.8.1 spec/support/stub_response.rb
httparty-0.8.0 spec/support/stub_response.rb
httparty2-0.7.10 spec/support/stub_response.rb
httparty-0.7.8 spec/support/stub_response.rb
httparty-0.7.7 spec/support/stub_response.rb
httparty-0.7.6 spec/support/stub_response.rb
httparty-0.7.4 spec/support/stub_response.rb
httparty-0.7.3 spec/support/stub_response.rb
httparty-0.7.2 spec/support/stub_response.rb
httparty-0.7.0 spec/support/stub_response.rb