forked from guard/guard-spork
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Initial commit (specs not complete)
- Loading branch information
0 parents
commit a5f3d95
Showing
14 changed files
with
398 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
pkg/* | ||
*.gem | ||
.bundle | ||
Gemfile.lock | ||
|
||
## MAC OS | ||
.DS_Store | ||
.Trashes | ||
.com.apple.timemachine.supported | ||
.fseventsd | ||
Desktop DB | ||
Desktop DF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in guard-spork.gemspec | ||
gemspec | ||
|
||
require 'rbconfig' | ||
|
||
if Config::CONFIG['target_os'] =~ /darwin/i | ||
gem 'rb-fsevent', '>= 0.3.6' | ||
gem 'growl', '~> 1.0.3' | ||
end | ||
if Config::CONFIG['target_os'] =~ /linux/i | ||
gem 'rb-inotify', '>= 0.5.1' | ||
gem 'libnotify', '~> 0.1.3' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
guard 'rspec', :version => 2 do | ||
watch('^spec/(.*)_spec.rb') | ||
watch('^lib/(.*).rb') { |m| "spec/#{m[1]}_spec.rb" } | ||
watch('^spec/spec_helper.rb') { "spec" } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2010 Thibaud Guillaume-Gentil | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
= Guard::Spork | ||
|
||
Spork guard allows to automatically & intelligently start/reload your RSpec/Cucumber Spork server(s). | ||
|
||
- Compatible with Spork 0.8.4 & 0.9.0.rc2 | ||
- Tested on Ruby 1.8.6, 1.8.7 & 1.9.2. | ||
|
||
== Install | ||
|
||
Please be sure to have {guard}[http://github.com/guard/guard] installed before continue. | ||
|
||
Install the gem: | ||
|
||
gem install guard-spork | ||
|
||
Add it to your Gemfile (inside test group): | ||
|
||
gem 'guard-spork' | ||
|
||
Add guard definition to your Guardfile with: | ||
|
||
guard init spork | ||
|
||
== Usage | ||
|
||
Please read {guard usage doc}[http://github.com/guard/guard#readme] | ||
|
||
== Guardfile | ||
|
||
Spork guard can be really be adapated to all kind of projects. | ||
Please read {guard doc}[http://github.com/guard/guard#readme] for more info about Guardfile DSL. | ||
|
||
!!! Attention place Spork guard before rspec/cucumber guards !!! | ||
|
||
=== Rails app | ||
|
||
guard 'spork' do | ||
watch('^config/application.rb$') | ||
watch('^config/environment.rb$') | ||
watch('^config/environments/.*\.rb$') | ||
watch('^config/initializers/.*\.rb$') | ||
watch('^spec/spec_helper.rb') | ||
end | ||
|
||
== Options | ||
|
||
Spork guard automatically detect RSpec/Cucumber/Bundler presence but you can disabled them via: | ||
|
||
guard 'spork', :cucumber => false, :bundler => false do | ||
... | ||
end | ||
|
||
Available options: | ||
|
||
:cucumber => false | ||
:rspec => false | ||
:bundler => false # don't use "bundle exec" | ||
:rspec_port => xxxx # default 8989 | ||
:cucumber_port => xxxx # default 8990 | ||
|
||
== Development | ||
|
||
- Source hosted at {GitHub}[http://github.com/guard/guard-spork] | ||
- Report issues/Questions/Feature requests on {GitHub Issues}[http://github.com/guard/guard-spork/issues] | ||
|
||
Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change | ||
you make. | ||
|
||
== Authors | ||
|
||
{Thibaud Guillaume-Gentil}[http://github.com/thibaudgg] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
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:prepare_fixtures | ||
rake spec' | ||
BASH | ||
end | ||
end | ||
|
||
desc "Run bundle install on each fixtures directories with Gemfile" | ||
task(:prepare_fixtures) do | ||
Dir.foreach("spec/fixtures") do |dir| | ||
if File.exists?("spec/fixtures/#{dir}/Gemfile") | ||
system <<-BASH | ||
cd spec/fixtures/#{dir}; | ||
bundle install | ||
BASH | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path('../lib', __FILE__) | ||
require 'guard/spork/version' | ||
|
||
Gem::Specification.new do |s| | ||
s.name = 'guard-spork' | ||
s.version = Guard::SporkVersion::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ['Thibaud Guillaume-Gentil'] | ||
s.email = ['thibaud@thibaud.me'] | ||
s.homepage = 'http://rubygems.org/gems/guard-spork' | ||
s.summary = 'Guard gem for Spork' | ||
s.description = 'Guard::Spork automatically manage Spork DRb servers' | ||
|
||
s.required_rubygems_version = '>= 1.3.6' | ||
s.rubyforge_project = 'guard-spork' | ||
|
||
s.add_dependency 'guard', '>= 0.2.0' | ||
s.add_dependency 'spork', '~> 0.9.0.rc2' | ||
|
||
s.add_development_dependency 'bundler', '~> 1.0.3' | ||
s.add_development_dependency 'rspec', '~> 2.1' | ||
|
||
s.files = Dir.glob('{lib}/**/*') + %w[LICENSE README.rdoc] | ||
s.require_path = 'lib' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'guard' | ||
require 'guard/guard' | ||
|
||
module Guard | ||
class Spork < Guard | ||
|
||
autoload :Runner, 'guard/spork/runner' | ||
attr_accessor :runner | ||
|
||
def initialize(watchers = [], options = {}) | ||
super | ||
@runner = Runner.new(options) | ||
end | ||
|
||
def start | ||
runner.launch_sporks("start") | ||
end | ||
|
||
def reload | ||
runner.kill_sporks | ||
runner.launch_sporks("reload") | ||
end | ||
|
||
def run_on_change(paths) | ||
runner.kill_sporks | ||
runner.launch_sporks("reload") | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
module Guard | ||
class Spork | ||
class Runner | ||
attr_accessor :options | ||
|
||
def initialize(options = {}) | ||
options[:rspec_port] ||= 8989 | ||
options[:cucumber_port] ||= 8990 | ||
@options = options | ||
end | ||
|
||
def launch_sporks(action) | ||
UI.info "#{action.capitalize}ing Spork for #{sporked_gems} ", :reset => true | ||
system(spork_command("rspec")) if rspec? | ||
system(spork_command("cucumber")) if cucumber? | ||
verify_launches(action) | ||
end | ||
|
||
def kill_sporks | ||
system("kill $(ps aux | awk '/spork/&&!/awk/{print $2;}') >/dev/null 2>&1") | ||
end | ||
|
||
private | ||
|
||
def spork_command(type) | ||
cmd_parts = [] | ||
cmd_parts << "bundle exec" if bundler? | ||
cmd_parts << "spork" | ||
|
||
case type | ||
when "rspec" | ||
cmd_parts << "-p #{options[:rspec_port]}" | ||
when "cucumber" | ||
cmd_parts << "cu" | ||
cmd_parts << "-p #{options[:cucumber_port]}" | ||
end | ||
|
||
cmd_parts << ">/dev/null 2>&1 < /dev/null &" | ||
cmd_parts.join(" ") | ||
end | ||
|
||
def verify_launches(action) | ||
30.times do | ||
sleep 1 | ||
begin | ||
TCPSocket.new('localhost', options[:rspec_port]).close if rspec? | ||
TCPSocket.new('localhost', options[:cucumber_port]).close if cucumber? | ||
rescue Errno::ECONNREFUSED | ||
print '.' | ||
next | ||
end | ||
UI.info "Spork for #{sporked_gems} successufly #{action}ed", :reset => true | ||
Notifier.notify "#{sporked_gems} successufly #{action}ed", :title => "Spork", :image => :success | ||
return true | ||
end | ||
UI.error "Could not #{action} Spork for #{sporked_gems}. Make sure you can use it manually first.", :reset => true | ||
Notifier.notify "#{sporked_gems} NOT #{action}ed", :title => "Spork", :image => :failed | ||
end | ||
|
||
def sporked_gems | ||
gems = [] | ||
gems << "RSpec" if rspec? | ||
gems << "Cucumber" if cucumber? | ||
gems.join(' & ') | ||
end | ||
|
||
def bundler? | ||
@bundler ||= File.exist?("#{Dir.pwd}/Gemfile") && options[:bundler] != false | ||
end | ||
|
||
def rspec? | ||
@rspec ||= File.exist?("#{Dir.pwd}/spec") && options[:rspec] != false | ||
end | ||
|
||
def cucumber? | ||
@cucumber ||= File.exist?("#{Dir.pwd}/features") && options[:cucumber] != false | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
guard 'spork' do | ||
watch('^config/application.rb$') | ||
watch('^config/environment.rb$') | ||
watch('^config/environments/.*\.rb$') | ||
watch('^config/initializers/.*\.rb$') | ||
watch('^spec/spec_helper.rb') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Guard | ||
module SporkVersion | ||
VERSION = "0.0.1" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'spec_helper' | ||
|
||
describe Guard::Spork::Runner do | ||
subject { Guard::Spork::Runner.new } | ||
|
||
its(:options) { should == { :cucumber_port => 8990, :rspec_port => 8989 } } | ||
|
||
describe "#launch_sporks" do | ||
before(:each) do | ||
subject.stub(:system) { true } | ||
Dir.stub(:pwd) { "" } | ||
end | ||
|
||
# context "with rspec" do | ||
# before(:each) do | ||
# File.should_receive(:exist?).with('/spec') { true } | ||
# File.should_receive(:exist?).with('/cucumber') { false } | ||
# end | ||
# | ||
# it "should launch rspec spork server" do | ||
# subject.should_receive(:system).with("kill $(ps aux | awk '/spork/&&!/awk/{print $2;}') >/dev/null 2>&1") | ||
# subject.launch_sporks("start") | ||
# end | ||
# | ||
# end | ||
|
||
|
||
end | ||
|
||
describe "#kill_sporks" do | ||
it "should use magic kill command" do | ||
subject.should_receive(:system).with("kill $(ps aux | awk '/spork/&&!/awk/{print $2;}') >/dev/null 2>&1") | ||
subject.kill_sporks | ||
end | ||
end | ||
|
||
|
||
end |
Oops, something went wrong.