Compare commits

..

No commits in common. "master" and "rails-assets" have entirely different histories.

27 changed files with 220 additions and 543 deletions

2
.gitignore vendored
View File

@ -2,5 +2,3 @@
.bundle
Gemfile.lock
pkg/*
*.orig

17
Gemfile
View File

@ -2,19 +2,10 @@ source "http://rubygems.org"
# Specify your gem's dependencies in guard-jasmine-headless-webkit.gemspec
gemspec
gem 'rake', '0.9.2'
gem 'guard', :git => 'https://github.com/guard/guard.git'
gem 'rspec'
gem 'cucumber'
gem 'mocha'
gem 'fakefs', :require => nil
gem 'jasmine-headless-webkit', :path => '../jasmine-headless-webkit'
gem 'guard', :git => 'git://github.com/guard/guard.git'
gem 'guard-rspec'
gem 'guard-cucumber'
gem 'rake', '0.8.7'
gem 'growl'
gem 'rb-fsevent'
gem 'fakefs', :require => nil
gem 'jasmine-headless-webkit', :path => '../jasmine-headless-webkit'

View File

@ -5,11 +5,13 @@ guard 'rspec', :cli => '-c', :version => 2 do
watch(%r{^spec/.+_spec\.rb})
watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end
guard 'cucumber', :cli => '-f pretty' do
watch(%r{^features/.+\.feature$})
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
# Rails example
watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
watch(%r{^spec/.+_spec\.rb})
watch(%r{^app/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
end

View File

@ -1,20 +0,0 @@
Copyright (c) 2011 John Bintz
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -2,11 +2,9 @@
Add running your Jasmine specs to your `Guardfile` via [`jasmine-headless-webkit`](http://github.com/johnbintz/jasmine-headless-webkit/). Nice!
``` ruby
guard 'jasmine-headless-webkit' do
watch(%r{^app/assets/javascripts/(.*)\..*}) { |m| newest_js_file("spec/javascripts/#{m[1]}_spec") }
end
```
`gem install guard-jasmine-headless-webkit` and then `guard init jasmine-headless-webkit` in your project directory to get started.
You should also put it in your `Gemfile` because, hey, why not, right?
@ -17,31 +15,14 @@ home folder's `.jasmine-headless-webkit` file.
## `guard` options
* `:all_on_start => false` to not run everything when starting, just like `guard-rspec`.
* `:rails_assets => true` to repackage Rails assets before each run.
* `:run_before => "<command to run>"` to run a command before running specs. If the command fails, the test run stops.
* `:valid_extensions => %w{js coffee}` to only trigger `run_on_change` events for files with these extensions. Forces Guard to re-run all tests when any other matched file changes.
* All other options from `Jasmine::Headless::Runner`: (see the [list of available options](https://github.com/johnbintz/jasmine-headless-webkit/blob/master/lib/jasmine/headless/options.rb#L11A))
## Using with .erb files in the Rails 3.1 Asset Pipeline and/or Jammit
### Deprecated options
If your code required Jammit or ERB templates, which aren't directly supported by `jasmine-headledd-webkit`,
use [`guard-rails-assets`](https://github.com/dnagir/guard-rails-assets) chained in before `guard-jasmine-headless-webkit` to precompile your application
code for testing:
``` ruby
guard 'rails-assets' do
watch(%r{^app/assets/javascripts/.*})
end
guard 'jasmine-headless-webkit' do
watch(%r{^public/assets/.*\.js})
... specs ...
end
```
Do the same for Jammit, using [`guard-jammit`](http://github.com/guard/guard-jammit).
### `guard-jammit` and Jammit >= 0.6.0
Jammit >= 0.6.0 changed how it determines the Rails environment. Use [my fork of `guard-jammit`](http://github.com/johnbintz/guard-jammit) until it's fixed upstream.
* `:jammit => true` to run `jammit -f 2>/dev/null` before the tests for the current file change are run.
* Use [guard-jammit](http://github.com/guard/guard-jammit) instead.
## What's the deal with `newest_js_file`?
@ -53,8 +34,12 @@ file is a little more complicated. `newest_js_file` extends the Guard DSL to sea
If you 100% know you won't need that support, modify your `Guardfile` as appropriate.
## License
## ...and the `.jst` file search?
This library is released under the MIT license:
I use [Backbone.js](http://documentcloud.github.com/backbone/) a lot, and I put my Underscore view templates in `app/views/*.jst`
and mash them all together with [Jammit](https://github.com/documentcloud/jammit) for use in my apps. Feel free to change that, it's your `Guardfile` after all.
Or, try it. It's easy to do in your `assets.yml` file:
templates:
- app/views/*.jst
* http://www.opensource.org/licenses/MIT

View File

@ -1,8 +1,6 @@
require 'bundler'
Bundler::GemHelper.install_tasks
include Rake::DSL if defined?(Rake::DSL)
desc 'Push everywhere!'
task :push_everywhere do
system %{git push origin master}
@ -13,26 +11,27 @@ require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
PLATFORMS = %w{1.8.7 1.9.2 ree 1.9.3}
def rvm_bundle(command = '')
Bundler.with_clean_env do
system %{bash -c 'unset BUNDLE_BIN_PATH && unset BUNDLE_GEMFILE && rvm #{PLATFORMS.join(',')} do bundle #{command}'}
end
end
class SpecFailure < StandardError; end
class BundleFailure < StandardError; end
namespace :spec do
desc "Run on three Rubies"
task :platforms do
rvm_bundle "update"
rvm_bundle "exec rspec spec"
rvm_bundle "exec cucumber"
raise SpecError.new if $?.exitstatus != 0
current = %x{rvm-prompt v}
fail = false
%w{1.8.7 1.9.2 ree}.each do |version|
puts "Switching to #{version}"
Bundler.with_clean_env do
system %{bash -c 'source ~/.rvm/scripts/rvm && rvm #{version} && bundle exec rake spec'}
end
if $?.exitstatus != 0
fail = true
break
end
end
system %{rvm #{current}}
exit (fail ? 1 : 0)
end
end
task :default => 'spec:platforms'

View File

@ -1,33 +0,0 @@
Feature: Runner
Scenario: Don't specify a reporter
Given I am going to call a JHW runner with the following reporters:
| name | file |
| Console | |
| File | notify-file |
And I am going to get a notification file
When I don't specify a reporter
And I run the runner
Then I should get the reporters
Scenario: Specify another console reporter
Given I am going to call a JHW runner with the following reporters:
| name | file |
| Verbose | |
| File | notify-file |
And I am going to get a notification file
When I specify the reporter "Verbose"
And I run the runner
Then I should get the reporters
And the reporter string should not have changed
Scenario: Specify two reporters
Given I am going to call a JHW runner with the following reporters:
| name | file |
| Verbose | |
| Tap | tap-file |
| File | notify-file |
And I am going to get a notification file
When I specify the reporter "Verbose Tap:tap-file"
And I run the runner
Then I should get the reporters

View File

@ -1,13 +0,0 @@
Given /^I am going to call a JHW runner with the following reporters:$/ do |table|
reporters = []
table.rows.each do | name, file |
reporters << [ name ]
reporters.last << file if !file.empty?
end
Jasmine::Headless::Runner.expects(:run).with(has_entry(:reporters => reporters))
Guard::JasmineHeadlessWebkit::Runner.expects(:notify)
end

View File

@ -1,3 +0,0 @@
Given /^I am going to get a notification file$/ do
Guard::JasmineHeadlessWebkit::Runner.stubs(:notify_report_file).returns(@report_file)
end

View File

@ -1,3 +0,0 @@
Then /^I should get the reporters$/ do
end

View File

@ -1,3 +0,0 @@
Then /^the reporter string should not have changed$/ do
@options[:reporters].should == @requested_reporter
end

View File

@ -1,3 +0,0 @@
When /^I don't specify a reporter$/ do
@options = {}
end

View File

@ -1,3 +0,0 @@
When /^I run the runner$/ do
Guard::JasmineHeadlessWebkit::Runner.run(@paths, @options)
end

View File

@ -1,6 +0,0 @@
When /^I specify the reporter "([^"]*)"$/ do |reporter|
@requested_reporter = reporter
@options = { :reporters => reporter }
end

View File

@ -1,30 +0,0 @@
require 'rspec'
require 'mocha'
require 'fakefs/safe'
require 'jasmine-headless-webkit'
require 'guard/jasmine-headless-webkit'
require 'coffee-script'
World(Mocha::API)
Before do
mocha_setup
FakeFS.activate!
@report_file = 'notify-file'
@paths = []
end
After do
begin
mocha_verify
ensure
mocha_teardown
end
FakeFS.deactivate!
end

View File

@ -1,8 +1,10 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "guard/jasmine-headless-webkit/version"
Gem::Specification.new do |s|
s.name = "guard-jasmine-headless-webkit"
s.version = '0.4.0.rc1'
s.version = Guard::JasmineHeadlessWebkitVersion::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["John Bintz"]
s.email = ["john@coswellproductions.com"]
@ -17,7 +19,6 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.add_runtime_dependency 'guard', '>= 0.4.0'
s.add_runtime_dependency 'jasmine-headless-webkit', '>= 0.7.0'
s.add_dependency 'guard', '>= 0.4.0'
s.add_dependency 'jasmine-headless-webkit', '>= 0.3.0'
end

View File

@ -1,32 +1,18 @@
require 'guard'
require 'guard/guard'
require 'coffee-script'
require 'guard/jasmine-headless-webkit/runner'
module Guard
class JasmineHeadlessWebkit < Guard
autoload :Runner, 'guard/jasmine-headless-webkit/runner'
DEFAULT_EXTENSIONS = %w{js coffee}
ALL_SPECS_MESSAGE = "Guard::JasmineHeadlessWebkit running all specs..."
SOME_SPECS_MESSAGE = "Guard::JasmineHeadlessWebkit running the following: %s"
attr_reader :files_to_rerun
DEFAULT_OPTIONS = {
:all_on_start => true,
:run_before => false,
:valid_extensions => DEFAULT_EXTENSIONS
}
def initialize(watchers = [], options = {})
super
@options = DEFAULT_OPTIONS.merge(options)
@filtered_options = options
DEFAULT_OPTIONS.keys.each { |key| @filtered_options.delete(key) }
@files_to_rerun = []
@options = {
:all_on_start => true,
:run_before => false,
:valid_extensions => DEFAULT_EXTENSIONS
}.merge(options)
end
def start
@ -34,23 +20,20 @@ module Guard
run_all if @options[:all_on_start]
end
def reload
@files_to_rerun = []
UI.info "Resetting Guard::JasmineHeadlessWebkit failed files..."
end
def run_all
run_something_and_rescue do
run_for_failed_files
end
UI.info "Guard::JasmineHeadlessWebkit running all specs..."
JasmineHeadlessWebkitRunner.run if run_all_things_before
@ran_before = false
end
def run_on_change(paths)
run_something_and_rescue do
if !(paths = filter_paths(paths)).empty?
paths = (paths + @files_to_rerun).uniq
run_for_failed_files(paths)
paths = filter_paths(paths)
@ran_before = false
if run_all_things_before
@ran_before = true
if !paths.empty?
UI.info "Guard::JasmineHeadlessWebkit running the following: #{paths.join(' ')}"
JasmineHeadlessWebkitRunner.run(paths)
else
run_all
end
@ -58,45 +41,45 @@ module Guard
end
private
def run_for_failed_files(paths = [])
if paths.empty?
UI.info(ALL_SPECS_MESSAGE)
else
UI.info(SOME_SPECS_MESSAGE % paths.join(' '))
end
failed_files = Runner.run(paths, @filtered_options)
@files_to_rerun = failed_files || paths
failed_files && @files_to_rerun.empty?
end
def filter_paths(paths)
paths.collect { |path| Dir[path] }.flatten.find_all { |path| File.extname(path)[valid_extensions] }.collect { |path| File.expand_path(path) }.uniq
paths.find_all { |path| File.extname(path)[valid_extensions] }
end
def valid_extensions
%r{\.(#{@options[:valid_extensions].join('|')})$}
end
def run_before
run_a_thing_before(:run_before, @options[:run_before])
end
def run_jammit
$stderr.puts "Jammit support is deprecated and will be removed in the future. Use guard-jammit instead." if @options[:jammit]
run_a_thing_before(:jammit, "Jammit", %{jammit -f 2>/dev/null})
end
def run_rails_assets
run_a_thing_before(:rails_assets, "Rails Assets", %{rake assets:precompile:for_testing})
end
def run_a_thing_before(option, *args)
if @options[option] && !@ran_before
run_program(*args)
else
true
end
end
def run_all_things_before
run_before and run_rails_assets and run_jammit
end
def run_program(name, command = nil)
command ||= name
UI.info "Guard::JasmineHeadlessWebkit running #{name}..."
system command
$?.exitstatus == 0
end
def run_something_and_rescue
yield
rescue ::CoffeeScript::CompilationError
rescue StandardError => e
if ENV['GUARD_ENV'] == 'test'
raise e
else
puts e.message
puts e.backtrace.join("\n")
puts
end
end
end
class Dsl

View File

@ -1,60 +1,37 @@
require 'guard/notifier'
require 'jasmine-headless-webkit'
require 'jasmine/headless/runner'
module Guard
class JasmineHeadlessWebkit
class Runner
def self.run(paths = [], options = {})
report_file = notify_report_file
options = options.merge(:reporters => process_reporters(options[:reporters], report_file), :colors => true, :files => paths)
Jasmine::Headless::Runner.run(options)
notify(report_file)
end
def self.notify_report_file
class JasmineHeadlessWebkitRunner
class << self
def run(paths = [])
file = Tempfile.new('guard-jasmine-headless-webkit')
file.close
file.path
Jasmine::Headless::Runner.run(:report => file.path, :colors => true, :files => paths)
notify(file.path)
end
def self.process_reporters(reporters, report_file)
reporters ||= 'Console'
out = []
reporters.split(' ').each do |reporter|
name, file = reporter.split(':', 2)
out << [ name ]
out.last << file if file && !file.empty?
end
out + [ [ 'File', report_file ] ]
end
def self.notify(file)
if (report = Jasmine::Headless::Report.load(file)).valid?
Notifier.notify(message(report.total, report.failed, report.time, report.has_used_console?), :title => 'Jasmine results', :image => image(report.has_used_console?, report.failed))
report.failed_files
else
raise Jasmine::Headless::InvalidReport
end
rescue Jasmine::Headless::InvalidReport => e
def notify(file)
if (data = File.read(file).strip).empty?
Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed)
false
else
total, fails, any_console, secs = File.read(file).strip.split('/')
Notifier.notify(message(total, fails, secs, any_console == "T"), :title => 'Jasmine results', :image => image(any_console == "T", fails))
fails.to_i
end
end
private
def self.message(total, fails, secs, any_console)
def message(total, fails, secs, any_console)
total_word = (total.to_i == 1) ? "test" : "tests"
"#{total} #{total_word}, #{fails} failures, #{secs} secs#{any_console ? ', console.log used' : ''}."
end
def self.image(any_console, fails)
def image(any_console, fails)
if any_console
:pending
else
@ -68,3 +45,4 @@ module Guard
end
end
end

View File

@ -1,4 +1,4 @@
# Run JS and CoffeeScript files in a typical Rails 3.1/Sprockets fashion.
# Run JS and CoffeeScript files in a typical Rails 3.1 fashion, placing Underscore templates in app/views/*.jst
# Your spec files end with _spec.{js,coffee}.
spec_location = "spec/javascripts/%s_spec"
@ -7,7 +7,9 @@ spec_location = "spec/javascripts/%s_spec"
# spec_location = "spec/javascripts/%sSpec"
guard 'jasmine-headless-webkit' do
watch(%r{^(app|lib|vendor)/assets/javascripts/(.*)$}) { |m| newest_js_file(spec_location % m[1]) }
watch(%r{^spec/javascripts/(.*)[Ss]pec\..*}) { |m| newest_js_file(spec_location % m[1]) }
watch(%r{^app/views/.*\.jst$})
watch(%r{^public/javascripts/(.*)\.js$}) { |m| newest_js_file(spec_location % m[1]) }
watch(%r{^app/assets/javascripts/(.*)\.(js|coffee)$}) { |m| newest_js_file(spec_location % m[1]) }
watch(%r{^spec/javascripts/(.*)_spec\..*}) { |m| newest_js_file(spec_location % m[1]) }
end

View File

@ -0,0 +1,5 @@
module Guard
module JasmineHeadlessWebkitVersion
VERSION = "0.1.1"
end
end

View File

@ -1,11 +0,0 @@
#!/usr/bin/env ruby
require 'rubygems'
require 'penchant'
if Penchant::Gemfile.do_full_env_switch!(ARGV[0])
puts "Gemfile switched to #{ARGV[0]}"
else
exit 0
end

View File

@ -1,15 +0,0 @@
#!/bin/bash
OLD_GIT_DIR=$GIT_DIR
if [ "$(penchant gemfile-env)" != "remote" ]; then
unset GIT_DIR
penchant gemfile remote
GIT_DIR=$OLD_GIT_DIR
git add Gemfile*
fi
bundle exec rake
R=$?
if [ $R -ne 0 ]; then exit $R; fi

View File

@ -1,35 +0,0 @@
#!/usr/bin/env ruby
if File.file?('Gemfile.erb')
pwd = Dir.pwd
Dir.chdir '..' do
File.readlines(File.join(pwd, 'Gemfile.erb')).find_all { |line| line[':git'] }.each do |line|
repo = line[%r{:git => (['"])(.*)\1}, 2]
puts "Installing #{repo}"
system %{git clone #{repo}}
end
end
puts "Bundling for local environment"
system %{script/gemfile local}
else
puts "Bundling..."
system %{bundle}
end
puts "Installing git hooks"
system %{script/install-git-hooks}
bundle = File.file?('Gemfile') ? 'bundle exec' : ''
command = [ bundle, 'rake', '-s', '-T', 'bootstrap' ]
if !(%x{#{command.join(' ')}}).empty?
puts "Trying to run rake bootstrap..."
system %{#{bundle} rake bootstrap}
end
puts "Done!"

View File

@ -1,6 +0,0 @@
#!/bin/bash
for hook in script/hooks/* ; do
ln -sf $PWD/$hook .git/hooks/${hook##*/}
done

