Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/custom url is not working on docker #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/mirage/client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions lib/mirage/client/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/mirage/client/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 30 additions & 1 deletion spec/mirage/client/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -133,6 +163,5 @@
Mirage::Runner.should_receive(:new).and_return(runner)
expect { runner.invoke(:stop, [], options) }.not_to raise_error
end

end
end