Sha256: 752f08ce92e28982764bea487e58bcecc9a3de8a5aee188f1b02eee29f61fda3

Contents?: true

Size: 1.95 KB

Versions: 5

Compression:

Stored size: 1.95 KB

Contents

require 'spec_helper'

describe Appsignal::Transmitter do
  let(:_80beans_) { 'http://www.80beans.com' }
  let(:action) { 'action' }
  let(:klass) { Appsignal::Transmitter }
  let(:instance) { klass.new(_80beans_, action, :the_api_key) }
  subject { instance }

  describe "#uri" do
    it "returns the uri" do
      Socket.stub(:gethostname => 'app1.local')
      subject.uri.should ==
        URI("http://www.80beans.com/action?api_key=the_api_key&hostname=app1.local&gem_version=#{Appsignal::VERSION}")
    end
  end

  describe "#transmit" do
    let(:http_client) { stub(:request => stub(:code => '200')) }
    before { instance.stub(:http_client => http_client) }

    subject { instance.transmit(:shipit => :payload) }

    it { should == '200' }
  end

  describe "#http_post" do
    it "calls Net::HTTP.post_form with the correct params" do
      post = stub
      post.should_receive(:[]=).with('Content-Type', 'application/json; charset=UTF-8')
      post.should_receive(:body=).with("{\"the\":\"payload\"}")
      Socket.stub(:gethostname => 'app1.local')

      Net::HTTP::Post.should_receive(:new).with(
        "/action?api_key=the_api_key&hostname=app1.local&gem_version=#{Appsignal::VERSION}"
      ).and_return(post)
      instance.send(:http_post, :the => :payload)
    end
  end

  describe "ca_file_path" do
    subject { instance.send(:ca_file_path) }

    it { should include('resources/cacert.pem') }
    it("should exist") { File.exists?(subject).should be_true }
  end

  describe "#http_client" do
    subject { instance.send(:http_client) }

    context "with a http uri" do
      it { should be_instance_of(Net::HTTP) }

      its(:use_ssl?) { should be_false }
    end

    context "with a https uri" do
      let(:instance) { klass.new('https://www.80beans.com', action, :the_api_key) }

      its(:use_ssl?) { should be_true }
      its(:verify_mode) { should == OpenSSL::SSL::VERIFY_PEER }
      its(:ca_file) { include('resources/cacert.pem') }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
appsignal-0.4.7 spec/appsignal/transmitter_spec.rb
appsignal-0.4.6 spec/appsignal/transmitter_spec.rb
appsignal-0.4.5 spec/appsignal/transmitter_spec.rb
appsignal-0.4.4 spec/appsignal/transmitter_spec.rb
appsignal-0.4.3 spec/appsignal/transmitter_spec.rb