View File

@ -1,44 +1,8 @@
require 'spec_helper'
require 'guard/jasmine-headless-webkit/runner'
require 'fakefs/spec_helpers'
describe Guard::JasmineHeadlessWebkit::Runner do
describe '.run' do
let(:reporter) { 'reporter' }
before do
described_class.stubs(:process_reporters).returns([ reporter ])
end
it 'should pass along options' do
Jasmine::Headless::Runner.expects(:run).with(all_of(has_key(:full_run), has_entry(:reporters => [ reporter ])))
Guard::JasmineHeadlessWebkit::Runner.run([], :full_run => false)
end
end
describe '.process_reporters' do
subject { described_class.process_reporters(reporters, report_file) }
let(:report_file) { 'report file' }
context 'none provided' do
let(:reporters) { nil }
it { should == [ [ 'Console' ], [ 'File', report_file ] ] }
end
context 'one provided' do
let(:reporters) { 'One' }
it { should == [ [ 'One' ], [ 'File', report_file ] ] }
end
context 'two provided' do
let(:reporters) { 'One Two:file.txt' }
it { should == [ [ 'One' ], [ 'Two', 'file.txt' ], [ 'File', report_file ] ] }
end
end
describe Guard::JasmineHeadlessWebkitRunner do
describe '.notify' do
include FakeFS::SpecHelpers
@ -49,25 +13,12 @@ describe Guard::JasmineHeadlessWebkit::Runner do
end
context 'system run not interrupted' do
let(:data) { 'TOTAL||1||0||5||F' }
let(:data) { '1/0/F/5' }
it 'should notify with the right information' do
Guard::Notifier.expects(:notify).with("1 test, 0 failures, 5.0 secs.", { :title => 'Jasmine results', :image => :success })
Guard::Notifier.expects(:notify).with("1 test, 0 failures, 5 secs.", { :title => 'Jasmine results', :image => :success })
Guard::JasmineHeadlessWebkit::Runner.notify(file).should == []
end
end
context 'with failures' do
let(:data) { <<-REPORT }
FAIL||Test||Two||file.js:50
TOTAL||1||1||5||F
REPORT
it 'should notify with the right information' do
Guard::Notifier.expects(:notify).with("1 test, 1 failures, 5.0 secs.", { :title => 'Jasmine results', :image => :failed })
Guard::JasmineHeadlessWebkit::Runner.notify(file).should == [ 'file.js' ]
Guard::JasmineHeadlessWebkitRunner.notify(file)
end
end
@ -77,7 +28,7 @@ REPORT
it 'should notify failure' do
Guard::Notifier.expects(:notify).with("Spec runner interrupted!", { :title => 'Jasmine results', :image => :failed })
Guard::JasmineHeadlessWebkit::Runner.notify(file).should be_false
Guard::JasmineHeadlessWebkitRunner.notify(file)
end
end
end

