Sha256: 003680e08efbfe100efafa0a99543e65d32cc7e07153bdcadeaa79d1f0069dde

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

require 'test_helper'

describe Outpost::Scouts::Http do
  class NetHttpStub
    class << self
      def response(&block); @response = block; end

      def get_response(*args)
        @response.call
      end
    end
  end

  before(:each) do
    config_stub = config_stub(:host => 'localhost', :http_class => NetHttpStub)
    @subject    = Outpost::Scouts::Http.new("description", config_stub)
  end

  it "should get the response code and response body" do
    NetHttpStub.response { response_stub('200', 'Body') }
    @subject.execute

    assert_equal 200   , @subject.response_code
    assert_equal 'Body', @subject.response_body
  end

  it "should set the reporting data accordingly" do
    NetHttpStub.response { response_stub('200', 'Body') }
    @subject.run

    assert_equal 200   , @subject.report_data[:response_code]
    assert_equal 'Body', @subject.report_data[:response_body]
  end

  it "should set response code and body as nil when connection refused" do
    NetHttpStub.response { raise Errno::ECONNREFUSED }
    @subject.execute

    refute @subject.response_code
    refute @subject.response_body
  end

  it "should set response code and body as nil when socket error" do
    NetHttpStub.response { raise SocketError }

    refute @subject.response_code
    refute @subject.response_body
  end

  private

  def config_stub(options={})
    build_stub(:options => options)
  end

  def response_stub(code, body)
    build_stub(:code => code, :body => body)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
outpost-0.2.4 test/outpost/scouts/http_test.rb
outpost-0.2.3 test/outpost/scouts/http_test.rb
outpost-0.2.2 test/outpost/scouts/http_test.rb
outpost-0.2.1 test/outpost/scouts/http_test.rb