├── .gitignore ├── script ├── install-git-hooks ├── gemfile ├── hooks │ └── pre-commit └── initialize-environment ├── spec ├── spec_helper.rb └── lib │ └── guard │ ├── jasmine-headless-webkit │ └── runner_spec.rb │ └── jasmine-headless-webkit_spec.rb ├── Gemfile ├── lib └── guard │ ├── jasmine-headless-webkit │ ├── templates │ │ └── Guardfile │ └── runner.rb │ └── jasmine-headless-webkit.rb ├── guard-jasmine-headless-webkit.gemspec ├── Guardfile ├── Rakefile └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | .bundle 3 | Gemfile.lock 4 | pkg/* 5 | *.orig 6 | 7 | -------------------------------------------------------------------------------- /script/install-git-hooks: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for hook in script/hooks/* ; do 4 | ln -sf $PWD/$hook .git/hooks/${hook##*/} 5 | done 6 | 7 | -------------------------------------------------------------------------------- /script/gemfile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'rubygems' 4 | require 'penchant' 5 | 6 | if Penchant::Gemfile.do_full_env_switch!(ARGV[0]) 7 | puts "Gemfile switched to #{ARGV[0]}" 8 | else 9 | exit 0 10 | end 11 | 12 | -------------------------------------------------------------------------------- /script/hooks/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | OLD_GIT_DIR=$GIT_DIR 4 | 5 | if [ "$(penchant gemfile-env)" != "remote" ]; then 6 | unset GIT_DIR 7 | penchant gemfile remote 8 | GIT_DIR=$OLD_GIT_DIR 9 | git add Gemfile* 10 | fi 11 | 12 | bundle exec rake 13 | R=$? 14 | if [ $R -ne 0 ]; then exit $R; fi 15 | 16 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'mocha' 2 | require 'guard' 3 | require 'guard/jasmine-headless-webkit' 4 | require 'fakefs/spec_helpers' 5 | 6 | RSpec.configure do |config| 7 | config.mock_with :mocha 8 | end 9 | 10 | ENV['GUARD_ENV'] = 'test' 11 | 12 | module Guard 13 | module UI 14 | class << self 15 | def info(*args) 16 | end 17 | end 18 | end 19 | end 20 | 21 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org" 2 | 3 | # Specify your gem's dependencies in guard-jasmine-headless-webkit.gemspec 4 | gemspec 5 | gem 'guard', :git => 'git://github.com/guard/guard.git' 6 | gem 'rspec' 7 | gem 'mocha' 8 | gem 'rake', '0.9.2' 9 | gem 'growl' 10 | gem 'fakefs', :require => nil 11 | gem 'jasmine-headless-webkit', :path => '../jasmine-headless-webkit' 12 | gem 'coffee-script' 13 | gem 'guard-rspec' 14 | -------------------------------------------------------------------------------- /lib/guard/jasmine-headless-webkit/templates/Guardfile: -------------------------------------------------------------------------------- 1 | # Run JS and CoffeeScript files in a typical Rails 3.1 fashion, placing Underscore templates in app/views/*.jst 2 | # Your spec files end with _spec.{js,coffee}. 3 | 4 | spec_location = "spec/javascripts/%s_spec" 5 | 6 | # uncomment if you use NerdCapsSpec.js 7 | # spec_location = "spec/javascripts/%sSpec" 8 | 9 | guard 'jasmine-headless-webkit' do 10 | watch(%r{^app/views/.*\.jst$}) 11 | watch(%r{^public/javascripts/(.*)\.js$}) { |m| newest_js_file(spec_location % m[1]) } 12 | watch(%r{^app/assets/javascripts/(.*?)\.(js(\.coffee)?|coffee)$}) { |m| newest_js_file(spec_location % m[1]) } 13 | watch(%r{^spec/javascripts/(.*)_spec\..*}) { |m| newest_js_file(spec_location % m[1]) } 14 | watch(%r{^spec/javascripts/helpers/(.*)}) { spec_location % '*' } 15 | end 16 | 17 | -------------------------------------------------------------------------------- /script/initialize-environment: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | if File.file?('Gemfile.erb') 4 | pwd = Dir.pwd 5 | 6 | Dir.chdir '..' do 7 | File.readlines(File.join(pwd, 'Gemfile.erb')).find_all { |line| line[':git'] }.each do |line| 8 | repo = line[%r{:git => (['"])(.*)\1}, 2] 9 | 10 | puts "Installing #{repo}" 11 | system %{git clone #{repo}} 12 | end 13 | end 14 | 15 | puts "Bundling for local environment" 16 | system %{script/gemfile local} 17 | else 18 | puts "Bundling..." 19 | system %{bundle} 20 | end 21 | 22 | puts "Installing git hooks" 23 | system %{script/install-git-hooks} 24 | 25 | bundle = File.file?('Gemfile') ? 'bundle exec' : '' 26 | 27 | command = [ bundle, 'rake', '-s', '-T', 'bootstrap' ] 28 | 29 | if !(%x{#{command.join(' ')}}).empty? 30 | puts "Trying to run rake bootstrap..." 31 | system %{#{bundle} rake bootstrap} 32 | end 33 | 34 | puts "Done!" 35 | 36 | -------------------------------------------------------------------------------- /guard-jasmine-headless-webkit.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | 3 | Gem::Specification.new do |s| 4 | s.name = "guard-jasmine-headless-webkit" 5 | s.version = '0.3.2' 6 | s.platform = Gem::Platform::RUBY 7 | s.authors = ["John Bintz"] 8 | s.email = ["john@coswellproductions.com"] 9 | s.homepage = "" 10 | s.summary = %q{Run jasmine-headless-webkit using guard} 11 | s.description = %q{Run jasmine-headless-webkit using guard} 12 | 13 | s.rubyforge_project = "guard-jasmine-headless-webkit" 14 | 15 | s.files = `git ls-files`.split("\n") 16 | s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") 17 | s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } 18 | s.require_paths = ["lib"] 19 | 20 | s.add_runtime_dependency 'guard', '>= 0.4.0' 21 | s.add_runtime_dependency 'jasmine-headless-webkit', '>= 0.7.0' 22 | end 23 | 24 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # A sample Guardfile 2 | # More info at https://github.com/guard/guard#readme 3 | 4 | guard 'rspec', :cli => '-c', :version => 2 do 5 | watch(%r{^spec/.+_spec\.rb}) 6 | watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" } 7 | watch('spec/spec_helper.rb') { "spec" } 8 | 9 | # Rails example 10 | watch('spec/spec_helper.rb') { "spec" } 11 | watch('config/routes.rb') { "spec/routing" } 12 | watch('app/controllers/application_controller.rb') { "spec/controllers" } 13 | watch(%r{^spec/.+_spec\.rb}) 14 | watch(%r{^app/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" } 15 | watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" } 16 | 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"] } 17 | end 18 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler' 2 | Bundler::GemHelper.install_tasks 3 | 4 | include Rake::DSL if defined?(Rake::DSL) 5 | 6 | desc 'Push everywhere!' 7 | task :push_everywhere do 8 | system %{git push origin master} 9 | system %{git push guard master} 10 | end 11 | 12 | require 'rspec/core/rake_task' 13 | 14 | RSpec::Core::RakeTask.new(:spec) 15 | 16 | PLATFORMS = %w{1.8.7 1.9.2 ree 1.9.3-rc1} 17 | 18 | def rvm_bundle(command = '') 19 | Bundler.with_clean_env do 20 | system %{bash -c 'unset BUNDLE_BIN_PATH && unset BUNDLE_GEMFILE && rvm #{PLATFORMS.join(',')} do bundle #{command}'}.tap { |o| p o } 21 | end 22 | end 23 | 24 | class SpecFailure < StandardError; end 25 | class BundleFailure < StandardError; end 26 | 27 | namespace :spec do 28 | desc "Run on three Rubies" 29 | task :platforms do 30 | rvm_bundle "update" 31 | rvm_bundle "exec rspec spec" 32 | raise SpecError.new if $?.exitstatus != 0 33 | end 34 | end 35 | 36 | task :default => 'spec:platforms' 37 | 38 | -------------------------------------------------------------------------------- /lib/guard/jasmine-headless-webkit/runner.rb: -------------------------------------------------------------------------------- 1 | require 'guard/notifier' 2 | require 'jasmine-headless-webkit' 3 | 4 | module Guard 5 | class JasmineHeadlessWebkit 6 | class Runner 7 | class << self 8 | def run(paths = [], options = {}) 9 | file = Tempfile.new('guard-jasmine-headless-webkit') 10 | file.close 11 | 12 | options.merge!(:report => file.path, :colors => true, :files => paths) 13 | 14 | Jasmine::Headless::Runner.run(options) 15 | 16 | notify(file.path) 17 | end 18 | 19 | def notify(file) 20 | if (report = Jasmine::Headless::Report.load(file)).valid? 21 | Notifier.notify(message(report.total, report.failed, report.time, report.has_used_console?), :title => 'Jasmine results', :image => image(report.has_used_console?, report.failed)) 22 | report.failed_files 23 | else 24 | raise Jasmine::Headless::InvalidReport 25 | end 26 | rescue Jasmine::Headless::InvalidReport => e 27 | Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed) 28 | false 29 | end 30 | 31 | private 32 | def message(total, fails, secs, any_console) 33 | total_word = (total.to_i == 1) ? "test" : "tests" 34 | 35 | "#{total} #{total_word}, #{fails} failures, #{secs} secs#{any_console ? ', console.log used' : ''}." 36 | end 37 | 38 | def image(any_console, fails) 39 | if any_console 40 | :pending 41 | else 42 | if fails.to_i == 0 43 | :success 44 | else 45 | :failed 46 | end 47 | end 48 | end 49 | end 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /spec/lib/guard/jasmine-headless-webkit/runner_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Guard::JasmineHeadlessWebkit::Runner do 4 | describe '.run' do 5 | it 'should pass along options' do 6 | Jasmine::Headless::Runner.expects(:run).with(has_key(:full_run)) 7 | 8 | Guard::JasmineHeadlessWebkit::Runner.run([], :full_run => false) 9 | end 10 | end 11 | 12 | describe '.notify' do 13 | include FakeFS::SpecHelpers 14 | 15 | let(:file) { 'temp.txt' } 16 | 17 | before do 18 | File.open(file, 'w') { |fh| fh.print data } 19 | end 20 | 21 | context 'system run not interrupted' do 22 | let(:data) { 'TOTAL||1||0||5||F' } 23 | 24 | it 'should notify with the right information' do 25 | Guard::Notifier.expects(:notify).with("1 test, 0 failures, 5.0 secs.", { :title => 'Jasmine results', :image => :success }) 26 | 27 | Guard::JasmineHeadlessWebkit::Runner.notify(file).should == [] 28 | end 29 | end 30 | 31 | context 'with failures' do 32 | let(:data) { <<-REPORT } 33 | FAIL||Test||Two||file.js:50 34 | TOTAL||1||1||5||F 35 | REPORT 36 | 37 | it 'should notify with the right information' do 38 | Guard::Notifier.expects(:notify).with("1 test, 1 failures, 5.0 secs.", { :title => 'Jasmine results', :image => :failed }) 39 | 40 | Guard::JasmineHeadlessWebkit::Runner.notify(file).should == [ 'file.js' ] 41 | end 42 | end 43 | 44 | context 'system run interrupted' do 45 | let(:data) { '' } 46 | 47 | it 'should notify failure' do 48 | Guard::Notifier.expects(:notify).with("Spec runner interrupted!", { :title => 'Jasmine results', :image => :failed }) 49 | 50 | Guard::JasmineHeadlessWebkit::Runner.notify(file).should be_false 51 | end 52 | end 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Guard support for jasmine-headless-webkit 2 | 3 | Add running your Jasmine specs to your `Guardfile` via [`jasmine-headless-webkit`](http://github.com/johnbintz/jasmine-headless-webkit/). Nice! 4 | 5 | guard 'jasmine-headless-webkit' do 6 | watch(%r{^app/assets/javascripts/(.*)\..*}) { |m| newest_js_file("spec/javascripts/#{m[1]}_spec") } 7 | end 8 | 9 | `gem install guard-jasmine-headless-webkit` and then `guard init jasmine-headless-webkit` in your project directory to get started. 10 | You should also put it in your `Gemfile` because, hey, why not, right? 11 | 12 | Output is colored by default. If you want it not colored, place a `--no-colors` option into the project's or your 13 | home folder's `.jasmine-headless-webkit` file. 14 | 15 | ## `guard` options 16 | 17 | * `:all_on_start => false` to not run everything when starting, just like `guard-rspec`. 18 | * `: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. 19 | 20 | ### Deprecated options 21 | * `:run_before => ""` to run a command before running specs. If the command fails, the test run stops. 22 | 23 | ## Using with Rails 3.1 and the Asset Pipeline and/or Jammit 24 | 25 | Use [`guard-rails-assets`](https://github.com/dnagir/guard-rails-assets) chained in before `guard-jasmine-headless-webkit` to precompile your application 26 | code for testing: 27 | 28 | guard 'rails-assets' do 29 | watch(%r{^app/assets/javascripts/.*}) 30 | end 31 | 32 | guard 'jasmine-headless-webkit' do 33 | watch(%r{^public/assets/.*\.js}) 34 | ... specs ... 35 | end 36 | 37 | Do the same for Jammit, using [`guard-jammit`](http://github.com/guard/guard-jammit). 38 | 39 | ### `guard-jammit` and Jammit >= 0.6.0 40 | 41 | 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. 42 | 43 | ## What's the deal with `newest_js_file`? 44 | 45 | Since one could, theoretically, have a CoffeeScript app file and a JavaScript spec file (or vice versa), the search for the correct matching 46 | file is a little more complicated. `newest_js_file` extends the Guard DSL to search the given path for the newest `.js` or `.coffee` file: 47 | 48 | newest_js_file('spec/javascripts/models/my_model') 49 | #=> search for Dir['spec/javascripts/models/my_model*.{js,coffee}'] and return the newest file found 50 | 51 | If you 100% know you won't need that support, modify your `Guardfile` as appropriate. 52 | 53 | ## ...and the `.jst` file search? 54 | 55 | I use [Backbone.js](http://documentcloud.github.com/backbone/) a lot, and I put my Underscore view templates in `app/views/*.jst` 56 | 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. 57 | Or, try it. It's easy to do in your `assets.yml` file: 58 | 59 | templates: 60 | - app/views/*.jst 61 | 62 | -------------------------------------------------------------------------------- /lib/guard/jasmine-headless-webkit.rb: -------------------------------------------------------------------------------- 1 | require 'guard' 2 | require 'guard/guard' 3 | require 'coffee-script' 4 | 5 | module Guard 6 | class JasmineHeadlessWebkit < Guard 7 | autoload :Runner, 'guard/jasmine-headless-webkit/runner' 8 | 9 | DEFAULT_EXTENSIONS = %w{js coffee} 10 | 11 | ALL_SPECS_MESSAGE = "Guard::JasmineHeadlessWebkit running all specs..." 12 | SOME_SPECS_MESSAGE = "Guard::JasmineHeadlessWebkit running the following: %s" 13 | 14 | attr_reader :files_to_rerun 15 | 16 | DEFAULT_OPTIONS = { 17 | :all_on_start => true, 18 | :run_before => false, 19 | :valid_extensions => DEFAULT_EXTENSIONS 20 | } 21 | 22 | def initialize(watchers = [], options = {}) 23 | super 24 | 25 | @options = DEFAULT_OPTIONS.merge(options) 26 | @filtered_options = options 27 | DEFAULT_OPTIONS.keys.each { |key| @filtered_options.delete(key) } 28 | 29 | 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] 30 | 31 | @files_to_rerun = [] 32 | end 33 | 34 | def start 35 | UI.info "Guard::JasmineHeadlessWebkit is running." 36 | run_all if @options[:all_on_start] 37 | end 38 | 39 | def reload 40 | @files_to_rerun = [] 41 | UI.info "Resetting Guard::JasmineHeadlessWebkit failed files..." 42 | end 43 | 44 | def run_all 45 | run_something_and_rescue do 46 | @ran_before = false 47 | 48 | run_for_failed_files if run_all_things_before 49 | end 50 | end 51 | 52 | def run_on_change(paths) 53 | run_something_and_rescue do 54 | paths = filter_paths(paths) 55 | @ran_before = false 56 | if run_all_things_before 57 | @ran_before = true 58 | if !paths.empty? 59 | paths = (paths + @files_to_rerun).uniq 60 | 61 | run_for_failed_files(paths) 62 | else 63 | run_all 64 | end 65 | end 66 | end 67 | end 68 | 69 | private 70 | def run_for_failed_files(paths = []) 71 | if paths.empty? 72 | UI.info(ALL_SPECS_MESSAGE) 73 | else 74 | UI.info(SOME_SPECS_MESSAGE % paths.join(' ')) 75 | end 76 | failed_files = Runner.run(paths, @filtered_options) 77 | @files_to_rerun = failed_files || paths 78 | 79 | failed_files && @files_to_rerun.empty? 80 | end 81 | 82 | def filter_paths(paths) 83 | paths.collect { |path| Dir[path] }.flatten.find_all { |path| File.extname(path)[valid_extensions] }.collect { |path| File.expand_path(path) }.uniq 84 | end 85 | 86 | def valid_extensions 87 | %r{\.(#{@options[:valid_extensions].join('|')})$} 88 | end 89 | 90 | def run_before 91 | run_a_thing_before(:run_before, @options[:run_before]) 92 | end 93 | 94 | def run_a_thing_before(option, *args) 95 | if @options[option] && !@ran_before 96 | run_program(*args) 97 | else 98 | true 99 | end 100 | end 101 | 102 | def run_all_things_before 103 | run_before 104 | end 105 | 106 | def run_program(name, command = nil) 107 | command ||= name 108 | UI.info "Guard::JasmineHeadlessWebkit running #{name}..." 109 | system command 110 | $?.exitstatus == 0 111 | end 112 | 113 | def run_something_and_rescue 114 | yield 115 | rescue ::CoffeeScript::CompilationError 116 | rescue StandardError => e 117 | if ENV['GUARD_ENV'] == 'test' 118 | raise e 119 | else 120 | puts e.message 121 | puts e.backtrace.join("\n") 122 | puts 123 | end 124 | end 125 | end 126 | 127 | class Dsl 128 | def newest_js_file(path) 129 | Dir[path + '*.{js,coffee}'].sort { |left, right| File.mtime(right) <=> File.mtime(left) }.first 130 | end 131 | end 132 | end 133 | 134 | -------------------------------------------------------------------------------- /spec/lib/guard/jasmine-headless-webkit_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Guard::JasmineHeadlessWebkit do 4 | let(:guard) { Guard::JasmineHeadlessWebkit.new([], options) } 5 | 6 | let(:options) { {} } 7 | 8 | describe "#start" do 9 | context 'no all on start' do 10 | let(:options) { { :all_on_start => false } } 11 | 12 | it "should not run all" do 13 | guard.expects(:run_all).never 14 | guard.start 15 | end 16 | end 17 | 18 | context 'all on start' do 19 | let(:options) { { :all_on_start => true } } 20 | 21 | it "should not run all" do 22 | guard.expects(:run_all).once 23 | guard.start 24 | end 25 | end 26 | 27 | context 'run_before' do 28 | let(:options) { { :run_before => true, :all_on_start => false } } 29 | 30 | it "should warn about deprecation" do 31 | Guard::UI.expects(:deprecation).at_least_once 32 | guard.start 33 | end 34 | end 35 | end 36 | 37 | describe '#run_all' do 38 | before do 39 | guard.stubs(:run_all_things_before).returns(true) 40 | end 41 | 42 | context 'fails' do 43 | it 'should return false' do 44 | Guard::JasmineHeadlessWebkit::Runner.stubs(:run).returns(['file.js']) 45 | 46 | guard.run_all.should be_false 47 | guard.files_to_rerun.should == ['file.js'] 48 | end 49 | end 50 | 51 | context 'succeeds' do 52 | it 'should return true' do 53 | Guard::JasmineHeadlessWebkit::Runner.stubs(:run).returns([]) 54 | 55 | guard.run_all.should be_true 56 | guard.files_to_rerun.should == [] 57 | end 58 | end 59 | 60 | context 'pass along jhw options' do 61 | let(:options) { { :all_on_start => false, :full_run => false } } 62 | 63 | it 'should only pass along jhw options' do 64 | Guard::JasmineHeadlessWebkit::Runner.expects(:run).with([], :full_run => false) 65 | 66 | guard.run_all 67 | end 68 | end 69 | end 70 | 71 | describe '#run_on_change' do 72 | include FakeFS::SpecHelpers 73 | 74 | let(:one_file) { %w{test.js} } 75 | 76 | def absolute(file) 77 | case file 78 | when Array 79 | file.collect { |f| absolute(f) } 80 | else 81 | File.expand_path(file) 82 | end 83 | end 84 | 85 | before do 86 | File.open(one_file.first, 'wb') 87 | end 88 | 89 | context 'two files' do 90 | it "should only run one" do 91 | Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(one_file), {}).returns(one_file) 92 | 93 | guard.run_on_change(%w{test.js test.js}).should be_false 94 | guard.files_to_rerun.should == one_file 95 | end 96 | end 97 | 98 | context 'one file no priors' do 99 | it "should not run all" do 100 | Guard::JasmineHeadlessWebkit::Runner.expects(:run).returns(one_file) 101 | 102 | guard.run_on_change(one_file).should be_false 103 | guard.files_to_rerun.should == one_file 104 | end 105 | end 106 | 107 | context 'one file one prior' do 108 | it "should not run all" do 109 | guard.instance_variable_set(:@files_to_rerun, [ "two.js" ]) 110 | Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(one_file) + [ "two.js" ], {}).returns(one_file) 111 | 112 | guard.run_on_change(one_file).should be_false 113 | guard.files_to_rerun.should == one_file 114 | end 115 | end 116 | 117 | context 'failed hard' do 118 | it "should not run all" do 119 | guard.instance_variable_set(:@files_to_rerun, absolute(one_file)) 120 | Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(one_file), {}).returns(false) 121 | 122 | guard.run_on_change(one_file).should be_false 123 | guard.files_to_rerun.should == absolute(one_file) 124 | end 125 | end 126 | 127 | context 'succeed, but still do not run all' do 128 | it "should run all" do 129 | Guard::JasmineHeadlessWebkit::Runner.expects(:run).returns([]) 130 | 131 | guard.run_on_change(one_file).should be_true 132 | guard.files_to_rerun.should == [] 133 | end 134 | end 135 | 136 | context 'no files given, just run all' do 137 | it 'should run all but not run once' do 138 | Guard::JasmineHeadlessWebkit::Runner.expects(:run).never 139 | guard.expects(:run_all).once.returns(true) 140 | 141 | guard.run_on_change([]).should be_true 142 | guard.files_to_rerun.should == [] 143 | end 144 | end 145 | 146 | context "Files I don't care about given, ignore" do 147 | it 'should run all but not run once' do 148 | Guard::JasmineHeadlessWebkit::Runner.expects(:run).never 149 | guard.expects(:run_all).once 150 | 151 | guard.run_on_change(%w{test.jst}) 152 | guard.files_to_rerun.should == [] 153 | end 154 | end 155 | 156 | context 'glob given' do 157 | let(:files) { %w{file1.js file2.js other.js} } 158 | 159 | before do 160 | files.each { |file| File.open(file, 'wb') } 161 | end 162 | 163 | context 'not a duplicate' do 164 | it 'should expand the glob' do 165 | Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(%w{file1.js file2.js}), {}).returns(false) 166 | 167 | guard.run_on_change(%w{file*.js}) 168 | end 169 | end 170 | 171 | context 'a duplicate' do 172 | it 'should expand the glob and uniq' do 173 | guard.instance_variable_set(:@files_to_rerun, absolute(%w{file1.js})) 174 | Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(%w{file1.js file2.js}), {}).returns(false) 175 | 176 | guard.run_on_change(%w{file*.js}) 177 | end 178 | end 179 | end 180 | end 181 | 182 | context 'with run_before' do 183 | context 'with failing command' do 184 | before do 185 | Guard::JasmineHeadlessWebkit::Runner.expects(:run).never 186 | Guard::UI.expects(:info).with(regexp_matches(/false/)) 187 | end 188 | 189 | let(:options) { { :run_before => 'false' } } 190 | 191 | it "should run the command first" do 192 | guard.run_all 193 | end 194 | end 195 | 196 | context 'with succeeding command' do 197 | before do 198 | Guard::JasmineHeadlessWebkit::Runner.expects(:run).once 199 | Guard::UI.expects(:info).with(regexp_matches(/true/)) 200 | Guard::UI.expects(:info).with(regexp_matches(/running all/)) 201 | end 202 | 203 | let(:options) { { :run_before => 'true' } } 204 | 205 | it "should run the command first" do 206 | guard.run_all 207 | end 208 | end 209 | end 210 | 211 | describe '#reload' do 212 | it 'should reset the state of the files_to_rerun' do 213 | Guard::UI.expects(:info).with(regexp_matches(/Resetting/)) 214 | 215 | guard.instance_variable_set(:@files_to_rerun, "test") 216 | guard.reload 217 | guard.files_to_rerun.should == [] 218 | end 219 | end 220 | end 221 | --------------------------------------------------------------------------------