Compare commits
No commits in common. "master" and "linux-support" have entirely different histories.
master
...
linux-supp
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,4 +2,3 @@
|
|||||||
.bundle
|
.bundle
|
||||||
Gemfile.lock
|
Gemfile.lock
|
||||||
pkg/*
|
pkg/*
|
||||||
.rvmrc
|
|
||||||
|
8
Gemfile
8
Gemfile
@ -2,17 +2,17 @@ source "http://rubygems.org"
|
|||||||
|
|
||||||
# Specify your gem's dependencies in guard-rails.gemspec
|
# Specify your gem's dependencies in guard-rails.gemspec
|
||||||
gemspec
|
gemspec
|
||||||
gem 'rake'
|
gem 'rake', '0.8.7'
|
||||||
gem 'fakefs', :require => nil
|
gem 'fakefs', :require => nil
|
||||||
gem 'guard'
|
gem 'guard', :git => 'https://github.com/guard/guard.git'
|
||||||
gem 'guard-rspec'
|
gem 'guard-rspec'
|
||||||
|
|
||||||
require 'rbconfig'
|
require 'rbconfig'
|
||||||
if RbConfig::CONFIG['target_os'] =~ /darwin/i
|
if Config::CONFIG['target_os'] =~ /darwin/i
|
||||||
gem 'rb-fsevent', '>= 0.3.9'
|
gem 'rb-fsevent', '>= 0.3.9'
|
||||||
gem 'growl', '~> 1.0.3'
|
gem 'growl', '~> 1.0.3'
|
||||||
end
|
end
|
||||||
if RbConfig::CONFIG['target_os'] =~ /linux/i
|
if Config::CONFIG['target_os'] =~ /linux/i
|
||||||
gem 'rb-inotify', '>= 0.5.1'
|
gem 'rb-inotify', '>= 0.5.1'
|
||||||
gem 'libnotify', '~> 0.1.3'
|
gem 'libnotify', '~> 0.1.3'
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
_This fork is no longer maintained. Visit [https://github.com/ranmocy/guard-rails](https://github.com/ranmocy/guard-rails) for the current official fork._
|
|
||||||
|
|
||||||
[![Build Status](http://travis-ci.org/johnbintz/guard-rails.png)](http://travis-ci.org/johnbintz/guard-rails)
|
[![Build Status](http://travis-ci.org/johnbintz/guard-rails.png)](http://travis-ci.org/johnbintz/guard-rails)
|
||||||
|
|
||||||
Want to restart your Rails development server whilst you work? Now you can!
|
Want to restart your Rails development server whilst you work? Now you can!
|
||||||
@ -16,9 +14,7 @@ Lots of fun options!
|
|||||||
* `:start_on_start` will start the server when starting Guard (default `true`)
|
* `:start_on_start` will start the server when starting Guard (default `true`)
|
||||||
* `:force_run` kills any process that's holding open the listen port before attempting to (re)start Rails (default `false`).
|
* `:force_run` kills any process that's holding open the listen port before attempting to (re)start Rails (default `false`).
|
||||||
* `:daemon` runs the server as a daemon, without any output to the terminal that ran `guard` (default `false`).
|
* `:daemon` runs the server as a daemon, without any output to the terminal that ran `guard` (default `false`).
|
||||||
* `:debugger` runs the server with the debugger enabled (default `false`). Required ruby-debug gem.
|
|
||||||
* `:timeout` waits this number of seconds when restarting the Rails server before reporting there's a problem (default `20`).
|
* `:timeout` waits this number of seconds when restarting the Rails server before reporting there's a problem (default `20`).
|
||||||
* `:server` lets you specify the webserver engine to use (try `:server => :thin`).
|
|
||||||
|
|
||||||
This is super-alpha, but it works for me! Only really hand-tested in Mac OS X. Feel free to fork'n'fix for other
|
This is super-alpha, but it works for me! Only really hand-tested in Mac OS X. Feel free to fork'n'fix for other
|
||||||
OSes, and to add some more real tests.
|
OSes, and to add some more real tests.
|
||||||
|
21
Rakefile
21
Rakefile
@ -15,10 +15,23 @@ RSpec::Core::RakeTask.new(:spec)
|
|||||||
namespace :spec do
|
namespace :spec do
|
||||||
desc "Run on three Rubies"
|
desc "Run on three Rubies"
|
||||||
task :platforms do
|
task :platforms do
|
||||||
prefix = "rvm 1.8.7,1.9.2,ree,1.9.3 do"
|
current = %x{rvm-prompt v}
|
||||||
system %{#{prefix} bundle}
|
|
||||||
system %{#{prefix} bundle exec rake spec}
|
fail = false
|
||||||
exit $?.exitstatus if $?.exitstatus != 0
|
%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)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -12,9 +12,7 @@ module Guard
|
|||||||
:environment => 'development',
|
:environment => 'development',
|
||||||
:start_on_start => true,
|
:start_on_start => true,
|
||||||
:force_run => false,
|
:force_run => false,
|
||||||
:timeout => 30,
|
:timeout => 20
|
||||||
:server => nil,
|
|
||||||
:debugger => false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def initialize(watchers = [], options = {})
|
def initialize(watchers = [], options = {})
|
||||||
@ -25,21 +23,19 @@ module Guard
|
|||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
server = options[:server] ? "#{options[:server]} and " : ""
|
UI.info "Guard::Rails will now restart your app on port #{options[:port]} using #{options[:environment]} environment."
|
||||||
UI.info "Guard::Rails will now restart your app on port #{options[:port]} using #{server}#{options[:environment]} environment."
|
run_all if options[:start_on_start]
|
||||||
reload("start") if options[:start_on_start]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def reload(action = "restart")
|
def run_all
|
||||||
action_cap = action.capitalize
|
UI.info "Restarting Rails..."
|
||||||
UI.info "#{action_cap}ing Rails..."
|
Notifier.notify("Rails restarting on port #{options[:port]} in #{options[:environment]} environment...", :title => "Restarting Rails...", :image => :pending)
|
||||||
Notifier.notify("Rails #{action}ing on port #{options[:port]} in #{options[:environment]} environment...", :title => "#{action_cap}ing Rails...", :image => :pending)
|
|
||||||
if runner.restart
|
if runner.restart
|
||||||
UI.info "Rails #{action}ed, pid #{runner.pid}"
|
UI.info "Rails restarted, pid #{runner.pid}"
|
||||||
Notifier.notify("Rails #{action}ed on port #{options[:port]}.", :title => "Rails #{action}ed!", :image => :success)
|
Notifier.notify("Rails restarted on port #{options[:port]}.", :title => "Rails restarted!", :image => :success)
|
||||||
else
|
else
|
||||||
UI.info "Rails NOT #{action}ed, check your log files."
|
UI.info "Rails NOT restarted, check your log files."
|
||||||
Notifier.notify("Rails NOT #{action}ed, check your log files.", :title => "Rails NOT #{action}ed!", :image => :failed)
|
Notifier.notify("Rails NOT restarted, check your log files.", :title => "Rails NOT restarted!", :image => :failed)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -48,11 +44,9 @@ module Guard
|
|||||||
runner.stop
|
runner.stop
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_on_changes(paths)
|
def run_on_change(paths)
|
||||||
reload
|
run_all
|
||||||
end
|
end
|
||||||
|
|
||||||
alias :run_on_change :run_on_changes
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ module Guard
|
|||||||
|
|
||||||
def stop
|
def stop
|
||||||
if File.file?(pid_file)
|
if File.file?(pid_file)
|
||||||
system %{kill -SIGINT #{File.read(pid_file).strip}}
|
system %{kill -KILL #{File.read(pid_file).strip}}
|
||||||
wait_for_no_pid if $?.exitstatus == 0
|
wait_for_no_pid if $?.exitstatus == 0
|
||||||
FileUtils.rm pid_file, :force => true
|
FileUtils.rm pid_file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -37,10 +37,8 @@ module Guard
|
|||||||
]
|
]
|
||||||
|
|
||||||
rails_options << '-d' if options[:daemon]
|
rails_options << '-d' if options[:daemon]
|
||||||
rails_options << '-u' if options[:debugger]
|
|
||||||
rails_options << options[:server] if options[:server]
|
|
||||||
|
|
||||||
%{sh -c 'cd #{Dir.pwd} && RAILS_ENV=#{options[:environment]} rails s #{rails_options.join(' ')} &'}
|
%{sh -c 'cd #{Dir.pwd} && rails s #{rails_options.join(' ')} &'}
|
||||||
end
|
end
|
||||||
|
|
||||||
def pid_file
|
def pid_file
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module GuardRails
|
module GuardRails
|
||||||
VERSION = '0.1.1'
|
VERSION = '0.0.3'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ describe Guard::RailsRunner do
|
|||||||
let(:pid) { 12345 }
|
let(:pid) { 12345 }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
FileUtils.mkdir_p File.split(runner.pid_file).first
|
|
||||||
File.open(runner.pid_file, 'w') { |fh| fh.print pid }
|
File.open(runner.pid_file, 'w') { |fh| fh.print pid }
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -47,22 +46,6 @@ describe Guard::RailsRunner do
|
|||||||
runner.build_rails_command.should match(%r{ -d})
|
runner.build_rails_command.should match(%r{ -d})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'debugger' do
|
|
||||||
let(:options) { default_options.merge(:debugger => true) }
|
|
||||||
|
|
||||||
it "should have a debugger switch" do
|
|
||||||
runner.build_rails_command.should match(%r{ -u})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'custom server' do
|
|
||||||
let(:options) { default_options.merge(:server => 'thin') }
|
|
||||||
|
|
||||||
it "should have the server name" do
|
|
||||||
runner.build_rails_command.should match(%r{thin})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#start' do
|
describe '#start' do
|
||||||
|
@ -19,7 +19,7 @@ describe Guard::Rails do
|
|||||||
|
|
||||||
context 'start on start' do
|
context 'start on start' do
|
||||||
it "should show the right message and run startup" do
|
it "should show the right message and run startup" do
|
||||||
guard.expects(:reload).once
|
guard.expects(:run_all).once
|
||||||
ui_expectation
|
ui_expectation
|
||||||
guard.start
|
guard.start
|
||||||
end
|
end
|
||||||
@ -29,44 +29,24 @@ describe Guard::Rails do
|
|||||||
let(:options) { { :start_on_start => false } }
|
let(:options) { { :start_on_start => false } }
|
||||||
|
|
||||||
it "should show the right message and not run startup" do
|
it "should show the right message and not run startup" do
|
||||||
guard.expects(:reload).never
|
guard.expects(:run_all).never
|
||||||
ui_expectation
|
ui_expectation
|
||||||
guard.start
|
guard.start
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#reload' do
|
describe '#run_all' do
|
||||||
let(:pid) { '12345' }
|
let(:pid) { '12345' }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
Guard::UI.expects(:info).with('Restarting Rails...')
|
||||||
|
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails restarting/), has_entry(:image => :pending))
|
||||||
Guard::RailsRunner.any_instance.stubs(:pid).returns(pid)
|
Guard::RailsRunner.any_instance.stubs(:pid).returns(pid)
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:runner_stub) { Guard::RailsRunner.any_instance.stubs(:restart) }
|
let(:runner_stub) { Guard::RailsRunner.any_instance.stubs(:restart) }
|
||||||
|
|
||||||
context 'at start' do
|
|
||||||
before do
|
|
||||||
Guard::UI.expects(:info).with('Starting Rails...')
|
|
||||||
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails starting/), has_entry(:image => :pending))
|
|
||||||
runner_stub.returns(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should start and show the pid file" do
|
|
||||||
Guard::UI.expects(:info).with(regexp_matches(/#{pid}/))
|
|
||||||
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails started/), has_entry(:image => :success))
|
|
||||||
|
|
||||||
guard.reload("start")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'after start' do
|
|
||||||
before do
|
|
||||||
Guard::RailsRunner.any_instance.stubs(:pid).returns(pid)
|
|
||||||
Guard::UI.expects(:info).with('Restarting Rails...')
|
|
||||||
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails restarting/), has_entry(:image => :pending))
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'with pid file' do
|
context 'with pid file' do
|
||||||
before do
|
before do
|
||||||
runner_stub.returns(true)
|
runner_stub.returns(true)
|
||||||
@ -76,7 +56,7 @@ describe Guard::Rails do
|
|||||||
Guard::UI.expects(:info).with(regexp_matches(/#{pid}/))
|
Guard::UI.expects(:info).with(regexp_matches(/#{pid}/))
|
||||||
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails restarted/), has_entry(:image => :success))
|
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails restarted/), has_entry(:image => :success))
|
||||||
|
|
||||||
guard.reload
|
guard.run_all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -90,8 +70,7 @@ describe Guard::Rails do
|
|||||||
Guard::UI.expects(:info).with(regexp_matches(/Rails NOT restarted/))
|
Guard::UI.expects(:info).with(regexp_matches(/Rails NOT restarted/))
|
||||||
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails NOT restarted/), has_entry(:image => :failed))
|
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails NOT restarted/), has_entry(:image => :failed))
|
||||||
|
|
||||||
guard.reload
|
guard.run_all
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -104,8 +83,8 @@ describe Guard::Rails do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#run_on_change' do
|
describe '#run_on_change' do
|
||||||
it "should reload on change" do
|
it "should run on change" do
|
||||||
guard.expects(:reload).once
|
guard.expects(:run_all).once
|
||||||
guard.run_on_change([])
|
guard.run_on_change([])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user