require 'spec_helper' describe '#diagnostic_checks' do it 'defaults to an empty array' do diagnostic_checks.should eq([]) end end describe '#diagnostic_check' do context 'with block given' do it 'adds a check' do diagnostic_check(:foo) { } diagnostic_checks.should have(1).check diagnostic_checks.first.name.should eq(:foo) end end context 'without block given' do it 'finds the check' do check = diagnostic_check(:foo) { } diagnostic_check(:foo).should eq(check) end end end describe '#diagnostic_message' do context 'with diagnostic_status returning :passed' do before do should_receive(:diagnostic_status).and_return(:passed) end specify do diagnostic_message.should eq('All Systems Operational') end end context 'with diagnostic_status returning :warning' do before do should_receive(:diagnostic_status).and_return(:warning) end specify do diagnostic_message.should eq('Experiencing Issues') end end context 'with diagnostic_status returning :failed' do before do should_receive(:diagnostic_status).and_return(:failed) end specify do diagnostic_message.should eq('System Failure') end end context 'with diagnostic_status returning :none' do before do should_receive(:diagnostic_status).and_return(:none) end specify do diagnostic_message.should eq('No Diagnostic Checks Run') end end end describe '#diagnostic_status' do context 'with all checks passing' do before do diagnostic_check(:foo) do |c| c.passed { true } end diagnostic_check(:bar) do |c| c.passed { true } end end it 'returns :passed' do diagnostic_status.should eq(:passed) end end context 'with a check that failed' do before do diagnostic_check(:foo) do |c| c.passed { true } end diagnostic_check(:zoo) do |c| c.warning { true } end diagnostic_check(:bar) do |c| c.failed { true } end end it 'returns :failed' do diagnostic_status.should eq(:failed) end end context 'with a warning check' do before do diagnostic_check(:foo) do |c| c.passed { true } end diagnostic_check(:bar) do |c| c.warning { true } end end it 'returns :warning' do diagnostic_status.should eq(:warning) end end context 'with no checks' do it 'returns :none' do diagnostic_status.should eq(:none) end end end