Compare commits
30 Commits
linux-supp
...
master
Author | SHA1 | Date |
---|---|---|
John Bintz | 36d24c0c14 | |
John Bintz | c1344a98b7 | |
John Bintz | 4d3fb9dfcc | |
Michel Pavan Macedo | 0435a4c17c | |
John Bintz | 885fc3c837 | |
John Bintz | 83b45e914b | |
John Bintz | 291782e101 | |
John Bintz | 4d7d44a07a | |
Darrin Holst | 963b9e0ab2 | |
John Bintz | 89e18ef84d | |
John Bintz | 5d3ceb5626 | |
John Bintz | 9ce3667e35 | |
John Bintz | 5c1e36f585 | |
Nathan Broadbent | 5a774dca2f | |
Nathan Broadbent | 14b8402e1c | |
John Bintz | 70d76d166d | |
John Bintz | 63c648c035 | |
Tim Preston | 3ac650799c | |
John Bintz | 39e1e4045b | |
John Bintz | 412a6b69a4 | |
John Bintz | cda46a0d88 | |
John Bintz | 0a82cb086e | |
Joel Moss | 3d897a7665 | |
Joel Moss | 7a81802b8c | |
Joel Moss | 1dcbbd4d11 | |
Joel Moss | 585dc242d6 | |
John Bintz | 3dd64624d1 | |
John Bintz | 16fe8bab53 | |
John Bintz | 45b8b6c4a2 | |
Tim Preston | 372e2cd24a |
|
@ -2,3 +2,4 @@
|
|||
.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', '0.8.7'
|
||||
gem 'rake'
|
||||
gem 'fakefs', :require => nil
|
||||
gem 'guard', :git => 'https://github.com/guard/guard.git'
|
||||
gem 'guard'
|
||||
gem 'guard-rspec'
|
||||
|
||||
require 'rbconfig'
|
||||
if Config::CONFIG['target_os'] =~ /darwin/i
|
||||
if RbConfig::CONFIG['target_os'] =~ /darwin/i
|
||||
gem 'rb-fsevent', '>= 0.3.9'
|
||||
gem 'growl', '~> 1.0.3'
|
||||
end
|
||||
if Config::CONFIG['target_os'] =~ /linux/i
|
||||
if RbConfig::CONFIG['target_os'] =~ /linux/i
|
||||
gem 'rb-inotify', '>= 0.5.1'
|
||||
gem 'libnotify', '~> 0.1.3'
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
_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!
|
||||
|
@ -14,7 +16,9 @@ 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,23 +15,10 @@ RSpec::Core::RakeTask.new(:spec)
|
|||
namespace :spec do
|
||||
desc "Run on three Rubies"
|
||||
task :platforms do
|
||||
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)
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,9 @@ module Guard
|
|||
:environment => 'development',
|
||||
:start_on_start => true,
|
||||
:force_run => false,
|
||||
:timeout => 20
|
||||
:timeout => 30,
|
||||
:server => nil,
|
||||
:debugger => false
|
||||
}
|
||||
|
||||
def initialize(watchers = [], options = {})
|
||||
|
@ -23,19 +25,21 @@ module Guard
|
|||
end
|
||||
|
||||
def 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]
|
||||
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]
|
||||
end
|
||||
|
||||
def run_all
|
||||
UI.info "Restarting Rails..."
|
||||
Notifier.notify("Rails restarting on port #{options[:port]} in #{options[:environment]} environment...", :title => "Restarting Rails...", :image => :pending)
|
||||
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)
|
||||
if runner.restart
|
||||
UI.info "Rails restarted, pid #{runner.pid}"
|
||||
Notifier.notify("Rails restarted on port #{options[:port]}.", :title => "Rails restarted!", :image => :success)
|
||||
UI.info "Rails #{action}ed, pid #{runner.pid}"
|
||||
Notifier.notify("Rails #{action}ed on port #{options[:port]}.", :title => "Rails #{action}ed!", :image => :success)
|
||||
else
|
||||
UI.info "Rails NOT restarted, check your log files."
|
||||
Notifier.notify("Rails NOT restarted, check your log files.", :title => "Rails NOT restarted!", :image => :failed)
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -44,9 +48,11 @@ module Guard
|
|||
runner.stop
|
||||
end
|
||||
|
||||
def run_on_change(paths)
|
||||
run_all
|
||||
def run_on_changes(paths)
|
||||
reload
|
||||
end
|
||||
|
||||
alias :run_on_change :run_on_changes
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -18,12 +18,12 @@ module Guard
|
|||
|
||||
def stop
|
||||
if File.file?(pid_file)
|
||||
system %{kill -KILL #{File.read(pid_file).strip}}
|
||||
system %{kill -SIGINT #{File.read(pid_file).strip}}
|
||||
wait_for_no_pid if $?.exitstatus == 0
|
||||
FileUtils.rm pid_file
|
||||
FileUtils.rm pid_file, :force => true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def restart
|
||||
stop
|
||||
start
|
||||
|
@ -37,8 +37,10 @@ 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 s #{rails_options.join(' ')} &'}
|
||||
%{sh -c 'cd #{Dir.pwd} && RAILS_ENV=#{options[:environment]} rails s #{rails_options.join(' ')} &'}
|
||||
end
|
||||
|
||||
def pid_file
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module GuardRails
|
||||
VERSION = '0.0.3'
|
||||
VERSION = '0.1.1'
|
||||
end
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ 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
|
||||
|
||||
|
@ -46,6 +47,22 @@ 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(:run_all).once
|
||||
guard.expects(:reload).once
|
||||
ui_expectation
|
||||
guard.start
|
||||
end
|
||||
|
@ -29,52 +29,73 @@ describe Guard::Rails do
|
|||
let(:options) { { :start_on_start => false } }
|
||||
|
||||
it "should show the right message and not run startup" do
|
||||
guard.expects(:run_all).never
|
||||
guard.expects(:reload).never
|
||||
ui_expectation
|
||||
guard.start
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#run_all' do
|
||||
describe '#reload' 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 'with pid file' do
|
||||
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 restart and show the pid file" do
|
||||
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 restarted/), has_entry(:image => :success))
|
||||
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails started/), has_entry(:image => :success))
|
||||
|
||||
guard.run_all
|
||||
guard.reload("start")
|
||||
end
|
||||
end
|
||||
|
||||
context 'no pid file' do
|
||||
context 'after start' do
|
||||
before do
|
||||
runner_stub.returns(false)
|
||||
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
|
||||
|
||||
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))
|
||||
context 'with pid file' do
|
||||
before do
|
||||
runner_stub.returns(true)
|
||||
end
|
||||
|
||||
guard.run_all
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe '#stop' do
|
||||
it "should stop correctly" do
|
||||
Guard::Notifier.expects(:notify).with('Until next time...', anything)
|
||||
|
@ -83,8 +104,8 @@ describe Guard::Rails do
|
|||
end
|
||||
|
||||
describe '#run_on_change' do
|
||||
it "should run on change" do
|
||||
guard.expects(:run_all).once
|
||||
it "should reload on change" do
|
||||
guard.expects(:reload).once
|
||||
guard.run_on_change([])
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue