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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
require 'spec_helper'
describe MailRoom::CLI do
let(:config_path) {File.expand_path('../fixtures/test_config.yml', File.dirname(__FILE__))}
let!(:configuration) {MailRoom::Configuration.new({:config_path => config_path})}
let(:coordinator) {stub(:run => true, :quit => true)}
let(:configuration_args) { anything }
let(:coordinator_args) { [anything, anything] }
describe '.new' do
let(:args) {["-c", "a path"]}
before :each do
MailRoom::Configuration.expects(:new).with(configuration_args).returns(configuration)
MailRoom::Coordinator.stubs(:new).with(*coordinator_args).returns(coordinator)
end
context 'with configuration args' do
let(:configuration_args) do
{:config_path => 'a path'}
end
it 'parses arguments into configuration' do
expect(MailRoom::CLI.new(args).configuration).to eq configuration
end
end
context 'with coordinator args' do
let(:coordinator_args) do
[configuration.mailboxes, anything]
end
it 'creates a new coordinator with configuration' do
expect(MailRoom::CLI.new(args).coordinator).to eq(coordinator)
end
end
end
describe '#start' do
let(:cli) {MailRoom::CLI.new([])}
before :each do
cli.configuration = configuration
cli.coordinator = coordinator
cli.stubs(:exit)
end
it 'starts running the coordinator' do
coordinator.expects(:run)
cli.start
end
context 'on error' do
let(:error) { RuntimeError.new("oh noes!") }
let(:coordinator) { stub(run: true, quit: true) }
let(:crash_handler) { stub(handle: nil) }
before do
cli.instance_variable_set(:@options, {exit_error_format: error_format})
coordinator.stubs(:run).raises(error)
MailRoom::CrashHandler.stubs(:new).returns(crash_handler)
end
context 'json format provided' do
let(:error_format) { 'json' }
it 'passes onto CrashHandler' do
crash_handler.expects(:handle).with(error, error_format)
cli.start
end
end
end
end
end
|