clean some things up

This commit is contained in:
John Bintz 2011-10-11 15:30:39 -04:00
parent c9e7bb60cb
commit 7040e0e949
9 changed files with 82 additions and 89 deletions

View File

@ -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'

View File

@ -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'

View File

@ -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

View File

@ -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?

View File

@ -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

View File

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

View File

@ -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

View File

@ -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

View File

@ -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