From fc545ba3a9ca0d8b16baf3a538f8ed674c73bbc7 Mon Sep 17 00:00:00 2001 From: Maciej Wozniak Date: Tue, 10 Apr 2018 15:36:34 +0100 Subject: [PATCH 1/2] Fix problem with custom url not working in docker. --- lib/mirage/client/client.rb | 4 ++-- lib/mirage/client/runner.rb | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/mirage/client/client.rb b/lib/mirage/client/client.rb index 080c11ae..3a66443a 100644 --- a/lib/mirage/client/client.rb +++ b/lib/mirage/client/client.rb @@ -12,10 +12,10 @@ class Client def initialize options={:url => "http://localhost:7001"}, &block if options.is_a?(String) && options =~ URI.regexp @url = options - elsif options.kind_of?(Hash) && options[:port] - @url = "http://localhost:#{options[:port]}" elsif options.kind_of?(Hash) && options[:url] @url = options[:url] + elsif options.kind_of?(Hash) && options[:port] + @url = "http://localhost:#{options[:port]}" else raise "specify a valid URL or port" end diff --git a/lib/mirage/client/runner.rb b/lib/mirage/client/runner.rb index d55a4900..6a5b82e1 100644 --- a/lib/mirage/client/runner.rb +++ b/lib/mirage/client/runner.rb @@ -42,12 +42,19 @@ def stop options={:port => []} # Mirage.running? :port => port -> boolean indicating whether Mirage is running on *locally* on the given port # Mirage.running? url -> boolean indicating whether Mirage is running on the given URL def running? options_or_url = {:port => 7001} - url = options_or_url.kind_of?(Hash) ? "http://localhost:#{options_or_url[:port]}" : options_or_url + if options_or_url.kind_of?(Hash) + if options_or_url[:url] + url = options_or_url[:url] + else + url = "http://localhost:#{options_or_url[:port]}" + end + else + url = options_or_url + end HTTParty.get(url) and return true rescue Errno::ECONNREFUSED return false end - end class Runner < Thor From 92e2a225c7bc3d61a400d6c87c603c6fde3aa403 Mon Sep 17 00:00:00 2001 From: Maciej Wozniak Date: Wed, 11 Apr 2018 15:03:39 +0100 Subject: [PATCH 2/2] @WozniakMac Add tests to running checker and client. --- spec/mirage/client/client_spec.rb | 2 +- spec/mirage/client/runner_spec.rb | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/spec/mirage/client/client_spec.rb b/spec/mirage/client/client_spec.rb index e73ac0be..78bdb6c0 100644 --- a/spec/mirage/client/client_spec.rb +++ b/spec/mirage/client/client_spec.rb @@ -17,7 +17,7 @@ mirage_url = "http://url.for.mirage" Client.new(mirage_url).url.should == mirage_url - Client.new(:url => mirage_url).url.should == mirage_url + Client.new(:url => mirage_url, :port => 9001).url.should == mirage_url end it 'can be configured with a port refering to which port Mirage is running on on localhost' do diff --git a/spec/mirage/client/runner_spec.rb b/spec/mirage/client/runner_spec.rb index 5feff830..bea525a5 100644 --- a/spec/mirage/client/runner_spec.rb +++ b/spec/mirage/client/runner_spec.rb @@ -42,7 +42,37 @@ @runner.should_receive(:invoke).with(:stop, [], :port => ports) Mirage.stop(:port => ports) end + end + + describe '.running?' do + before(:each) do + HTTParty.stub(:get) + end + + it 'should check running app if you do not pass params' do + url = 'http://localhost:7001' + HTTParty.should_receive(:get).with(url).and_return(true) + Mirage.running? + end + it 'should check running app if you pass url as string' do + url = 'http://my.url:9000' + HTTParty.should_receive(:get).with(url).and_return(true) + Mirage.running?(url) + end + + it 'should check running app if you pass url in hash' do + url = 'http://my.url:9000' + HTTParty.should_receive(:get).with(url).and_return(true) + Mirage.running?({:url => url}) + end + + it 'should check running app if you pass port in hash' do + url = 'http://localhost:1234' + port = 1234 + HTTParty.should_receive(:get).with(url).and_return(true) + Mirage.running?({:port => port}) + end end describe Mirage::Runner do @@ -133,6 +163,5 @@ Mirage::Runner.should_receive(:new).and_return(runner) expect { runner.invoke(:stop, [], options) }.not_to raise_error end - end end \ No newline at end of file