File: crash_handler_spec.rb

package info (click to toggle)
ruby-mail-room 0.10.0%2Breally0.0.9-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 376 kB
  • sloc: ruby: 1,749; makefile: 5
file content (42 lines) | stat: -rw-r--r-- 1,007 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'spec_helper'

describe MailRoom::CrashHandler do

  let(:error_message) { "oh noes!" }
  let(:error) { RuntimeError.new(error_message) }
  let(:stdout) { StringIO.new }

  describe '#handle' do

    subject{ described_class.new(stdout).handle(error, format) }

    context 'when given a json format' do
      let(:format) { 'json' }

      it 'writes a json message to stdout' do
        subject
        stdout.rewind
        output = stdout.read

        expect(output).to end_with("\n")
        expect(JSON.parse(output)['message']).to eq(error_message)
      end
    end

    context 'when given a blank format' do
      let(:format) { "" }

      it 'raises an error as designed' do
        expect{ subject }.to raise_error(error.class, error_message)
      end
    end

    context 'when given a nonexistent format' do
      let(:format) { "nonsense" }

      it 'raises an error as designed' do
        expect{ subject }.to raise_error(error.class, error_message)
      end
    end
  end
end