Skip to content

Commit

Permalink
pass other options into jhw
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbintz committed Sep 14, 2011
1 parent c2a3635 commit 9b6cb02
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
17 changes: 11 additions & 6 deletions lib/guard/jasmine-headless-webkit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ class JasmineHeadlessWebkit < Guard

attr_reader :files_to_rerun

DEFAULT_OPTIONS = {
:all_on_start => true,
:run_before => false,
:valid_extensions => DEFAULT_EXTENSIONS
}

def initialize(watchers = [], options = {})
super
@options = {
:all_on_start => true,
:run_before => false,
:valid_extensions => DEFAULT_EXTENSIONS
}.merge(options)

@options = DEFAULT_OPTIONS.merge(options)
@filtered_options = options
DEFAULT_OPTIONS.keys.each { |key| @filtered_options.delete(key) }

UI.deprecation ":run_before is deprecated. Use guard-shell to do something beforehand. This will be removed in a future release." if @options[:run_before]

Expand Down Expand Up @@ -68,7 +73,7 @@ def run_for_failed_files(paths = [])
UI.info(SOME_SPECS_MESSAGE % paths.join(' '))
end

if failed_files = JasmineHeadlessWebkitRunner.run(paths)
if failed_files = JasmineHeadlessWebkitRunner.run(paths, @filtered_options)
@files_to_rerun = failed_files
end

Expand Down
6 changes: 4 additions & 2 deletions lib/guard/jasmine-headless-webkit/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
module Guard
class JasmineHeadlessWebkitRunner
class << self
def run(paths = [])
def run(paths = [], options = {})
file = Tempfile.new('guard-jasmine-headless-webkit')
file.close

Jasmine::Headless::Runner.run(:report => file.path, :colors => true, :files => paths)
options.merge!(:report => file.path, :colors => true, :files => paths)

Jasmine::Headless::Runner.run(options)

notify(file.path)
end
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/guard/jasmine-headless-webkit/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
require 'fakefs/spec_helpers'

describe Guard::JasmineHeadlessWebkitRunner do
describe '.run' do
it 'should pass along options' do
Jasmine::Headless::Runner.expects(:run).with(has_key(:full_run))

Guard::JasmineHeadlessWebkitRunner.run([], :full_run => false)
end
end

describe '.notify' do
include FakeFS::SpecHelpers

Expand Down
16 changes: 13 additions & 3 deletions spec/lib/guard/jasmine-headless-webkit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,24 @@
guard.files_to_rerun.should == []
end
end

context 'pass along jhw options' do
let(:options) { { :all_on_start => false, :full_run => false } }

it 'should only pass along jhw options' do
Guard::JasmineHeadlessWebkitRunner.expects(:run).with([], :full_run => false)

guard.run_all
end
end
end

describe '#run_on_change' do
let(:one_file) { %w{test.js} }

context 'two files' do
it "should only run one" do
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file).returns(one_file)
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file, {}).returns(one_file)

guard.run_on_change(%w{test.js test.js}).should be_false
guard.files_to_rerun.should == one_file
Expand All @@ -83,7 +93,7 @@
context 'one file one prior' do
it "should not run all" do
guard.instance_variable_set(:@files_to_rerun, [ "two.js" ])
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file + [ "two.js" ]).returns(one_file)
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file + [ "two.js" ], {}).returns(one_file)

guard.run_on_change(one_file).should be_false
guard.files_to_rerun.should == one_file
Expand All @@ -93,7 +103,7 @@
context 'failed hard' do
it "should not run all" do
guard.instance_variable_set(:@files_to_rerun, one_file)
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file).returns(nil)
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file, {}).returns(nil)

guard.run_on_change(one_file).should be_false
guard.files_to_rerun.should == one_file
Expand Down

0 comments on commit 9b6cb02

Please sign in to comment.