Skip to content

Commit

Permalink
Added --host support
Browse files Browse the repository at this point in the history
- For when you need to change the ip address.
- Added Tests
- Updated README
  • Loading branch information
Jon Whitcraft committed Jan 1, 2015
1 parent f21cb7d commit bcdd111
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Options
-------

* `:port` is the port number to run on (default `9292`)
* `:host` is the host ip address to run on (default `0.0.0.0`)
* `:environment` is the environment to use (default `development`)
* `:start_on_start` will start the server when starting Guard (default `true`)
* `:force_run` kills any process that's holding open the listen port before attempting to (re)start Rack (default `false`).
Expand Down
1 change: 1 addition & 0 deletions lib/guard/rack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Rack < ::Guard::Plugin

DEFAULT_OPTIONS = {
port: 9292,
host: '0.0.0.0',
environment: 'development',
start_on_start: true,
force_run: false,
Expand Down
3 changes: 2 additions & 1 deletion lib/guard/rack/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def build_rack_command
command.push(
options[:config],
'--env', options[:environment].to_s,
'--port', options[:port].to_s
'--port', options[:port].to_s,
'--host', options[:host].to_s
)

command << '--daemonize' if options[:daemon]
Expand Down
18 changes: 17 additions & 1 deletion spec/lib/guard/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:environment) { 'development' }
let(:port) { 3000 }

let(:default_options) { { environment: environment, port: port, config: 'config.ru' } }
let(:default_options) { { environment: environment, port: port, config: 'config.ru', host: '0.0.0.0' } }
let(:options) { default_options }

before do
Expand Down Expand Up @@ -83,6 +83,22 @@
end
end
end

context 'host' do
context 'default' do
it 'should default to 0.0.0.0' do
expect(runner.send(:build_rack_command)).to include('0.0.0.0')
end
end

context 'custom' do
let(:options) { default_options.merge(host: '127.0.0.0') }
it 'should honour config option' do
default_options.merge(host: '127.0.0.0')
expect(runner.send(:build_rack_command)).to include('127.0.0.0')
end
end
end
end

describe '#start' do
Expand Down

0 comments on commit bcdd111

Please sign in to comment.