Sha256: 7c43f97d686dc9d66a3608ac419fc3ef1b1472b39e0d524ac7abb15e7b90317d

Contents?: true

Size: 1.67 KB

Versions: 12

Compression:

Stored size: 1.67 KB

Contents

require 'gorgon/crash_reporter'

describe "CrashReporter" do
  let(:exchange) { stub("Bunny Exchange", :publish => nil) }
  let(:info) { {
      :out_file => "stdout_file", :err_file => "stderr_file", :footer_text => "Text"
    } }

  let(:container_class) do
    Class.new do
      extend(CrashReporter)
    end
  end

  describe "#report_crash" do
    it "tails output file to get last few lines and cat err file to get all lines" do
      container_class.should_receive(:'`').once.
        with(/tail.*stdout_file/).and_return ""
      container_class.should_receive(:'`').once.
        with(/cat.*stderr_file/).and_return ""
      container_class.report_crash exchange, info
    end

    it "calls send_crash_message" do
      container_class.stub!(:'`').and_return "stdout text", "stderr text "
      container_class.should_receive(:send_crash_message).with(exchange, "stdout text", "stderr text Text")
      container_class.report_crash exchange, info
    end

    it "returns last lines of output from stderr message and footer text" do
      container_class.stub!(:'`').and_return "stdout text", "stderr text "
      container_class.stub!(:send_crash_message)
      result = container_class.report_crash exchange, info
      result.should == "stdout text\nstderr text Text"
    end
  end

  describe "#send_crash_message" do
    it "sends message with output and errors from syncer using reply_exchange " do
      reply = {:type => :crash, :hostname => Socket.gethostname, :stdout => "some output",
        :stderr => "some errors"}
      exchange.should_receive(:publish).with(Yajl::Encoder.encode(reply))
      container_class.send_crash_message exchange, "some output", "some errors"
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
gorgon-0.5.0.rc1 spec/crash_reporter_spec.rb
gorgon-0.4.5 spec/crash_reporter_spec.rb
gorgon-0.4.5.rc1 spec/crash_reporter_spec.rb
gorgon-0.4.4 spec/crash_reporter_spec.rb
gorgon-0.4.3 spec/crash_reporter_spec.rb
gorgon-0.4.2 spec/crash_reporter_spec.rb
gorgon-0.4.1 spec/crash_reporter_spec.rb
gorgon-0.4.1.rc1 spec/crash_reporter_spec.rb
gorgon-0.4.0 spec/crash_reporter_spec.rb
gorgon-0.4.0.rc2 spec/crash_reporter_spec.rb
gorgon-0.4.0.rc1 spec/crash_reporter_spec.rb
gorgon-0.3.2 spec/crash_reporter_spec.rb