From 00fbd41f07430db0ed1174016cb13453d0db3016 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 23 May 2011 21:28:01 -0400 Subject: [PATCH] yeah, it's working --- Gemfile | 3 ++ Guardfile | 17 +++++++ README.md | 0 guard-jasmine-headless-webkit.gemspec | 2 +- lib/guard/jasmine-headless-webkit.rb | 7 ++- lib/guard/jasmine-headless-webkit/runner.rb | 11 +++++ .../templates/Guardfile | 9 ++++ lib/guard/jasmine-headless-webkit/version.rb | 2 +- .../lib/guard/jasmine-headless-webkit_spec.rb | 48 +++++++++++++++++++ spec/spec_helper.rb | 16 +++++++ 10 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 Guardfile create mode 100644 README.md create mode 100644 lib/guard/jasmine-headless-webkit/runner.rb create mode 100644 spec/lib/guard/jasmine-headless-webkit_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/Gemfile b/Gemfile index 07c9411..0b908ad 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,6 @@ source "http://rubygems.org" # Specify your gem's dependencies in guard-jasmine-headless-webkit.gemspec gemspec +gem 'guard' +gem 'rspec' +gem 'mocha' diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..9ad38fa --- /dev/null +++ b/Guardfile @@ -0,0 +1,17 @@ +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +guard 'rspec', :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" } + + # 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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/guard-jasmine-headless-webkit.gemspec b/guard-jasmine-headless-webkit.gemspec index 3a714da..bf92f40 100644 --- a/guard-jasmine-headless-webkit.gemspec +++ b/guard-jasmine-headless-webkit.gemspec @@ -4,7 +4,7 @@ require "guard/jasmine-headless-webkit/version" Gem::Specification.new do |s| s.name = "guard-jasmine-headless-webkit" - s.version = Guard::JasmineHeadlessWebkit::VERSION + s.version = Guard::JasmineHeadlessWebkitVersion::VERSION s.platform = Gem::Platform::RUBY s.authors = ["John Bintz"] s.email = ["john@coswellproductions.com"] diff --git a/lib/guard/jasmine-headless-webkit.rb b/lib/guard/jasmine-headless-webkit.rb index c6e3ed5..80b2b9d 100644 --- a/lib/guard/jasmine-headless-webkit.rb +++ b/lib/guard/jasmine-headless-webkit.rb @@ -1,5 +1,6 @@ require 'guard' require 'guard/guard' +require 'guard/jasmine-headless-webkit/runner' module Guard class JasmineHeadlessWebkit < Guard @@ -16,13 +17,11 @@ module Guard end def run_all - system %{jasmine-headless-webkit} + JasmineHeadlessWebkitRunner.run end def run_on_change(paths) - system %{jasmine-headless-webkit #{paths.join(" ")}} - - run_all if $?.exitstatus != 1 + run_all if JasmineHeadlessWebkitRunner.run(paths) != 1 end end diff --git a/lib/guard/jasmine-headless-webkit/runner.rb b/lib/guard/jasmine-headless-webkit/runner.rb new file mode 100644 index 0000000..5d9d658 --- /dev/null +++ b/lib/guard/jasmine-headless-webkit/runner.rb @@ -0,0 +1,11 @@ +module Guard + class JasmineHeadlessWebkitRunner + class << self + def run(paths = []) + system %{jasmine-headless-webkit #{paths.join(" ")}} + $?.exitstatus + end + end + end +end + diff --git a/lib/guard/jasmine-headless-webkit/templates/Guardfile b/lib/guard/jasmine-headless-webkit/templates/Guardfile index e69de29..0226c9b 100644 --- a/lib/guard/jasmine-headless-webkit/templates/Guardfile +++ b/lib/guard/jasmine-headless-webkit/templates/Guardfile @@ -0,0 +1,9 @@ +# Run JS and CoffeeScript files in a typical Rails 3.1 fashion, placing Underscore templates in app/views/*.jst + +guard 'jasmine-headless-webkit' do + watch(%r{^app/views/.*\.jst}) + watch(%r{^public/javascripts/(.*)\.js}) { |m| newest_js_file("spec/javascripts/#{m[1]}") } + watch(%r{^app/assets/javascripts/(.*)\.(js|coffee)}) { |m| newest_js_file("spec/javascripts/#{m[1]}") } + watch(%r{^spec/javascripts/(.*)_spec\..*}) { |m| newest_js_file("spec/javascripts/#{m[1]}") } +end + diff --git a/lib/guard/jasmine-headless-webkit/version.rb b/lib/guard/jasmine-headless-webkit/version.rb index 7673388..ca156fd 100644 --- a/lib/guard/jasmine-headless-webkit/version.rb +++ b/lib/guard/jasmine-headless-webkit/version.rb @@ -1,5 +1,5 @@ module Guard - module JasmineHeadlessWebkit + module JasmineHeadlessWebkitVersion VERSION = "0.0.1" end end diff --git a/spec/lib/guard/jasmine-headless-webkit_spec.rb b/spec/lib/guard/jasmine-headless-webkit_spec.rb new file mode 100644 index 0000000..1973d0e --- /dev/null +++ b/spec/lib/guard/jasmine-headless-webkit_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' +require 'guard/jasmine-headless-webkit' + +describe Guard::JasmineHeadlessWebkit do + let(:guard) { Guard::JasmineHeadlessWebkit.new([], options) } + + let(:options) { {} } + + describe "#start" do + context 'no all on start' do + let(:options) { { :all_on_start => false } } + + it "should not run all" do + guard.expects(:run_all).never + guard.start + end + end + + context 'all on start' do + let(:options) { { :all_on_start => true } } + + it "should not run all" do + guard.expects(:run_all).once + guard.start + end + end + end + + describe '#run_on_change' do + context 'jhw call fails' do + it "should not run all" do + Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(1) + guard.expects(:run_all).never + + guard.run_on_change(%w{test}) + end + end + + context 'succeed, run all' do + it "should run all" do + Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(0) + guard.expects(:run_all).once + + guard.run_on_change(%w{test}) + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..fb3367d --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,16 @@ +require 'mocha' +require 'guard' + +RSpec.configure do |config| + config.mock_with :mocha +end + +module Guard + module UI + class << self + def info(*args) + end + end + end +end +