diff options
Diffstat (limited to 'spec/lib/health_checks/health_checks_spec.rb')
-rw-r--r-- | spec/lib/health_checks/health_checks_spec.rb | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/spec/lib/health_checks/health_checks_spec.rb b/spec/lib/health_checks/health_checks_spec.rb new file mode 100644 index 000000000..c7037b813 --- /dev/null +++ b/spec/lib/health_checks/health_checks_spec.rb @@ -0,0 +1,77 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe HealthChecks do + include HealthChecks + + describe :add do + + it 'adds a check to the collection and returns the check' do + check = double('MockCheck', :check => true) + expect(add(check)).to eq(check) + end + + it 'does not add checks that do not define the check method' do + check = double('BadCheck') + expect(add(check)).to eq(false) + end + + end + + describe :all do + + it 'returns all the checks' do + check1 = double('MockCheck', :check => true) + check2 = double('AnotherCheck', :check => false) + add(check1) + add(check2) + expect(all).to include(check1, check2) + end + + end + + describe :each do + + it 'iterates over each check' do + expect(subject).to respond_to(:each) + end + + end + + describe :ok? do + + it 'returns true if all checks are ok' do + checks = [ + double('MockCheck', :ok? => true), + double('FakeCheck', :ok? => true), + double('TestCheck', :ok? => true) + ] + HealthChecks.stub(:all => checks) + + expect(HealthChecks.ok?).to be_true + end + + it 'returns false if all checks fail' do + checks = [ + double('MockCheck', :ok? => false), + double('FakeCheck', :ok? => false), + double('TestCheck', :ok? => false) + ] + HealthChecks.stub(:all => checks) + + expect(HealthChecks.ok?).to be_false + end + + it 'returns false if a single check fails' do + checks = [ + double('MockCheck', :ok? => true), + double('FakeCheck', :ok? => false), + double('TestCheck', :ok? => true) + ] + HealthChecks.stub(:all => checks) + + expect(HealthChecks.ok?).to be_false + end + + end + +end |