Permalink
Browse files

initial working version

  • Loading branch information...
1 parent dcadcd2 commit 970538f71cdcbced729f4e2527329f5b48bac545 @carhartl committed Apr 1, 2011
View
@@ -2,3 +2,4 @@
.bundle
Gemfile.lock
pkg/*
+.rvmrc
View
@@ -2,3 +2,14 @@ source "http://rubygems.org"
# Specify your gem's dependencies in guard-phantomjs.gemspec
gemspec
+
+require 'rbconfig'
+
+if Config::CONFIG['target_os'] =~ /darwin/i
+ gem 'rb-fsevent'
+ gem 'growl'
+end
+if Config::CONFIG['target_os'] =~ /linux/i
+ gem 'rb-inotify'
+ gem 'libnotify'
+end
View
@@ -0,0 +1,5 @@
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/(.*)_spec.rb})
+ watch(%r{^lib/(.*)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^spec/spec_helper.rb}) { "spec" }
+end
View
@@ -1,2 +1,21 @@
require 'bundler'
Bundler::GemHelper.install_tasks
+
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:spec)
+task :default => :spec
+
+namespace(:spec) do
+ desc "Run all specs on multiple ruby versions (requires rvm)"
+ task(:portability) do
+ %w[1.8.6 1.8.7 1.9.2].each do |version|
+ system <<-BASH
+ bash -c 'source ~/.rvm/scripts/rvm;
+ rvm #{version};
+ echo "--------- version #{version} ----------\n";
+ bundle install;
+ rake spec'
+ BASH
+ end
+ end
+end
@@ -1,19 +1,25 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
-require "guard-phantomjs/version"
+require "guard/phantomjs/version"
Gem::Specification.new do |s|
s.name = "guard-phantomjs"
- s.version = Guard::Phantomjs::VERSION
+ s.version = Guard::PhantomJSVersion::VERSION
s.platform = Gem::Platform::RUBY
- s.authors = ["TODO: Write your name"]
- s.email = ["TODO: Write your email address"]
- s.homepage = ""
- s.summary = %q{TODO: Write a gem summary}
- s.description = %q{TODO: Write a gem description}
+ s.authors = ["Klaus Hartl"]
+ s.email = ["klaus.hartl@gmail.com"]
+ s.homepage = "http://github.com/carhartl/guard-phantomjs"
+ s.summary = "Guard gem for PhantomJS"
+ s.description = "PhantomJS guard allows to automatically run PhantomJS (headless, WebKit-based browser)."
s.rubyforge_project = "guard-phantomjs"
+ s.add_dependency "guard", ">= 0.3"
+
+ s.add_development_dependency "bundler", "~> 1.0.0"
+ s.add_development_dependency "rspec", "~> 2.3.0"
+ s.add_development_dependency "guard-rspec"
+
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -1,5 +0,0 @@
-module Guard
- module Phantomjs
- # Your code goes here...
- end
-end
@@ -0,0 +1,36 @@
+require 'guard'
+require 'guard/guard'
+
+module Guard
+ class PhantomJS < Guard
+
+ def initialize(watchers = [], options = {})
+ super
+
+ # @options[:runner] ||= 'run-jasmine.js'
+ @options[:server] ||= 'http://127.0.0.1:8888/'
+ @options = options
+ end
+
+ def start
+ UI.info 'Guard::PhantomJS is running!'
+ end
+
+ def run_on_change(paths)
+ return if paths.empty?
+
+ cmd = "phantomjs #{@options[:runner]} #{@options[:server]}"
+ result = %x[#{cmd}]
+
+ notify(result, result =~ /0 failures/ ? :success : :failed)
+ end
+
+
+ private
+
+ def notify(message, image)
+ Notifier.notify(message, :title => 'Jasmine results', :image => image)
+ end
+
+ end
+end
@@ -0,0 +1,5 @@
+guard 'phantomjs', :runner => 'run-jasmine.js' do
+ # Rails example
+ watch(%r{public/.+\.js})
+ watch(%r{^spec/javascripts/.+\.js})
+end
@@ -1,5 +1,5 @@
module Guard
- module Phantomjs
+ module PhantomJSVersion
VERSION = "0.0.1"
end
end
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+module Guard
+ describe PhantomJS do
+
+ describe "#run_on_change" do
+ it "executes phantomjs" do
+ pending
+
+ subject.run_on_change(['foo'])
+ end
+ end
+
+ end
+end
View
@@ -0,0 +1,12 @@
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+require 'rspec'
+require 'guard/phantomjs'
+
+# Requires supporting files with custom matchers and macros, etc,
+# in ./support/ and its subdirectories.
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+
+RSpec.configure do |config|
+
+end

0 comments on commit 970538f

Please sign in to comment.