@@ -118,11 +118,11 @@ def when_no_thorfiles_exist
118118 end
119119
120120 describe "commands" do
121+ let ( :location ) { "#{ File . dirname ( __FILE__ ) } /fixtures/command.thor" }
121122 before do
122- @location = "#{ File . dirname ( __FILE__ ) } /fixtures/command.thor"
123123 @original_yaml = {
124124 "random" => {
125- :location => @ location,
125+ :location => location ,
126126 :filename => "4a33b894ffce85d7b412fc1b36f88fe0" ,
127127 :namespaces => %w( amazing )
128128 }
@@ -214,31 +214,52 @@ def when_no_thorfiles_exist
214214 end
215215
216216 describe "install/update" do
217- before do
218- allow ( FileUtils ) . to receive ( :mkdir_p )
219- allow ( FileUtils ) . to receive ( :touch )
220- allow ( Thor ::LineEditor ) . to receive ( :readline ) . and_return ( "Y" )
221-
222- path = File . join ( Thor ::Util . thor_root , Digest ::SHA256 . hexdigest ( @location + "random" ) )
223- expect ( File ) . to receive ( :open ) . with ( path , "w" )
224- end
217+ context "with local thor files" do
218+ before do
219+ allow ( FileUtils ) . to receive ( :mkdir_p )
220+ allow ( FileUtils ) . to receive ( :touch )
221+ allow ( Thor ::LineEditor ) . to receive ( :readline ) . and_return ( "Y" )
222+
223+ path = File . join ( Thor ::Util . thor_root , Digest ::SHA256 . hexdigest ( location + "random" ) )
224+ expect ( File ) . to receive ( :open ) . with ( path , "w" )
225+ end
225226
226- it "updates existing thor files" do
227- path = File . join ( Thor ::Util . thor_root , @original_yaml [ "random" ] [ :filename ] )
228- if File . directory? path
229- expect ( FileUtils ) . to receive ( :rm_rf ) . with ( path )
230- else
231- expect ( File ) . to receive ( :delete ) . with ( path )
227+ it "updates existing thor files" do
228+ path = File . join ( Thor ::Util . thor_root , @original_yaml [ "random" ] [ :filename ] )
229+ if File . directory? path
230+ expect ( FileUtils ) . to receive ( :rm_rf ) . with ( path )
231+ else
232+ expect ( File ) . to receive ( :delete ) . with ( path )
233+ end
234+ silence_warnings do
235+ silence ( :stdout ) { Thor ::Runner . start ( %w( update random ) ) }
236+ end
232237 end
233- silence_warnings do
234- silence ( :stdout ) { Thor ::Runner . start ( %w( update random ) ) }
238+
239+ it "installs thor files" do
240+ ARGV . replace %W( install #{ location } )
241+ silence_warnings do
242+ silence ( :stdout ) { Thor ::Runner . start }
243+ end
235244 end
236245 end
237246
238- it "installs thor files" do
239- ARGV . replace %W( install #{ @location } )
240- silence_warnings do
241- silence ( :stdout ) { Thor ::Runner . start }
247+ context "with remote thor files" do
248+ let ( :location ) { "https://example.com/Thorfile" }
249+
250+ it "installs thor files" do
251+ allow ( Thor ::LineEditor ) . to receive ( :readline ) . and_return ( "Y" , "random" )
252+ stub_request ( :get , location ) . to_return ( :body => "class Foo < Thor; end" )
253+ path = File . join ( Thor ::Util . thor_root , Digest ::SHA256 . hexdigest ( location + "random" ) )
254+ expect ( File ) . to receive ( :open ) . with ( path , "w" )
255+ expect { silence ( :stdout ) { Thor ::Runner . start ( %W( install #{ location } ) ) } } . not_to raise_error
256+ end
257+
258+ it "shows proper errors" do
259+ expect ( Thor ::Runner ) . to receive :exit
260+ expect ( URI ) . to receive ( :open ) . with ( location ) . and_raise ( OpenURI ::HTTPError . new ( "foo" , StringIO . new ) )
261+ content = capture ( :stderr ) { Thor ::Runner . start ( %W( install #{ location } ) ) }
262+ expect ( content ) . to include ( "Error opening URI '#{ location } '" )
242263 end
243264 end
244265 end
0 commit comments