aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib/health_checks/health_checkable_spec.rb
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2014-09-30 13:56:59 +0100
committerGareth Rees <gareth@mysociety.org>2014-09-30 13:56:59 +0100
commitc64360898beca1162a1bdef9ca4b76676e0907f8 (patch)
tree5c0452a20ce0310f72d0741b171085c5efe1d312 /spec/lib/health_checks/health_checkable_spec.rb
parente5a9052a9ffd27117775e8adaeaa2e24607e8000 (diff)
parent3a40bfc8a8abbfedb554215849b1c6372864eb1f (diff)
Merge branch 'issues/1827-healthcheck' into rails-3-develop
Diffstat (limited to 'spec/lib/health_checks/health_checkable_spec.rb')
-rw-r--r--spec/lib/health_checks/health_checkable_spec.rb128
1 files changed, 128 insertions, 0 deletions
diff --git a/spec/lib/health_checks/health_checkable_spec.rb b/spec/lib/health_checks/health_checkable_spec.rb
new file mode 100644
index 000000000..abfeb5c21
--- /dev/null
+++ b/spec/lib/health_checks/health_checkable_spec.rb
@@ -0,0 +1,128 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+
+describe HealthChecks::HealthCheckable do
+
+ before(:each) do
+ class MockCheck
+ include HealthChecks::HealthCheckable
+ end
+ @subject = MockCheck.new
+ end
+
+ describe :initialize do
+
+ it 'allows a custom failure message to be set' do
+ @subject = MockCheck.new(:failure_message => 'F')
+ expect(@subject.failure_message).to eq('F')
+ end
+
+ it 'allows a custom success message to be set' do
+ @subject = MockCheck.new(:success_message => 'S')
+ expect(@subject.success_message).to eq('S')
+ end
+
+ end
+
+ describe :name do
+
+ it 'returns the name of the check' do
+ expect(@subject.name).to eq('MockCheck')
+ end
+
+ end
+
+ describe :check do
+
+ it 'is intended to be overridden by the includer' do
+ expect{ @subject.check }.to raise_error(NotImplementedError)
+ end
+
+ end
+
+ describe :ok? do
+
+ it 'returns true if the check was successful' do
+ @subject.stub(:check => true)
+ expect(@subject.ok?).to be_true
+ end
+
+ it 'returns false if the check failed' do
+ @subject.stub(:check => false)
+ expect(@subject.ok?).to be_false
+ end
+
+ end
+
+ describe :failure_message do
+
+ it 'returns a default message if one has not been set' do
+ expect(@subject.failure_message).to eq('Failed')
+ end
+
+ end
+
+ describe :failure_message= do
+
+ it 'allows a custom failure message to be set' do
+ @subject.failure_message = 'F'
+ expect(@subject.failure_message).to eq('F')
+ end
+
+ end
+
+ describe :success_message do
+
+ it 'returns a default message if one has not been set' do
+ expect(@subject.success_message).to eq('Success')
+ end
+
+ end
+
+ describe :success_message= do
+
+ it 'allows a custom success message to be set' do
+ @subject.success_message = 'S'
+ expect(@subject.success_message).to eq('S')
+ end
+
+ end
+
+ describe :message do
+
+ context 'if the check succeeds' do
+
+ before(:each) do
+ @subject.stub(:check => true)
+ end
+
+ it 'returns the default success message' do
+ expect(@subject.message).to eq('Success')
+ end
+
+ it 'returns a custom success message if one has been set' do
+ @subject.success_message = 'Custom Success'
+ expect(@subject.message).to eq('Custom Success')
+ end
+
+ end
+
+ context 'if the check fails' do
+
+ before(:each) do
+ @subject.stub(:check => false)
+ end
+
+ it 'returns the default failure message' do
+ expect(@subject.message).to eq('Failed')
+ end
+
+ it 'returns a custom failure message if one has been set' do
+ @subject.failure_message = 'Custom Failed'
+ expect(@subject.message).to eq('Custom Failed')
+ end
+
+ end
+
+ end
+
+end