@@ -131,4 +131,92 @@ def perform_update(fixture_name = "")
131131 end
132132 end
133133 end
134+
135+ describe ReporterHub do
136+ let ( :hub ) { described_class . new }
137+
138+ before do
139+ ENV [ "HOMEBREW_NO_COLOR" ] = "1"
140+ allow ( hub ) . to receive ( :select_formula_or_cask ) . and_return ( [ ] )
141+ end
142+
143+ it "dumps new formulae report" do
144+ allow ( hub ) . to receive ( :select_formula_or_cask ) . with ( :A ) . and_return ( [ "foo" , "bar" , "baz" ] )
145+ allow ( hub ) . to receive_messages ( installed? : false , all_formula_json : [
146+ { "name" => "foo" , "desc" => "foobly things" } ,
147+ { "name" => "baz" , "desc" => "baz desc" } ,
148+ ] )
149+ expect { hub . dump } . to output ( <<~EOS ) . to_stdout
150+ ==> New Formulae
151+ bar
152+ baz: baz desc
153+ foo: foobly things
154+ EOS
155+ end
156+
157+ it "dumps new casks report" do
158+ allow ( hub ) . to receive ( :select_formula_or_cask ) . with ( :AC ) . and_return ( [ "foo/cask1" , "foo/cask2" , "foo/cask3" ] )
159+ allow ( hub ) . to receive_messages ( cask_installed? : false , all_cask_json : [
160+ { "token" => "cask1" , "desc" => "desc1" } ,
161+ { "token" => "cask3" , "desc" => "desc3" } ,
162+ ] )
163+ allow ( Cask ::Caskroom ) . to receive ( :any_casks_installed? ) . and_return ( true )
164+ expect { hub . dump } . to output ( <<~EOS ) . to_stdout
165+ ==> New Casks
166+ cask1: desc1
167+ cask2
168+ cask3: desc3
169+ EOS
170+ end
171+
172+ it "dumps deleted installed formulae and casks report" do
173+ allow ( hub ) . to receive ( :select_formula_or_cask ) . with ( :D ) . and_return ( [ "baz" , "foo" , "bar" ] )
174+ allow ( hub ) . to receive ( :installed? ) . with ( "baz" ) . and_return ( true )
175+ allow ( hub ) . to receive ( :installed? ) . with ( "foo" ) . and_return ( true )
176+ allow ( hub ) . to receive ( :installed? ) . with ( "bar" ) . and_return ( true )
177+ allow ( hub ) . to receive ( :select_formula_or_cask ) . with ( :A ) . and_return ( [ ] )
178+ allow ( hub ) . to receive ( :select_formula_or_cask ) . with ( :DC ) . and_return ( [ "cask2" , "cask1" ] )
179+ allow ( hub ) . to receive ( :cask_installed? ) . with ( "cask1" ) . and_return ( true )
180+ allow ( hub ) . to receive ( :cask_installed? ) . with ( "cask2" ) . and_return ( true )
181+ allow ( Homebrew ::SimulateSystem ) . to receive ( :simulating_or_running_on_linux? ) . and_return ( false )
182+ expect { hub . dump } . to output ( <<~EOS ) . to_stdout
183+ ==> Deleted Installed Formulae
184+ bar
185+ baz
186+ foo
187+ ==> Deleted Installed Casks
188+ cask1
189+ cask2
190+ EOS
191+ end
192+
193+ it "dumps outdated formulae and casks report" do
194+ allow ( Formula ) . to receive ( :installed ) . and_return ( [
195+ instance_double ( Formula , name : "foo" , outdated? : true ) ,
196+ instance_double ( Formula , name : "bar" , outdated? : true ) ,
197+ ] )
198+ allow ( Cask ::Caskroom ) . to receive ( :casks ) . and_return ( [
199+ instance_double ( Cask ::Cask , token : "baz" , outdated? : true ) ,
200+ instance_double ( Cask ::Cask , token : "qux" , outdated? : true ) ,
201+ ] )
202+ expect { hub . dump } . to output ( <<~EOS ) . to_stdout
203+ ==> Outdated Formulae
204+ bar
205+ foo
206+ ==> Outdated Casks
207+ baz
208+ qux
209+
210+ You have 2 outdated formulae and 2 outdated casks installed.
211+ You can upgrade them with brew upgrade
212+ or list them with brew outdated.
213+ EOS
214+ end
215+
216+ it "prints nothing if there are no changes" do
217+ allow ( Formula ) . to receive ( :installed ) . and_return ( [ ] )
218+ allow ( Cask ::Caskroom ) . to receive ( :casks ) . and_return ( [ ] )
219+ expect { hub . dump } . not_to output . to_stdout
220+ end
221+ end
134222end
0 commit comments