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

Make it possible to run within mountable engine within a dummy app (using jasminerice) #83

Merged
merged 2 commits into from
Oct 16, 2012
Merged
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ The server options configures the server environment that is needed to run Guard

:timeout => 20000 # The time in ms to wait for the spec runner to finish.
# default: 10000

:rackup_config => 'spec/dummy/config.ru' # Path to rackup config file (i.e. for webrick, mongrel, thin, unicorn).
# default: ./config.ru
# This option is useful when using guard-jasmine in a mountable engine
# and the config.ru is within the dummy app
```

If you're setting the `:server` option to `:none`, you can supply the Jasmine runner url manually:
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/jasmine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def initialize(watchers = [], options = { })
def start
if Jasmine.phantomjs_bin_valid?(options[:phantomjs_bin])

Server.start(options[:server], options[:port], options[:server_env], options[:spec_dir]) unless options[:server] == :none
Server.start(options[:server], options[:port], options[:server_env], options[:spec_dir], options[:rackup_config]) unless options[:server] == :none

if Jasmine.runner_available?(options)
run_all if options[:all_on_start]
Expand Down
14 changes: 10 additions & 4 deletions lib/guard/jasmine/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ class << self
# @param [Number] port the server port
# @param [String] environment the Rails environment
# @param [String] spec_dir the spec directory
# @param [String] (optional) custom rackup config to use (i.e. spec/dummy/config.ru for mountable engines)
#
def start(strategy, port, environment, spec_dir)
def start(strategy, port, environment, spec_dir, rackup_config = nil)
strategy = detect_server(spec_dir) if strategy == :auto

case strategy
when :webrick, :mongrel, :thin, :unicorn
start_rack_server(port, environment, strategy)
start_rack_server(port, environment, strategy, rackup_config)
when :jasmine_gem
start_rake_server(port, 'jasmine')
else
Expand Down Expand Up @@ -53,11 +54,16 @@ def stop
# @param [Number] port the server port
# @param [String] environment the Rails environment
# @param [Symbol] server the rack server to use
# @param [String] (optional) custom rackup config to use (i.e. spec/dummy/config.ru for mountable engines)
#
def start_rack_server(port, environment, server)
def start_rack_server(port, environment, server, rackup_config)
::Guard::UI.info "Guard::Jasmine starts #{ server } test server on port #{ port } in #{ environment } environment."

self.process = ChildProcess.build('rackup', '-E', environment.to_s, '-p', port.to_s, '-s', server.to_s)
if rackup_config
self.process = ChildProcess.build('rackup', '-E', environment.to_s, '-p', port.to_s, '-s', server.to_s, rackup_config)
else
self.process = ChildProcess.build('rackup', '-E', environment.to_s, '-p', port.to_s, '-s', server.to_s)
end
self.process.io.inherit! if ::Guard.respond_to?(:options) && ::Guard.options && ::Guard.options[:verbose]
self.process.start

Expand Down
15 changes: 11 additions & 4 deletions spec/guard/jasmine/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
end

it 'starts a :thin rack server' do
server.should_receive(:start_rack_server).with(8888, 'test', :thin)
server.should_receive(:start_rack_server).with(8888, 'test', :thin, nil)
server.start(:thin, 8888, 'test', 'spec/javascripts')
end
end
Expand All @@ -109,7 +109,7 @@
end

it 'starts a :mongrel rack server' do
server.should_receive(:start_rack_server).with(8888, 'test', :mongrel)
server.should_receive(:start_rack_server).with(8888, 'test', :mongrel, nil)
server.start(:mongrel, 8888, 'test', 'spec/javascripts')
end
end
Expand All @@ -126,7 +126,7 @@
end

it 'starts a :webrick rack server' do
server.should_receive(:start_rack_server).with(8888, 'test', :webrick)
server.should_receive(:start_rack_server).with(8888, 'test', :webrick, nil)
server.start(:webrick, 8888, 'test', 'spec/javascripts')
end
end
Expand All @@ -143,11 +143,18 @@
end

it 'starts a :unicorn rack server' do
server.should_receive(:start_rack_server).with(8888, 'test', :unicorn)
server.should_receive(:start_rack_server).with(8888, 'test', :unicorn, nil)
server.start(:unicorn, 8888, 'test', 'spec/javascripts')
end
end

context 'with the :webrick strategy and a custom config.ru' do
it 'starts a :webrick rack server' do
server.should_receive(:start_rack_server).with(8888, 'test', :webrick, 'my/cool.ru')
server.start(:webrick, 8888, 'test', 'spec/javascripts', 'my/cool.ru')
end
end

context 'with the :jasmine_gem strategy' do
it 'does not auto detect a server' do
server.should_not_receive(:detect_server)
Expand Down
2 changes: 1 addition & 1 deletion spec/guard/jasmine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
end

it 'does start a server' do
server.should_receive(:start).with(:jasmine_gem, 3333, 'test', 'spec/javascripts')
server.should_receive(:start).with(:jasmine_gem, 3333, 'test', 'spec/javascripts', nil)
guard.start
end
end
Expand Down