Skip to content

Commit

Permalink
Add a verbose option to the CLI runner. (Closes #119)
Browse files Browse the repository at this point in the history
  • Loading branch information
netzpirat committed Apr 3, 2013
1 parent 374502a commit a81e741
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## Master

- [#119](https://github.com/netzpirat/guard-jasmine/issues/119): Add a `verbose` option to the CLI runner.

## 1.13.2 - March 13, 2013

- [#118](https://github.com/netzpirat/guard-jasmine/pull/118): Fix Rake task execution on Windows. ([@twill88][])
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -616,6 +616,7 @@ Options:
# Default: auto
-p, [--port=N] # Server port to use
# Default: Random free port
[--verbose] # Show the server output in the console
-e, [--server-env=SERVER_ENV] # The server environment to use, for example `development`, `test` etc.
# Default: test
[--server-timeout=N] # The number of seconds to wait for the Jasmine spec server
Expand Down
6 changes: 6 additions & 0 deletions lib/guard/jasmine/cli.rb
Expand Up @@ -44,6 +44,11 @@ class CLI < Thor
:default => 60,
:desc => 'The number of seconds to wait for the Jasmine spec server'

method_option :verbose,
:type => :boolean,
:default => false,
:desc => 'Show the server output in the console'

method_option :rackup_config,
:type => :string,
:aliases => '-c',
Expand Down Expand Up @@ -140,6 +145,7 @@ def spec(*paths)
runner_options[:jasmine_url] = options.url || "http://localhost:#{ runner_options[:port] }#{ options.server.to_sym == :jasmine_gem ? '/' : '/jasmine' }"
runner_options[:phantomjs_bin] = options.bin || CLI.which('phantomjs')
runner_options[:timeout] = options.timeout
runner_options[:verbose] = options.verbose
runner_options[:server] = options.server.to_sym
runner_options[:server_env] = options.server_env
runner_options[:server_timeout] = options.server_timeout
Expand Down
13 changes: 7 additions & 6 deletions lib/guard/jasmine/server.rb
Expand Up @@ -37,9 +37,9 @@ def start(options)
when :unicorn
start_unicorn_server(port, options)
when :jasmine_gem
start_rake_server(port, 'jasmine')
start_rake_server(port, 'jasmine', options)
else
start_rake_server(port, server.to_s) unless server == :none
start_rake_server(port, server.to_s, options) unless server == :none
end

wait_for_server(port, timeout) unless server == :none
Expand Down Expand Up @@ -76,7 +76,7 @@ def start_rack_server(server, port, options)

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

rescue => e
Expand All @@ -99,7 +99,7 @@ def start_unicorn_server(port, options)

self.process = ChildProcess.build('unicorn_rails', '-E', environment.to_s, '-p', port.to_s)
self.process.environment['COVERAGE'] = options[:coverage].to_s
self.process.io.inherit! if ::Guard.respond_to?(:options) && ::Guard.options && ::Guard.options[:verbose]
self.process.io.inherit! if options[:verbose]
self.process.start

rescue => e
Expand All @@ -110,12 +110,13 @@ def start_unicorn_server(port, options)
#
# @param [Number] port the server port
# @param [String] task the rake task name
# @option options [Symbol] server the rack server to use
#
def start_rake_server(port, task)
def start_rake_server(port, task, options)
::Guard::UI.info "Guard::Jasmine starts Jasmine Gem test server on port #{ port }."

self.process = ChildProcess.build('ruby', '-S', 'rake', task, "JASMINE_PORT=#{ port }")
self.process.io.inherit! if ::Guard.respond_to?(:options) && ::Guard.options && ::Guard.options[:verbose]
self.process.io.inherit! if options[:verbose]
self.process.start

rescue => e
Expand Down
10 changes: 10 additions & 0 deletions spec/guard/jasmine/cli_spec.rb
Expand Up @@ -64,6 +64,11 @@
cli.start(['spec', '--timeout', '20000'])
end

it 'sets the verbose mode' do
runner.should_receive(:run).with(anything(), hash_including(:verbose => true)).and_return [true, []]
cli.start(['spec', '--verbose'])
end

it 'sets the server environment' do
runner.should_receive(:run).with(anything(), hash_including(:server_env => 'development')).and_return [true, []]
cli.start(['spec', '--server-env', 'development'])
Expand Down Expand Up @@ -134,6 +139,11 @@
cli.start(['spec'])
end

it 'sets the verbose mode' do
runner.should_receive(:run).with(anything(), hash_including(:verbose => false)).and_return [true, []]
cli.start(['spec'])
end

it 'sets the coverage support' do
runner.should_receive(:run).with(anything(), hash_including(:coverage => false)).and_return [true, []]
cli.start(['spec'])
Expand Down
4 changes: 2 additions & 2 deletions spec/guard/jasmine/server_spec.rb
Expand Up @@ -274,7 +274,7 @@
end

it 'starts the :jasmine rake task server' do
server.should_receive(:start_rake_server).with(8888, 'jasmine')
server.should_receive(:start_rake_server).with(8888, 'jasmine', options)
server.start(options)
end
end
Expand All @@ -295,7 +295,7 @@
end

it 'starts a custom rake task server' do
server.should_receive(:start_rake_server).with(8888, 'custom_server_strategy')
server.should_receive(:start_rake_server).with(8888, 'custom_server_strategy', options)
server.start(options)
end
end
Expand Down

0 comments on commit a81e741

Please sign in to comment.