From 7040e0e949a92a6aa4d0603b53fd8c6293101254 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 11 Oct 2011 15:30:39 -0400 Subject: [PATCH] clean some things up --- Gemfile | 6 +- Rakefile | 32 ++++----- guard-jasmine-headless-webkit.gemspec | 8 +-- lib/guard/jasmine-headless-webkit.rb | 5 +- lib/guard/jasmine-headless-webkit/runner.rb | 71 ++++++++++--------- lib/guard/jasmine-headless-webkit/version.rb | 5 -- .../jasmine-headless-webkit/runner_spec.rb | 12 ++-- .../lib/guard/jasmine-headless-webkit_spec.rb | 30 ++++---- spec/spec_helper.rb | 2 + 9 files changed, 82 insertions(+), 89 deletions(-) delete mode 100644 lib/guard/jasmine-headless-webkit/version.rb diff --git a/Gemfile b/Gemfile index bcfffbb..7762a10 100644 --- a/Gemfile +++ b/Gemfile @@ -2,10 +2,12 @@ source "http://rubygems.org" # Specify your gem's dependencies in guard-jasmine-headless-webkit.gemspec gemspec -gem 'guard', :git => 'https://github.com/guard/guard.git' +gem 'guard', :git => 'git://github.com/guard/guard.git' gem 'rspec' gem 'mocha' -gem 'rake', '0.8.7' +gem 'rake', '0.9.2' gem 'growl' gem 'fakefs', :require => nil gem 'jasmine-headless-webkit', :path => '../jasmine-headless-webkit' +gem 'coffee-script' +gem 'guard-rspec' diff --git a/Rakefile b/Rakefile index 456d898..01a5c77 100644 --- a/Rakefile +++ b/Rakefile @@ -13,27 +13,25 @@ require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) +PLATFORMS = %w{1.8.7 1.9.2 ree 1.9.3-rc1} + +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}'}.tap { |o| p o } + end +end + +class SpecFailure < StandardError; end +class BundleFailure < StandardError; end + namespace :spec do desc "Run on three Rubies" task :platforms do - 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) + rvm_bundle "update" + rvm_bundle "exec rspec spec" + raise SpecError.new if $?.exitstatus != 0 end end task :default => 'spec:platforms' + diff --git a/guard-jasmine-headless-webkit.gemspec b/guard-jasmine-headless-webkit.gemspec index 8f802df..00ac598 100644 --- a/guard-jasmine-headless-webkit.gemspec +++ b/guard-jasmine-headless-webkit.gemspec @@ -1,10 +1,8 @@ # -*- 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 = Guard::JasmineHeadlessWebkitVersion::VERSION + s.version = '0.3.2' s.platform = Gem::Platform::RUBY s.authors = ["John Bintz"] s.email = ["john@coswellproductions.com"] @@ -19,7 +17,7 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - s.add_dependency 'guard', '>= 0.4.0' - s.add_dependency 'jasmine-headless-webkit', '>= 0.7.0' + s.add_runtime_dependency 'guard', '>= 0.4.0' + s.add_runtime_dependency 'jasmine-headless-webkit', '>= 0.7.0' end diff --git a/lib/guard/jasmine-headless-webkit.rb b/lib/guard/jasmine-headless-webkit.rb index a0ff50c..8e3a2cd 100644 --- a/lib/guard/jasmine-headless-webkit.rb +++ b/lib/guard/jasmine-headless-webkit.rb @@ -1,10 +1,11 @@ require 'guard' require 'guard/guard' -require 'guard/jasmine-headless-webkit/runner' require 'coffee-script' 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..." @@ -72,7 +73,7 @@ module Guard else UI.info(SOME_SPECS_MESSAGE % paths.join(' ')) end - failed_files = JasmineHeadlessWebkitRunner.run(paths, @filtered_options) + failed_files = Runner.run(paths, @filtered_options) @files_to_rerun = failed_files || paths failed_files && @files_to_rerun.empty? diff --git a/lib/guard/jasmine-headless-webkit/runner.rb b/lib/guard/jasmine-headless-webkit/runner.rb index 70bc3c5..99896ce 100644 --- a/lib/guard/jasmine-headless-webkit/runner.rb +++ b/lib/guard/jasmine-headless-webkit/runner.rb @@ -2,50 +2,51 @@ require 'guard/notifier' require 'jasmine-headless-webkit' module Guard - class JasmineHeadlessWebkitRunner - class << self - def run(paths = [], options = {}) - file = Tempfile.new('guard-jasmine-headless-webkit') - file.close + class JasmineHeadlessWebkit + class Runner + class << self + def run(paths = [], options = {}) + file = Tempfile.new('guard-jasmine-headless-webkit') + file.close - options.merge!(:report => file.path, :colors => true, :files => paths) + options.merge!(:report => file.path, :colors => true, :files => paths) - Jasmine::Headless::Runner.run(options) + Jasmine::Headless::Runner.run(options) - notify(file.path) - end - - def 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 + notify(file.path) end - rescue Jasmine::Headless::InvalidReport => e - Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed) - false - end - private - 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 image(any_console, fails) - if any_console - :pending - else - if fails.to_i == 0 - :success + def 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 - :failed + raise Jasmine::Headless::InvalidReport + end + rescue Jasmine::Headless::InvalidReport => e + Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed) + false + end + + private + 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 image(any_console, fails) + if any_console + :pending + else + if fails.to_i == 0 + :success + else + :failed + end end end end end end end - diff --git a/lib/guard/jasmine-headless-webkit/version.rb b/lib/guard/jasmine-headless-webkit/version.rb deleted file mode 100644 index aa34fd1..0000000 --- a/lib/guard/jasmine-headless-webkit/version.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Guard - module JasmineHeadlessWebkitVersion - VERSION = "0.3.1" - end -end diff --git a/spec/lib/guard/jasmine-headless-webkit/runner_spec.rb b/spec/lib/guard/jasmine-headless-webkit/runner_spec.rb index a0bac69..6ada022 100644 --- a/spec/lib/guard/jasmine-headless-webkit/runner_spec.rb +++ b/spec/lib/guard/jasmine-headless-webkit/runner_spec.rb @@ -1,13 +1,11 @@ require 'spec_helper' -require 'guard/jasmine-headless-webkit/runner' -require 'fakefs/spec_helpers' -describe Guard::JasmineHeadlessWebkitRunner do +describe Guard::JasmineHeadlessWebkit::Runner 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) + Guard::JasmineHeadlessWebkit::Runner.run([], :full_run => false) end end @@ -26,7 +24,7 @@ describe Guard::JasmineHeadlessWebkitRunner do 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::JasmineHeadlessWebkitRunner.notify(file).should == [] + Guard::JasmineHeadlessWebkit::Runner.notify(file).should == [] end end @@ -39,7 +37,7 @@ 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::JasmineHeadlessWebkitRunner.notify(file).should == [ 'file.js' ] + Guard::JasmineHeadlessWebkit::Runner.notify(file).should == [ 'file.js' ] end end @@ -49,7 +47,7 @@ REPORT it 'should notify failure' do Guard::Notifier.expects(:notify).with("Spec runner interrupted!", { :title => 'Jasmine results', :image => :failed }) - Guard::JasmineHeadlessWebkitRunner.notify(file).should be_false + Guard::JasmineHeadlessWebkit::Runner.notify(file).should be_false end end end diff --git a/spec/lib/guard/jasmine-headless-webkit_spec.rb b/spec/lib/guard/jasmine-headless-webkit_spec.rb index 95e15db..a3ab442 100644 --- a/spec/lib/guard/jasmine-headless-webkit_spec.rb +++ b/spec/lib/guard/jasmine-headless-webkit_spec.rb @@ -1,6 +1,4 @@ require 'spec_helper' -require 'guard/jasmine-headless-webkit' -require 'fakefs/spec_helpers' describe Guard::JasmineHeadlessWebkit do let(:guard) { Guard::JasmineHeadlessWebkit.new([], options) } @@ -43,7 +41,7 @@ describe Guard::JasmineHeadlessWebkit do context 'fails' do it 'should return false' do - Guard::JasmineHeadlessWebkitRunner.stubs(:run).returns(['file.js']) + Guard::JasmineHeadlessWebkit::Runner.stubs(:run).returns(['file.js']) guard.run_all.should be_false guard.files_to_rerun.should == ['file.js'] @@ -52,7 +50,7 @@ describe Guard::JasmineHeadlessWebkit do context 'succeeds' do it 'should return true' do - Guard::JasmineHeadlessWebkitRunner.stubs(:run).returns([]) + Guard::JasmineHeadlessWebkit::Runner.stubs(:run).returns([]) guard.run_all.should be_true guard.files_to_rerun.should == [] @@ -63,7 +61,7 @@ describe Guard::JasmineHeadlessWebkit 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::JasmineHeadlessWebkit::Runner.expects(:run).with([], :full_run => false) guard.run_all end @@ -90,7 +88,7 @@ describe Guard::JasmineHeadlessWebkit do context 'two files' do it "should only run one" do - Guard::JasmineHeadlessWebkitRunner.expects(:run).with(absolute(one_file), {}).returns(one_file) + 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 @@ -99,7 +97,7 @@ describe Guard::JasmineHeadlessWebkit do context 'one file no priors' do it "should not run all" do - Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(one_file) + Guard::JasmineHeadlessWebkit::Runner.expects(:run).returns(one_file) guard.run_on_change(one_file).should be_false guard.files_to_rerun.should == one_file @@ -109,7 +107,7 @@ describe Guard::JasmineHeadlessWebkit do 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(absolute(one_file) + [ "two.js" ], {}).returns(one_file) + 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 @@ -119,7 +117,7 @@ describe Guard::JasmineHeadlessWebkit do context 'failed hard' do it "should not run all" do guard.instance_variable_set(:@files_to_rerun, absolute(one_file)) - Guard::JasmineHeadlessWebkitRunner.expects(:run).with(absolute(one_file), {}).returns(false) + 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) @@ -128,7 +126,7 @@ describe Guard::JasmineHeadlessWebkit do context 'succeed, but still do not run all' do it "should run all" do - Guard::JasmineHeadlessWebkitRunner.expects(:run).returns([]) + Guard::JasmineHeadlessWebkit::Runner.expects(:run).returns([]) guard.run_on_change(one_file).should be_true guard.files_to_rerun.should == [] @@ -137,7 +135,7 @@ describe Guard::JasmineHeadlessWebkit do context 'no files given, just run all' do it 'should run all but not run once' do - Guard::JasmineHeadlessWebkitRunner.expects(:run).never + Guard::JasmineHeadlessWebkit::Runner.expects(:run).never guard.expects(:run_all).once.returns(true) guard.run_on_change([]).should be_true @@ -147,7 +145,7 @@ describe Guard::JasmineHeadlessWebkit do context "Files I don't care about given, ignore" do it 'should run all but not run once' do - Guard::JasmineHeadlessWebkitRunner.expects(:run).never + Guard::JasmineHeadlessWebkit::Runner.expects(:run).never guard.expects(:run_all).once guard.run_on_change(%w{test.jst}) @@ -164,7 +162,7 @@ describe Guard::JasmineHeadlessWebkit do context 'not a duplicate' do it 'should expand the glob' do - Guard::JasmineHeadlessWebkitRunner.expects(:run).with(absolute(%w{file1.js file2.js}), {}).returns(false) + Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(%w{file1.js file2.js}), {}).returns(false) guard.run_on_change(%w{file*.js}) end @@ -173,7 +171,7 @@ describe Guard::JasmineHeadlessWebkit do context 'a duplicate' do it 'should expand the glob and uniq' do guard.instance_variable_set(:@files_to_rerun, absolute(%w{file1.js})) - Guard::JasmineHeadlessWebkitRunner.expects(:run).with(absolute(%w{file1.js file2.js}), {}).returns(false) + Guard::JasmineHeadlessWebkit::Runner.expects(:run).with(absolute(%w{file1.js file2.js}), {}).returns(false) guard.run_on_change(%w{file*.js}) end @@ -184,7 +182,7 @@ describe Guard::JasmineHeadlessWebkit do context 'with run_before' do context 'with failing command' do before do - Guard::JasmineHeadlessWebkitRunner.expects(:run).never + Guard::JasmineHeadlessWebkit::Runner.expects(:run).never Guard::UI.expects(:info).with(regexp_matches(/false/)) end @@ -197,7 +195,7 @@ describe Guard::JasmineHeadlessWebkit do context 'with succeeding command' do before do - Guard::JasmineHeadlessWebkitRunner.expects(:run).once + Guard::JasmineHeadlessWebkit::Runner.expects(:run).once Guard::UI.expects(:info).with(regexp_matches(/true/)) Guard::UI.expects(:info).with(regexp_matches(/running all/)) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9d18222..00d52b2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,7 @@ require 'mocha' require 'guard' +require 'guard/jasmine-headless-webkit' +require 'fakefs/spec_helpers' RSpec.configure do |config| config.mock_with :mocha