Skip to content

Commit

Permalink
Provide a Rake task that wraps the Thor CLI. (Fixes #30)
Browse files Browse the repository at this point in the history
  • Loading branch information
netzpirat committed Feb 1, 2012
1 parent 82d916a commit 2c77102
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 21 deletions.
56 changes: 42 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.
* Runs the standard Jasmine test runner, so you can use [Jasminerice][] for integrating [Jasmine][] into the
[Rails 3.1 asset pipeline][] and write your specs in [CoffeeScript][].

* Command line helper for CI server integration.
* Thor and Rake command line helper for CI server integration.

* Runs on Mac OS X, Linux and Windows.

Expand Down Expand Up @@ -332,7 +332,9 @@ So if you want to have a precise spec detection, you should:
To get a feeling how your naming strategy works, play with the web based Jasmine runner and modify the `spec` query
parameter.

## Guard::Jasmine for your CI server
## Guard::Jasmine outside of Guard

### Thor command line utility

Guard::Jasmine includes a little command line utility to run your specs once and output the specdoc to the console.

Expand All @@ -343,22 +345,26 @@ $ guard-jasmine
You can get help on the available options with the `help` task:

```bash
$ guard-jasmine help spec

Usage:
guard-jasmine spec

Options:
-s, [--server=SERVER] # Server to start, either `auto`, `none`, `webrick`, `mongrel`, `thin`, `jasmine_gem`
# Default: auto
-p, [--port=N] # Server port to use
# Default: 8888
-u, [--url=URL] # The url of the Jasmine test runner
# Default: http://127.0.0.1:8888/jasmine
-b, [--bin=BIN] # The location of the PhantomJS binary
# Default: /usr/local/bin/phantomjs
-t, [--timeout=N] # The maximum time in milliseconds to wait for the spec runner to finish
# Default: 10000
-c, [--console=CONSOLE] # Whether to show console.log statements in the spec runner, either `always`, `never` or `failure`
# Default: failure
-s, [--server=SERVER] # Server to start, either `auto`, `none`, `webrick`, `mongrel`, `thin`, `jasmine_gem`
# Default: auto
-p, [--port=N] # Server port to use
# Default: 8888
-u, [--url=URL] # The url of the Jasmine test runner
# Default: http://127.0.0.1:8888/jasmine
-b, [--bin=BIN] # The location of the PhantomJS binary
# Default: /usr/local/bin/phantomjs
-t, [--timeout=N] # The maximum time in milliseconds to wait for the spec runner to finish
# Default: 10000
-c, [--console=CONSOLE] # Whether to show console.log statements in the spec runner, either `always`, `never` or `failure`
# Default: failure
-e, [--server-env=SERVER_ENV] # The server environment to use, for example `development`, `test` etc.
# Default: test

Run the Jasmine spec runner
```
Expand All @@ -369,6 +375,28 @@ By default all specs are run, but you can supply multiple paths to your specs to
$ guard-jasmine spec/javascripts/a_spec.js.coffee spec/javascripts/another_spec.js.coffee
```

### Rake task integration

Guard::Jasmine provides a Rake task wrapper around the Thor command line utility. Simply create a JasmineTask within
your `Rakefile`:

```ruby
require 'guard/jasmine/task'
Guard::JasmineTask.new
```

You can configure the CLI options either by providing the options as parameter or use a block:

```ruby
require 'guard/jasmine/task'

Guard::JasmineTask.new do |task|
task.options = '-t 15 -e test'
end

Guard::JasmineTask.new(:jasmine_no_server, '-s none')
```

### Travis CI integration

With the given `guard-jasmine` script you're able to configure [Travis CI](http://travis-ci.org/) to run Guard::Jasmine.
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/jasmine/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CLI < Thor
method_option :server_env,
:type => :string,
:aliases => '-e',
:default => 'development',
:default => 'test',
:desc => 'The server environment to use, for example `development`, `test` etc.'

# Run the Guard::Jasmine::Runner with options from
Expand Down
42 changes: 42 additions & 0 deletions lib/guard/jasmine/task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env ruby

require 'rake'
require 'rake/tasklib'

require 'guard/jasmine/cli'

module Guard

# Provides a method to define a Rake task that
# runs the Jasmine specs.
#
class JasmineTask < ::Rake::TaskLib

# Name of the main, top level task
attr_accessor :name

# CLI options
attr_accessor :options

# Initialize the Rake task
#
# @param [Symbol] name the name of the Rake task
# @param [String] options the CLI options
# @yield [JasmineTask] the task
#
def initialize(name = :jasmine, options = '')
@name = name
@options = options

yield self if block_given?

namespace :guard do
desc 'Run all Jasmine specs'
task(name) do
Guard::Jasmine::CLI.start(options.split)
end
end
end

end
end
12 changes: 6 additions & 6 deletions spec/guard/jasmine/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
context 'with specified options' do
context 'for the server' do
it 'sets the server type' do
server.should_receive(:start).with(:thin, 8888, 'development')
server.should_receive(:start).with(:thin, 8888, 'test')
cli.start(['spec', '--server', 'thin'])
end

it 'sets the server port' do
server.should_receive(:start).with(:auto, 4321, 'development')
server.should_receive(:start).with(:auto, 4321, 'test')
cli.start(['spec', '--port', '4321'])
end
end
Expand All @@ -50,8 +50,8 @@
end

it 'sets the server environment' do
runner.should_receive(:run).with(anything(), hash_including(:server_env => 'test')).and_return [true, []]
cli.start(['spec', '--server_env', 'test'])
runner.should_receive(:run).with(anything(), hash_including(:server_env => 'development')).and_return [true, []]
cli.start(['spec', '--server_env', 'development'])
end

context 'for a valid console option' do
Expand All @@ -73,7 +73,7 @@
context 'without specified options' do
context 'for the server' do
it 'sets the server type' do
server.should_receive(:start).with(:auto, 8888, 'development')
server.should_receive(:start).with(:auto, 8888, 'test')
cli.start(['spec'])
end
end
Expand Down Expand Up @@ -105,7 +105,7 @@
end

it 'sets the server environment' do
runner.should_receive(:run).with(anything(), hash_including(:server_env => 'development')).and_return [true, []]
runner.should_receive(:run).with(anything(), hash_including(:server_env => 'test')).and_return [true, []]
cli.start(['spec'])
end
end
Expand Down

0 comments on commit 2c77102

Please sign in to comment.