22
33module OkComputer
44 describe CheckCollection do
5- let ( :foocheck ) { double ( :check ) }
6- let ( :barcheck ) { double ( :check ) }
5+ let ( :foocheck ) { Check . new }
6+ let ( :barcheck ) { Check . new }
77 let ( :registry ) { { foo : foocheck , bar : barcheck } }
88
9- before do
10- allow ( foocheck ) . to receive ( :registrant_name= )
11- allow ( barcheck ) . to receive ( :registrant_name= )
12- end
13-
149 subject { CheckCollection . new ( "foo collection name" ) }
10+ let ( :default_collection ) { CheckCollection . new ( "foo collection name" , true ) }
1511
1612 context ".new" do
1713 it "sets the display name of the check collection" do
@@ -33,6 +29,15 @@ module OkComputer
3329 expect ( barcheck ) . to receive ( :run )
3430 subject . run
3531 end
32+
33+ it "does not run checks registered with skip_all" do
34+ foocheck . skip_all = true
35+ default_collection . register ( :foo , foocheck )
36+ default_collection . register ( :bar , barcheck )
37+ expect ( foocheck ) . not_to receive ( :run )
38+ expect ( barcheck ) . to receive ( :run )
39+ default_collection . run
40+ end
3641 end
3742 end
3843 end
@@ -43,6 +48,19 @@ module OkComputer
4348 subject . register ( :bar , barcheck )
4449 expect ( subject . checks ) . to eq ( registry . values )
4550 end
51+
52+ it "omits checks registered with skip_all" do
53+ foocheck . skip_all = true
54+ default_collection . register ( :foo , foocheck )
55+ default_collection . register ( :bar , barcheck )
56+ expect ( default_collection . checks ) . to eq ( [ barcheck ] )
57+ end
58+
59+ it "does not omit skipped checks from a named collection" do
60+ foocheck . skip_all = true
61+ subject . register ( :foo , foocheck )
62+ expect ( subject . checks ) . to eq ( [ foocheck ] )
63+ end
4664 end
4765
4866 context "#register" do
@@ -67,6 +85,12 @@ module OkComputer
6785 expect ( subject . fetch ( :foo ) ) . to eq ( foocheck )
6886 end
6987
88+ it "finds checks registered with skip_all" do
89+ foocheck . skip_all = true
90+ subject . register ( :foo , foocheck )
91+ expect ( subject . fetch ( :foo ) ) . to eq ( foocheck )
92+ end
93+
7094 it "finds checks in a sub_collection" do
7195 sub_collection = CheckCollection . new ( "sub" )
7296 subject . register ( "sub" , sub_collection )
@@ -121,7 +145,17 @@ module OkComputer
121145 subject . register ( :bar , barcheck )
122146 allow ( foocheck ) . to receive ( :to_text ) { "foo" }
123147 allow ( barcheck ) . to receive ( :to_text ) { "bar" }
124- expect ( subject . to_text ) . to eq ( "foo collection name\n \s \s foo\n \s \s bar" )
148+ expect ( subject . to_text ) . to eq ( "foo collection name\n \s \s bar\n \s \s foo" )
149+ end
150+
151+ it "omits checks registered with skip_all" do
152+ foocheck . skip_all = true
153+ default_collection . register ( :foo , foocheck )
154+ default_collection . register ( :bar , barcheck )
155+ allow ( foocheck ) . to receive ( :to_text ) { "foo" }
156+ allow ( barcheck ) . to receive ( :to_text ) { "bar" }
157+ expect ( foocheck ) . not_to receive ( :to_text )
158+ expect ( default_collection . to_text ) . to eq ( "foo collection name\n \s \s bar" )
125159 end
126160 end
127161
@@ -134,6 +168,16 @@ module OkComputer
134168 combined_hash = JSON . parse ( foocheck . to_json ) . merge ( JSON . parse ( barcheck . to_json ) )
135169 expect ( subject . to_json ) . to eq ( combined_hash . to_json )
136170 end
171+
172+ it "omits checks registered with skip_all" do
173+ foocheck . skip_all = true
174+ default_collection . register ( :foo , foocheck )
175+ default_collection . register ( :bar , barcheck )
176+ allow ( foocheck ) . to receive ( :to_json ) { { "foo" => "foo result" } . to_json }
177+ allow ( barcheck ) . to receive ( :to_json ) { { "bar" => "bar result" } . to_json }
178+ expect ( foocheck ) . not_to receive ( :to_json )
179+ expect ( default_collection . to_json ) . to eq ( { "bar" => "bar result" } . to_json )
180+ end
137181 end
138182
139183 context "#success?" do
@@ -152,6 +196,15 @@ module OkComputer
152196 allow ( barcheck ) . to receive ( :success? ) { false }
153197 expect ( subject ) . not_to be_success
154198 end
199+
200+ it "ignores failures from checks registered with skip_all" do
201+ foocheck . skip_all = true
202+ default_collection . register ( :foo , foocheck )
203+ default_collection . register ( :bar , barcheck )
204+ allow ( barcheck ) . to receive ( :success? ) { true }
205+ expect ( foocheck ) . not_to receive ( :success? )
206+ expect ( default_collection ) . to be_success
207+ end
155208 end
156209 end
157210end
0 commit comments