Sha256: ac2450fd7b9edcf21457f950dc77839cf9c770b9e944ea0ee987f602fb790c7a

Contents?: true

Size: 1.3 KB

Versions: 5

Compression:

Stored size: 1.3 KB

Contents

require 'spec_helper'

require 'observed/http'

describe Observed::Plugins::HTTP do

  subject {
    Observed::Plugins::HTTP.new
  }

  before {
    subject.configure config
  }

  let(:config) {
    {
        timeout_in_milliseconds: 1000,
        method: 'get',
        url: 'http://google.com/',
        tag: 'test',
        system: sys
    }
  }

  let(:sys) {
    sys = mock('system')
    sys.stubs(:now).returns(before).then.returns(after)
    sys
  }

  let(:before) {
    Time.now
  }

  let(:after) {
    Time.now + 1
  }

  let(:response) {
    res = stub('response')
    res.stubs(body: 'the response body')
    res
  }

  context 'when timed out' do
    before {
      Timeout.expects(:timeout).raises(Timeout::Error)

      sys.expects(:report).with('test.error', {status: :error, error: {message: 'Timed out.'}, timed_out: true})
    }

    it 'reports an error' do
      expect { subject.observe }.to_not raise_error
    end
  end

  context 'when not timed out' do
    before {
      Timeout.expects(:timeout).returns({ status: :success, result: 'Get http://google.com/' })

      sys.expects(:report).with('test.success', {status: :success, result: 'Get http://google.com/', elapsed_time: after - before})
    }

    it 'reports an success' do
      expect { subject.observe }.to_not raise_error
    end
  end

end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
observed-http-0.2.0 spec/http_spec.rb
observed-0.2.0 plugins/observed-http/spec/http_spec.rb
observed-http-0.2.0.rc1 spec/http_spec.rb
observed-0.2.0.rc2 plugins/observed-http/spec/http_spec.rb
observed-0.2.0.rc1 plugins/observed-http/spec/http_spec.rb