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
|
||||
Gemfile.lock
|
||||
pkg/*
|
||||
.rvmrc
|
||||
|
8
Gemfile
8
Gemfile
@ -2,17 +2,17 @@ source "http://rubygems.org"
|
||||
|
||||
# Specify your gem's dependencies in guard-rails.gemspec
|
||||
gemspec
|
||||
gem 'rake'
|
||||
gem 'rake', '0.8.7'
|
||||
gem 'fakefs', :require => nil
|
||||
gem 'guard'
|
||||
gem 'guard', :git => 'https://github.com/guard/guard.git'
|
||||
gem 'guard-rspec'
|
||||
|
||||
require 'rbconfig'
|
||||
if RbConfig::CONFIG['target_os'] =~ /darwin/i
|
||||
if Config::CONFIG['target_os'] =~ /darwin/i
|
||||
gem 'rb-fsevent', '>= 0.3.9'
|
||||
gem 'growl', '~> 1.0.3'
|
||||
end
|
||||
if RbConfig::CONFIG['target_os'] =~ /linux/i
|
||||
if Config::CONFIG['target_os'] =~ /linux/i
|
||||
gem 'rb-inotify', '>= 0.5.1'
|
||||
gem 'libnotify', '~> 0.1.3'
|
||||
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)
|
||||
|
||||
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`)
|
||||
* `: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`).
|
||||
* `: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`).
|
||||
* `: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
|
||||
OSes, and to add some more real tests.
|
||||
|
21
Rakefile
21
Rakefile
@ -15,10 +15,23 @@ RSpec::Core::RakeTask.new(:spec)
|
||||
namespace :spec do
|
||||
desc "Run on three Rubies"
|
||||
task :platforms do
|
||||
prefix = "rvm 1.8.7,1.9.2,ree,1.9.3 do"
|
||||
system %{#{prefix} bundle}
|
||||
system %{#{prefix} bundle exec rake spec}
|
||||
exit $?.exitstatus if $?.exitstatus != 0
|
||||
current = %x{rvm-prompt v}
|
||||
|
||||
fail = false
|
||||
%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
|
||||
|
||||
|
@ -12,9 +12,7 @@ module Guard
|
||||
:environment => 'development',
|
||||
:start_on_start => true,
|
||||
:force_run => false,
|
||||
:timeout => 30,
|
||||
:server => nil,
|
||||
:debugger => false
|
||||
:timeout => 20
|
||||
}
|
||||
|
||||
def initialize(watchers = [], options = {})
|
||||
@ -25,21 +23,19 @@ module Guard
|
||||
end
|
||||
|
||||
def start
|
||||
server = options[:server] ? "#{options[:server]} and " : ""
|
||||
UI.info "Guard::Rails will now restart your app on port #{options[:port]} using #{server}#{options[:environment]} environment."
|
||||
reload("start") if options[:start_on_start]
|
||||
UI.info "Guard::Rails will now restart your app on port #{options[:port]} using #{options[:environment]} environment."
|
||||
run_all if options[:start_on_start]
|
||||
end
|
||||
|
||||
def reload(action = "restart")
|
||||
action_cap = action.capitalize
|
||||
UI.info "#{action_cap}ing Rails..."
|
||||
Notifier.notify("Rails #{action}ing on port #{options[:port]} in #{options[:environment]} environment...", :title => "#{action_cap}ing Rails...", :image => :pending)
|
||||
def run_all
|
||||
UI.info "Restarting Rails..."
|
||||
Notifier.notify("Rails restarting on port #{options[:port]} in #{options[:environment]} environment...", :title => "Restarting Rails...", :image => :pending)
|
||||
if runner.restart
|
||||
UI.info "Rails #{action}ed, pid #{runner.pid}"
|
||||
Notifier.notify("Rails #{action}ed on port #{options[:port]}.", :title => "Rails #{action}ed!", :image => :success)
|
||||
UI.info "Rails restarted, pid #{runner.pid}"
|
||||
Notifier.notify("Rails restarted on port #{options[:port]}.", :title => "Rails restarted!", :image => :success)
|
||||
else
|
||||
UI.info "Rails NOT #{action}ed, check your log files."
|
||||
Notifier.notify("Rails NOT #{action}ed, check your log files.", :title => "Rails NOT #{action}ed!", :image => :failed)
|
||||
UI.info "Rails NOT restarted, check your log files."
|
||||
Notifier.notify("Rails NOT restarted, check your log files.", :title => "Rails NOT restarted!", :image => :failed)
|
||||
end
|
||||
end
|
||||
|
||||
@ -48,11 +44,9 @@ module Guard
|
||||
runner.stop
|
||||
end
|
||||
|
||||
def run_on_changes(paths)
|
||||
reload
|
||||
def run_on_change(paths)
|
||||
run_all
|
||||
end
|
||||
|
||||
alias :run_on_change :run_on_changes
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -18,9 +18,9 @@ module Guard
|
||||
|
||||
def stop
|
||||
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
|
||||
FileUtils.rm pid_file, :force => true
|
||||
FileUtils.rm pid_file
|
||||
end
|
||||
end
|
||||
|
||||
@ -37,10 +37,8 @@ module Guard
|
||||
]
|
||||
|
||||
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
|
||||
|
||||
def pid_file
|
||||
|
@ -1,4 +1,4 @@
|
||||
module GuardRails
|
||||
VERSION = '0.1.1'
|
||||
VERSION = '0.0.3'
|
||||
end
|
||||
|
||||
|
@ -17,7 +17,6 @@ describe Guard::RailsRunner do
|
||||
let(:pid) { 12345 }
|
||||
|
||||
before do
|
||||
FileUtils.mkdir_p File.split(runner.pid_file).first
|
||||
File.open(runner.pid_file, 'w') { |fh| fh.print pid }
|
||||
end
|
||||
|
||||
@ -47,22 +46,6 @@ describe Guard::RailsRunner do
|
||||
runner.build_rails_command.should match(%r{ -d})
|
||||
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
|
||||
|
||||
describe '#start' do
|
||||
|
@ -19,7 +19,7 @@ describe Guard::Rails do
|
||||
|
||||
context 'start on start' do
|
||||
it "should show the right message and run startup" do
|
||||
guard.expects(:reload).once
|
||||
guard.expects(:run_all).once
|
||||
ui_expectation
|
||||
guard.start
|
||||
end
|
||||
@ -29,69 +29,48 @@ describe Guard::Rails do
|
||||
let(:options) { { :start_on_start => false } }
|
||||
|
||||
it "should show the right message and not run startup" do
|
||||
guard.expects(:reload).never
|
||||
guard.expects(:run_all).never
|
||||
ui_expectation
|
||||
guard.start
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#reload' do
|
||||
describe '#run_all' do
|
||||
let(:pid) { '12345' }
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
let(:runner_stub) { Guard::RailsRunner.any_instance.stubs(:restart) }
|
||||
|
||||
context 'at start' do
|
||||
context 'with pid file' 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
|
||||
it "should restart 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::Notifier.expects(:notify).with(regexp_matches(/Rails restarted/), has_entry(:image => :success))
|
||||
|
||||
guard.reload("start")
|
||||
guard.run_all
|
||||
end
|
||||
end
|
||||
|
||||
context 'after start' do
|
||||
context 'no pid file' 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))
|
||||
runner_stub.returns(false)
|
||||
end
|
||||
|
||||
context 'with pid file' do
|
||||
before do
|
||||
runner_stub.returns(true)
|
||||
end
|
||||
it "should restart and show the pid file" do
|
||||
Guard::UI.expects(:info).with(regexp_matches(/#{pid}/)).never
|
||||
Guard::UI.expects(:info).with(regexp_matches(/Rails NOT restarted/))
|
||||
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails NOT restarted/), has_entry(:image => :failed))
|
||||
|
||||
it "should restart and show the pid file" do
|
||||
Guard::UI.expects(:info).with(regexp_matches(/#{pid}/))
|
||||
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails restarted/), has_entry(:image => :success))
|
||||
|
||||
guard.reload
|
||||
end
|
||||
end
|
||||
|
||||
context 'no pid file' do
|
||||
before do
|
||||
runner_stub.returns(false)
|
||||
end
|
||||
|
||||
it "should restart and show the pid file" do
|
||||
Guard::UI.expects(:info).with(regexp_matches(/#{pid}/)).never
|
||||
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.reload
|
||||
end
|
||||
guard.run_all
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -104,8 +83,8 @@ describe Guard::Rails do
|
||||
end
|
||||
|
||||
describe '#run_on_change' do
|
||||
it "should reload on change" do
|
||||
guard.expects(:reload).once
|
||||
it "should run on change" do
|
||||
guard.expects(:run_all).once
|
||||
guard.run_on_change([])
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user