View File

@ -1,4 +1,5 @@
require 'spec_helper'
require 'guard/jasmine-headless-webkit'
describe Guard::JasmineHeadlessWebkit do
let(:guard) { Guard::JasmineHeadlessWebkit.new([], options) }
@ -25,158 +26,127 @@ describe Guard::JasmineHeadlessWebkit do
end
end
describe '#run_all' do
before do
guard.stubs(:run_all_things_before).returns(true)
end
context 'fails' do
it 'should return false' do
Guard::JasmineHeadlessWebkit::Runner.stubs(:run).returns(['file.js'])
guard.run_all.should be_false
guard.files_to_rerun.should == ['file.js']
end
end
context 'succeeds' do
it 'should return true' do
Guard::JasmineHeadlessWebkit::Runner.stubs(:run).returns([])
guard.run_all.should be_true
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::JasmineHeadlessWebkit::Runner.expects(:run).with([], :full_run => false)
guard.run_all
end
end
end
describe '#run_on_change' do
include FakeFS::SpecHelpers
let(:one_file) { %w{test.js} }
def absolute(file)
case file
when Array
file.collect { |f| absolute(f) }
else
File.expand_path(file)
end
end
before do
File.open(one_file.first, 'wb')
end
context 'two files' do
it "should only run one" do
Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(one_file), {}).returns(one_file)
guard.run_on_change(%w{test.js test.js}).should be_false
guard.files_to_rerun.should == one_file
end
end
context 'one file no priors' do
context 'jhw call fails' do
it "should not run all" do
Guard::JasmineHeadlessWebkit::Runner.expects(:run).returns(one_file)
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(1)
guard.expects(:run_all).never
guard.run_on_change(one_file).should be_false
guard.files_to_rerun.should == one_file
end
end
context 'one file one prior' do
it "should not run all" do
guard.instance_variable_set(:@files_to_rerun, [ "two.js" ])
Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(one_file) + [ "two.js" ], {}).returns(one_file)
guard.run_on_change(one_file).should be_false
guard.files_to_rerun.should == one_file
end
end
context 'failed hard' do
it "should not run all" do
guard.instance_variable_set(:@files_to_rerun, absolute(one_file))
Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(one_file), {}).returns(false)
guard.run_on_change(one_file).should be_false
guard.files_to_rerun.should == absolute(one_file)
guard.run_on_change(%w{test.js})
end
end
context 'succeed, but still do not run all' do
it "should run all" do
Guard::JasmineHeadlessWebkit::Runner.expects(:run).returns([])
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(0)
guard.expects(:run_all).never
guard.run_on_change(one_file).should be_true
guard.files_to_rerun.should == []
guard.run_on_change(%w{test.js})
end
end
context 'no files given, just run all' do
it 'should run all but not run once' do
Guard::JasmineHeadlessWebkit::Runner.expects(:run).never
guard.expects(:run_all).once.returns(true)
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
guard.expects(:run_all).once
guard.run_on_change([]).should be_true
guard.files_to_rerun.should == []
guard.run_on_change([])
end
end
context "Files I don't care about given, ignore" do
it 'should run all but not run once' do
Guard::JasmineHeadlessWebkit::Runner.expects(:run).never
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
guard.expects(:run_all).once
guard.run_on_change(%w{test.jst})
guard.files_to_rerun.should == []
end
end
end
context 'glob given' do
let(:files) { %w{file1.js file2.js other.js} }
context 'with run_before' do
context 'with failing command' do
before do
files.each { |file| File.open(file, 'wb') }
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
Guard::UI.expects(:info).with(regexp_matches(/false/))
Guard::UI.expects(:info).with(regexp_matches(/running all/))
end
context 'not a duplicate' do
it 'should expand the glob' do
Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(%w{file1.js file2.js}), {}).returns(false)
let(:options) { { :run_before => 'false' } }
guard.run_on_change(%w{file*.js})
it "should run the command first" do
guard.run_all
end
end
context 'a duplicate' do
it 'should expand the glob and uniq' do
guard.instance_variable_set(:@files_to_rerun, absolute(%w{file1.js}))
Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(%w{file1.js file2.js}), {}).returns(false)
guard.run_on_change(%w{file*.js})
context 'with succeeding command' do
before do
Guard::JasmineHeadlessWebkitRunner.expects(:run).once
Guard::UI.expects(:info).with(regexp_matches(/true/))
Guard::UI.expects(:info).with(regexp_matches(/running all/))
end
let(:options) { { :run_before => 'true' } }
it "should run the command first" do
guard.run_all
end
end
end
describe '#reload' do
it 'should reset the state of the files_to_rerun' do
Guard::UI.expects(:info).with(regexp_matches(/Resetting/))
describe 'run jammit first' do
context 'run on run_all if called first' do
before do
guard.expects(:run_program).once.with('Jammit', regexp_matches(/jammit/)).returns(true)
Guard::JasmineHeadlessWebkitRunner.expects(:run).once
end
guard.instance_variable_set(:@files_to_rerun, "test")
guard.reload
guard.files_to_rerun.should == []
let(:options) { { :jammit => true } }
it "should run jammit first" do
guard.run_all
end
end
context 'only run once if run_on_change is successful' do
before do
guard.expects(:run_program).once.with('Jammit', regexp_matches(/jammit/)).returns(true)
Guard::JasmineHeadlessWebkitRunner.expects(:run).once.returns(0)
end
let(:options) { { :jammit => true } }
it "should run jammit only once" do
guard.run_on_change(%w{path.js})
end
end
end
describe 'run rails_assets first' do
context 'run on run_all if called first' do
before do
guard.expects(:run_program).with('Rails Assets', regexp_matches(/assets:precompile:for_testing/)).once.returns(true)
Guard::JasmineHeadlessWebkitRunner.expects(:run).once
end
let(:options) { { :rails_assets => true } }
it "should run rails assets first" do
guard.run_all
end
end
context 'only run once if run_on_change is successful' do
before do
guard.expects(:run_program).with('Rails Assets', regexp_matches(/assets:precompile:for_testing/)).once.returns(true)
Guard::JasmineHeadlessWebkitRunner.expects(:run).once.returns(0)
end
let(:options) { { :rails_assets => true } }
it "should run rails assets only once" do
guard.run_on_change(%w{path.js})
end
end
end
end

View File

@ -1,14 +1,10 @@
require 'mocha'
require 'guard'
require 'guard/jasmine-headless-webkit'
require 'fakefs/spec_helpers'
RSpec.configure do |config|
config.mock_with :mocha
end
ENV['GUARD_ENV'] = 'test'
module Guard
module UI
class << self