diagnostics 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/features/diagnostic_checks.feature +48 -20
- data/lib/diagnostics/check.rb +18 -25
- data/lib/diagnostics/methods.rb +2 -2
- data/lib/diagnostics/version.rb +1 -1
- data/lib/diagnostics.rb +8 -0
- data/spec/diagnostics/check_spec.rb +33 -26
- data/spec/diagnostics/methods_spec.rb +24 -27
- data/spec/diagnostics_spec.rb +13 -0
- data/spec_rails/rails2/Gemfile.lock +1 -1
- data/spec_rails/rails2/features/diagnostics_page.feature +6 -6
- data/spec_rails/rails2/features/status_page.feature +10 -10
- data/spec_rails/rails2/features/step_definitions/diagnostic_steps.rb +8 -4
- metadata +5 -5
data/Gemfile.lock
CHANGED
@@ -12,12 +12,16 @@ Feature: Diagnostic checks
|
|
12
12
|
$:.unshift(File.dirname(__FILE__) + '/../../lib')
|
13
13
|
require 'diagnostics'
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
class StatusMethods
|
16
|
+
include DiagnosticsCheck
|
17
|
+
|
18
|
+
def passed; true end
|
19
|
+
def warning; false end
|
20
|
+
def failed; false end
|
19
21
|
end
|
20
22
|
|
23
|
+
check = diagnostic_check(:StatusMethods)
|
24
|
+
|
21
25
|
puts check.passed?
|
22
26
|
puts check.warning?
|
23
27
|
puts check.failed?
|
@@ -39,13 +43,19 @@ Feature: Diagnostic checks
|
|
39
43
|
$:.unshift(File.dirname(__FILE__) + '/../../lib')
|
40
44
|
require 'diagnostics'
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
class AttributesOnCheck
|
47
|
+
include DiagnosticsCheck
|
48
|
+
|
49
|
+
def data
|
50
|
+
lambda do |d|
|
51
|
+
d['Master'] = 'Up'
|
52
|
+
d['Slave'] = 'Down'
|
53
|
+
end
|
46
54
|
end
|
47
55
|
end
|
48
56
|
|
57
|
+
check = diagnostic_check(:AttributesOnCheck)
|
58
|
+
|
49
59
|
puts check.data.attributes(:plain)
|
50
60
|
puts
|
51
61
|
puts check.data.attributes(:html)
|
@@ -74,13 +84,19 @@ Feature: Diagnostic checks
|
|
74
84
|
$:.unshift(File.dirname(__FILE__) + '/../../lib')
|
75
85
|
require 'diagnostics'
|
76
86
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
87
|
+
class ListsOnCheck
|
88
|
+
include DiagnosticsCheck
|
89
|
+
|
90
|
+
def data
|
91
|
+
lambda do |d|
|
92
|
+
d << ['a', 'b', 'c']
|
93
|
+
d << [1, 2, 3]
|
94
|
+
end
|
81
95
|
end
|
82
96
|
end
|
83
97
|
|
98
|
+
check = diagnostic_check(:ListsOnCheck)
|
99
|
+
|
84
100
|
puts check.data.lists(:plain)
|
85
101
|
puts
|
86
102
|
puts check.data.lists(:html)
|
@@ -106,13 +122,19 @@ Feature: Diagnostic checks
|
|
106
122
|
$:.unshift(File.dirname(__FILE__) + '/../../lib')
|
107
123
|
require 'diagnostics'
|
108
124
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
125
|
+
class TextsOnCheck
|
126
|
+
include DiagnosticsCheck
|
127
|
+
|
128
|
+
def data
|
129
|
+
lambda do |d|
|
130
|
+
d << 'a'
|
131
|
+
d << 'b'
|
132
|
+
end
|
113
133
|
end
|
114
134
|
end
|
115
135
|
|
136
|
+
check = diagnostic_check(:TextsOnCheck)
|
137
|
+
|
116
138
|
puts check.data.texts(:plain)
|
117
139
|
puts
|
118
140
|
puts check.data.texts(:html)
|
@@ -134,13 +156,19 @@ Feature: Diagnostic checks
|
|
134
156
|
$:.unshift(File.dirname(__FILE__) + '/../../lib')
|
135
157
|
require 'diagnostics'
|
136
158
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
159
|
+
class TablesOnCheck
|
160
|
+
include DiagnosticsCheck
|
161
|
+
|
162
|
+
def data
|
163
|
+
lambda do |d|
|
164
|
+
d << { 'heading1' => [1,2,3],
|
165
|
+
'heading2' => [4,5,6] }
|
166
|
+
end
|
141
167
|
end
|
142
168
|
end
|
143
169
|
|
170
|
+
check = diagnostic_check(:TablesOnCheck)
|
171
|
+
|
144
172
|
print check.data.tables(:html)
|
145
173
|
"""
|
146
174
|
When I run "ruby tables.rb"
|
data/lib/diagnostics/check.rb
CHANGED
@@ -1,44 +1,33 @@
|
|
1
1
|
module Diagnostics
|
2
|
-
class Check
|
2
|
+
class Check < Struct.new(:cls)
|
3
3
|
|
4
|
-
def self.add(
|
5
|
-
Diagnostics.checks << check = new(
|
4
|
+
def self.add(cls)
|
5
|
+
Diagnostics.checks << check = new(cls)
|
6
6
|
check
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.find(name)
|
10
|
-
Diagnostics.checks.select {|c| c.name == name }[0]
|
10
|
+
Diagnostics.checks.select {|c| c.name == name.to_s }[0]
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
def initialize(name, &block)
|
16
|
-
@name = name
|
17
|
-
instance_eval(&block) if block
|
18
|
-
end
|
19
|
-
|
20
|
-
def passed(&block)
|
21
|
-
@passed_block = block
|
22
|
-
end
|
23
|
-
|
24
|
-
def warning(&block)
|
25
|
-
@warning_block = block
|
13
|
+
def name
|
14
|
+
cls.name
|
26
15
|
end
|
27
16
|
|
28
|
-
def
|
29
|
-
@
|
17
|
+
def instance
|
18
|
+
@instance ||= cls.new
|
30
19
|
end
|
31
20
|
|
32
21
|
def passed?
|
33
|
-
@
|
22
|
+
@passed_method_result ||= call_method(:passed)
|
34
23
|
end
|
35
24
|
|
36
25
|
def warning?
|
37
|
-
@
|
26
|
+
@warning_method_result ||= call_method(:warning)
|
38
27
|
end
|
39
28
|
|
40
29
|
def failed?
|
41
|
-
@
|
30
|
+
@failed_method_result ||= call_method(:failed)
|
42
31
|
end
|
43
32
|
|
44
33
|
def status
|
@@ -49,7 +38,11 @@ module Diagnostics
|
|
49
38
|
end
|
50
39
|
|
51
40
|
def data
|
52
|
-
|
41
|
+
@data_method_result ||= if instance.respond_to?(:data)
|
42
|
+
instance.data.call(data_group) && data_group
|
43
|
+
else
|
44
|
+
data_group
|
45
|
+
end
|
53
46
|
end
|
54
47
|
|
55
48
|
private
|
@@ -58,8 +51,8 @@ module Diagnostics
|
|
58
51
|
@data_group ||= DataGroup.new
|
59
52
|
end
|
60
53
|
|
61
|
-
def
|
62
|
-
|
54
|
+
def call_method(meth)
|
55
|
+
instance.respond_to?(meth) && instance.send(meth)
|
63
56
|
end
|
64
57
|
|
65
58
|
end
|
data/lib/diagnostics/methods.rb
CHANGED
data/lib/diagnostics/version.rb
CHANGED
data/lib/diagnostics.rb
CHANGED
@@ -3,27 +3,43 @@ require 'spec_helper'
|
|
3
3
|
module Diagnostics
|
4
4
|
describe Check do
|
5
5
|
|
6
|
+
before { class MyClass; end }
|
7
|
+
|
6
8
|
describe '.add' do
|
7
9
|
it 'adds a check' do
|
8
|
-
described_class.add
|
10
|
+
described_class.add MyClass
|
9
11
|
Diagnostics.should have(1).checks
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
13
15
|
describe '.find' do
|
14
|
-
let!(:check) { described_class.add
|
16
|
+
let!(:check) { described_class.add MyClass }
|
15
17
|
|
16
18
|
it 'finds the check by name' do
|
17
|
-
described_class.find(
|
19
|
+
described_class.find('Diagnostics::MyClass').should eq(check)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#name' do
|
24
|
+
it 'returns the diagnostic class name' do
|
25
|
+
described_class.new(MyClass).name.should eq('Diagnostics::MyClass')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#instance' do
|
30
|
+
it 'returns an instance of the diagnostic class' do
|
31
|
+
described_class.new(MyClass).instance.should be_an_instance_of(MyClass)
|
18
32
|
end
|
19
33
|
end
|
20
34
|
|
21
35
|
describe 'status predicate methods' do
|
22
|
-
let(:check)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
36
|
+
let(:check) { described_class.new(MyClass) }
|
37
|
+
|
38
|
+
before do
|
39
|
+
check.cls.class_eval do
|
40
|
+
def passed; true end
|
41
|
+
def warning; false end
|
42
|
+
def failed; false end
|
27
43
|
end
|
28
44
|
end
|
29
45
|
|
@@ -45,32 +61,23 @@ module Diagnostics
|
|
45
61
|
context "with #{status}" do
|
46
62
|
let(:check) { create_check(status) }
|
47
63
|
specify { check.status.should eq(status) }
|
64
|
+
after { check.cls.send(:remove_method, status) }
|
48
65
|
end
|
49
66
|
end
|
50
67
|
|
51
|
-
def create_check(status
|
52
|
-
described_class.new(
|
53
|
-
|
54
|
-
|
55
|
-
|
68
|
+
def create_check(status)
|
69
|
+
described_class.new(MyClass).tap do |check|
|
70
|
+
check.cls.class_eval do
|
71
|
+
define_method(status) { true }
|
72
|
+
end
|
56
73
|
end
|
57
74
|
end
|
58
75
|
end
|
59
76
|
|
60
77
|
describe '#data' do
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
d.should be_an_instance_of(Diagnostics::DataGroup)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context 'given no block' do
|
70
|
-
it 'returns a DataGroup instance' do
|
71
|
-
data = described_class.new(:foo).data
|
72
|
-
data.should be_an_instance_of(Diagnostics::DataGroup)
|
73
|
-
end
|
78
|
+
it 'returns a DataGroup instance' do
|
79
|
+
data = described_class.new(MyClass).data
|
80
|
+
data.should be_an_instance_of(Diagnostics::DataGroup)
|
74
81
|
end
|
75
82
|
end
|
76
83
|
|
@@ -8,19 +8,9 @@ end
|
|
8
8
|
|
9
9
|
describe '#diagnostic_check' do
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
diagnostic_checks.should have(1).check
|
15
|
-
diagnostic_checks.first.name.should eq(:foo)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'without block given' do
|
20
|
-
it 'finds the check' do
|
21
|
-
check = diagnostic_check(:foo) { }
|
22
|
-
diagnostic_check(:foo).should eq(check)
|
23
|
-
end
|
11
|
+
it 'finds the check' do
|
12
|
+
class MyClass; include(DiagnosticsCheck) end
|
13
|
+
diagnostic_check(:MyClass).cls.should eq(MyClass)
|
24
14
|
end
|
25
15
|
|
26
16
|
end
|
@@ -73,11 +63,13 @@ describe '#diagnostic_status' do
|
|
73
63
|
|
74
64
|
context 'with all checks passing' do
|
75
65
|
before do
|
76
|
-
|
77
|
-
|
66
|
+
class MyPassingClass
|
67
|
+
include DiagnosticsCheck
|
68
|
+
def passed; true end
|
78
69
|
end
|
79
|
-
|
80
|
-
|
70
|
+
class MySecondPassingClass
|
71
|
+
include DiagnosticsCheck
|
72
|
+
def passed; true end
|
81
73
|
end
|
82
74
|
end
|
83
75
|
|
@@ -88,14 +80,17 @@ describe '#diagnostic_status' do
|
|
88
80
|
|
89
81
|
context 'with a check that failed' do
|
90
82
|
before do
|
91
|
-
|
92
|
-
|
83
|
+
class MyPassingClass
|
84
|
+
include DiagnosticsCheck
|
85
|
+
def passed; true end
|
93
86
|
end
|
94
|
-
|
95
|
-
|
87
|
+
class MyWarningClass
|
88
|
+
include DiagnosticsCheck
|
89
|
+
def warning; true end
|
96
90
|
end
|
97
|
-
|
98
|
-
|
91
|
+
class MyFailedClass
|
92
|
+
include DiagnosticsCheck
|
93
|
+
def failed; true end
|
99
94
|
end
|
100
95
|
end
|
101
96
|
|
@@ -106,11 +101,13 @@ describe '#diagnostic_status' do
|
|
106
101
|
|
107
102
|
context 'with a warning check' do
|
108
103
|
before do
|
109
|
-
|
110
|
-
|
104
|
+
class MyPassingClass
|
105
|
+
include DiagnosticsCheck
|
106
|
+
def passed; true end
|
111
107
|
end
|
112
|
-
|
113
|
-
|
108
|
+
class MyWarningClass
|
109
|
+
include DiagnosticsCheck
|
110
|
+
def warning; true end
|
114
111
|
end
|
115
112
|
end
|
116
113
|
|
data/spec/diagnostics_spec.rb
CHANGED
@@ -8,4 +8,17 @@ describe Diagnostics do
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
+
end
|
12
|
+
|
13
|
+
describe DiagnosticsCheck do
|
14
|
+
|
15
|
+
describe '.included' do
|
16
|
+
before { diagnostic_checks.should be_empty }
|
17
|
+
|
18
|
+
it 'adds the class to checks' do
|
19
|
+
class MyCheck; include DiagnosticsCheck end
|
20
|
+
diagnostic_checks.should have(1).check
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
11
24
|
end
|
@@ -8,26 +8,26 @@ Feature: Diagnostics page
|
|
8
8
|
Then I should be on the diagnostics page
|
9
9
|
|
10
10
|
Scenario: A passing diagnostic check with data attributes
|
11
|
-
Given a diagnostic check named "
|
11
|
+
Given a diagnostic check named "MySQLCheck" with the following statuses:
|
12
12
|
| passed | warning | failed |
|
13
13
|
| true | false | false |
|
14
|
-
And diagnostic check "
|
14
|
+
And diagnostic check "MySQLCheck" has the following data attributes:
|
15
15
|
| a | b | c |
|
16
16
|
| 1 | 2 | 3 |
|
17
17
|
When I go to the diagnostics page
|
18
|
-
Then I should see a passed diagnostic check named "
|
18
|
+
Then I should see a passed diagnostic check named "MySQLCheck"
|
19
19
|
And should see "a: 1" within diagnostic data
|
20
20
|
And should see "b: 2" within diagnostic data
|
21
21
|
And should see "c: 3" within diagnostic data
|
22
22
|
And should see "All Systems Operational" as the title
|
23
23
|
|
24
24
|
Scenario: A failed diagnostic check with a data list
|
25
|
-
Given a diagnostic check named "
|
25
|
+
Given a diagnostic check named "MySQLCheck" with the following statuses:
|
26
26
|
| passed | warning | failed |
|
27
27
|
| false | false | true |
|
28
|
-
And diagnostic check "
|
28
|
+
And diagnostic check "MySQLCheck" has a data list: "a,b,c"
|
29
29
|
When I go to the diagnostics page
|
30
|
-
Then I should see a failed diagnostic check named "
|
30
|
+
Then I should see a failed diagnostic check named "MySQLCheck"
|
31
31
|
And should see "a" within diagnostic data
|
32
32
|
And should see "b" within diagnostic data
|
33
33
|
And should see "c" within diagnostic data
|
@@ -11,33 +11,33 @@ Feature: Status page
|
|
11
11
|
Then I should be on the status page
|
12
12
|
|
13
13
|
Scenario: A simple passing diagnostic check
|
14
|
-
Given a diagnostic check named "
|
14
|
+
Given a diagnostic check named "MySQLCheck" with the following statuses:
|
15
15
|
| passed | warning | failed |
|
16
16
|
| true | false | false |
|
17
17
|
When I go to the status page
|
18
|
-
Then I should see a passed diagnostic check named "
|
18
|
+
Then I should see a passed diagnostic check named "MySQLCheck"
|
19
19
|
And should see "All Systems Operational" as the title
|
20
20
|
|
21
21
|
Scenario: Diagnostic checks that contain one warning check
|
22
|
-
Given a diagnostic check named "
|
22
|
+
Given a diagnostic check named "MySQLCheck" with the following statuses:
|
23
23
|
| passed | warning | failed |
|
24
24
|
| true | false | false |
|
25
|
-
Given a diagnostic check named "
|
25
|
+
Given a diagnostic check named "PostgreSQLCheck" with the following statuses:
|
26
26
|
| passed | warning | failed |
|
27
27
|
| false | true | false |
|
28
28
|
When I go to the status page
|
29
|
-
Then I should see a passed diagnostic check named "
|
30
|
-
And should see a warning diagnostic check named "
|
29
|
+
Then I should see a passed diagnostic check named "MySQLCheck"
|
30
|
+
And should see a warning diagnostic check named "PostgreSQLCheck"
|
31
31
|
And should see "Experiencing Issues" as the title
|
32
32
|
|
33
33
|
Scenario: Diagnostic checks that contain one failing check
|
34
|
-
Given a diagnostic check named "
|
34
|
+
Given a diagnostic check named "MySQLCheck" with the following statuses:
|
35
35
|
| passed | warning | failed |
|
36
36
|
| true | false | false |
|
37
|
-
Given a diagnostic check named "
|
37
|
+
Given a diagnostic check named "PostgreSQLCheck" with the following statuses:
|
38
38
|
| passed | warning | failed |
|
39
39
|
| false | false | true |
|
40
40
|
When I go to the status page
|
41
|
-
Then I should see a passed diagnostic check named "
|
42
|
-
And should see a failed diagnostic check named "
|
41
|
+
Then I should see a passed diagnostic check named "MySQLCheck"
|
42
|
+
And should see a failed diagnostic check named "PostgreSQLCheck"
|
43
43
|
And should see "System Failure" as the title
|
@@ -1,11 +1,15 @@
|
|
1
1
|
Given /^a diagnostic check named "([^"]*)" with the following statuses:$/ do |name, table|
|
2
2
|
statuses = table.hashes[0]
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
body = Class.new do
|
5
|
+
include DiagnosticsCheck
|
6
|
+
define_method(:passed) { eval(statuses[:passed]) }
|
7
|
+
define_method(:warning) { eval(statuses[:warning]) }
|
8
|
+
define_method(:failed) { eval(statuses[:failed]) }
|
8
9
|
end
|
10
|
+
|
11
|
+
Object.send(:remove_const, name) if Object.const_defined?(name)
|
12
|
+
Object.const_set(name, body)
|
9
13
|
end
|
10
14
|
|
11
15
|
Given /^diagnostic check "([^"]*)" has the following data attributes:$/ do |name, table|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diagnostics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Justin Ko
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-23 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -216,7 +216,7 @@ rubyforge_project: diagnostics
|
|
216
216
|
rubygems_version: 1.4.2
|
217
217
|
signing_key:
|
218
218
|
specification_version: 3
|
219
|
-
summary: diagnostics-0.0.
|
219
|
+
summary: diagnostics-0.0.3
|
220
220
|
test_files:
|
221
221
|
- features/diagnostic_checks.feature
|
222
222
|
- features/step_definitions/aruba.rb
|