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
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
|