diff --git a/guard-jessie.gemspec b/guard-jessie.gemspec index 0848a4f..4c03ac1 100644 --- a/guard-jessie.gemspec +++ b/guard-jessie.gemspec @@ -1,6 +1,6 @@ # -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) -require "guard-jessie/version" +require "guard/jessie" Gem::Specification.new do |s| s.name = "guard-jessie" @@ -10,7 +10,7 @@ Gem::Specification.new do |s| s.email = ["mtaszycki@gmail.com"] s.homepage = "https://github.com/mehowte/guard-jessie" s.summary = %q{Guard gem for jessie} - s.description = %q{Guard::Jessie automatically runs you jasmine specs through jessie driver} + s.description = %q{Guard::Jessie automatically runs your jasmine specs through jessie driver} s.rubyforge_project = "guard-jessie" @@ -18,7 +18,6 @@ Gem::Specification.new do |s| s.add_development_dependency 'bundler', '~> 1.0' s.add_development_dependency 'rspec', '~> 2.6' - s.add_development_dependency 'guard-ego' s.add_development_dependency 'guard-bundler' s.add_development_dependency 'guard-rspec' diff --git a/lib/guard-jessie.rb b/lib/guard-jessie.rb index c9196f9..e69de29 100644 --- a/lib/guard-jessie.rb +++ b/lib/guard-jessie.rb @@ -1,5 +0,0 @@ -module Guard - module Jessie - # Your code goes here... - end -end diff --git a/lib/guard/jessie.rb b/lib/guard/jessie.rb new file mode 100644 index 0000000..54679de --- /dev/null +++ b/lib/guard/jessie.rb @@ -0,0 +1,21 @@ +require 'guard' +require 'guard/guard' + +module Guard + class Jessie < Guard + autoload :VERSION, 'guard/jessie/version' + autoload :Runner, 'guard/jessie/runner' + + def run_all + puts "Running all specs" + Runner.run %w[spec] + end + + def run_on_change paths + paths_string = paths.map {|path| "#{path}" }.join(' ') + puts "Running #{paths_string}" + Runner.run paths + end + end +end + diff --git a/lib/guard/jessie/runner.rb b/lib/guard/jessie/runner.rb new file mode 100644 index 0000000..c3ec2db --- /dev/null +++ b/lib/guard/jessie/runner.rb @@ -0,0 +1,20 @@ +module Guard + class Jessie + module Runner + def self.run paths + return false if paths.empty? + system(jessie_command(paths)) + end + + private + def self.jessie_command(paths) + cmd_parts = [] + cmd_parts << "jessie" + cmd_parts << "-f progress" + cmd_parts << paths.join(" ") + + cmd_parts.join(" ") + end + end + end +end diff --git a/lib/guard/jessie/templates/Guardfile b/lib/guard/jessie/templates/Guardfile new file mode 100644 index 0000000..75b9213 --- /dev/null +++ b/lib/guard/jessie/templates/Guardfile @@ -0,0 +1,19 @@ +guard 'jessie' do + + # Standard node project + watch(%r{^spec/.+(_spec|Spec)\.(js|coffee)$}) + watch(%r{^lib/(.+)\.(js|coffee)$}) { |m| "spec/lib/#{m[1]}_spec.js" } + watch('spec/spec_helper.js') { "spec" } + + # Typical Rails (version < 3.1) app + watch(%r{^spec/javascripts/.+(_spec|Spec)\.(js|coffee)$}) + watch(%r{^public/javascripts/(.+)\.(js|coffee)$}) { |m| "spec/javascripts/#{m[1]}_spec.js" } + watch('spec/spec_helper.js') { "spec" } + + # Typical Rails (version >= 3.1) app + watch(%r{^spec/javascripts/.+(_spec|Spec)\.(js|coffee)$}) + # you'll want to make adjustments to the rule below if you don't use coffeescript in your tests ;) + watch(%r{^app/assets/javascripts/(.+)\.(js|coffee)$}) { |m| "spec/javascripts/#{m[1]}_spec.coffee" } + watch('spec/spec_helper.js') { "spec" } +end + diff --git a/lib/guard-jessie/version.rb b/lib/guard/jessie/version.rb similarity index 73% rename from lib/guard-jessie/version.rb rename to lib/guard/jessie/version.rb index b47a979..b3595d2 100644 --- a/lib/guard-jessie/version.rb +++ b/lib/guard/jessie/version.rb @@ -1,5 +1,5 @@ module Guard - module Jessie + class Jessie VERSION = "0.0.1" end end diff --git a/spec/lib/guard/jessie/runner_spec.rb b/spec/lib/guard/jessie/runner_spec.rb new file mode 100644 index 0000000..de4670c --- /dev/null +++ b/spec/lib/guard/jessie/runner_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' +module Guard + class Jessie + describe Runner do + let(:multiple_paths) { %w[/spec ./spec/something.js ../spec/something_else.js other_thing.js]} + context "when passed an empty paths list" do + it "returns false" do + subject.run([]).should be_false + end + end + + context "when passed multiple paths" do + it "runs jessie with those paths" do + subject.should_receive(:system).with( + "jessie -f progress /spec ./spec/something.js ../spec/something_else.js other_thing.js" + ) + subject.run(multiple_paths) + end + + end + + end + end +end diff --git a/spec/lib/guard/jessie_spec.rb b/spec/lib/guard/jessie_spec.rb new file mode 100644 index 0000000..3722473 --- /dev/null +++ b/spec/lib/guard/jessie_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' +module Guard + describe Jessie do + let(:paths) { %w[array of changed paths]} + + describe "#run_all" do + it "runs all specs" do + Jessie::Runner.should_receive(:run).with(["spec"]) + subject.run_all + end + end + describe "#run_on_change" do + it "runs changed files" do + Jessie::Runner.should_receive(:run).with(paths) + subject.run_on_change paths + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..191fa35 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,4 @@ +$LOAD_PATH.unshift(File.dirname(__FILE__)) +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) + +require 'guard/jessie'