Compare commits

...

30 Commits

Author SHA1 Message Date
John Bintz 36d24c0c14 update maintainer message, thanks to @ranmocy for taking over 2013-01-22 10:24:11 -05:00
John Bintz c1344a98b7 bump version 2012-08-24 10:08:49 -04:00
John Bintz 4d3fb9dfcc Merge pull request #18 from mmacedo/environment
Ensure specified environment is used
2012-07-09 05:48:29 -07:00
Michel Pavan Macedo 0435a4c17c Ensure specified environment is used
If for any reason RAILS_ENV was set to test this command will start a
Rails server with test environment:

    rails s -e development

But this one will start with development environment:

    RAILS_ENV=development rails s

I am not sure who is at fault here, but this ensures guard-rails will
always use the environment specified by the environment option.
2012-07-08 06:29:01 -03:00
John Bintz 885fc3c837 Merge branch 'master' of github.com:johnbintz/guard-rails 2012-06-12 14:12:55 -04:00
John Bintz 83b45e914b also make old guard happy 2012-06-12 13:45:57 -04:00
John Bintz 291782e101 make modern guard happy 2012-06-12 13:45:03 -04:00
John Bintz 4d7d44a07a Merge pull request #13 from darrinholst/master
stop server with SIGINT
2012-01-30 08:52:15 -08:00
Darrin Holst 963b9e0ab2 use SIGINT instead of KILL so the pid gets cleaned up 2012-01-30 08:20:47 -06:00
John Bintz 89e18ef84d fix 1.9.3 warning 2012-01-16 09:33:13 -05:00
John Bintz 5d3ceb5626 bump version 2012-01-16 09:31:09 -05:00
John Bintz 9ce3667e35 Merge pull request #12 from ndbroadbent/bump_timeout
Bumped the default timeout to 30 seconds
2012-01-14 07:13:56 -08:00
John Bintz 5c1e36f585 Merge pull request #11 from ndbroadbent/master
Changed notifications at start to say "Rails starting..." instead of "Rails restarting..."
2012-01-14 07:13:23 -08:00
Nathan Broadbent 5a774dca2f Bumped the default timeout to 30 seconds, so that slightly larger apps don't feel left out 2012-01-14 11:52:00 +08:00
Nathan Broadbent 14b8402e1c Fixed notifications at start to say "Rails starting..." and "Rails started!" instead of "restarting". I enjoy accurate messages 2012-01-14 11:42:59 +08:00
John Bintz 70d76d166d Merge branch 'master' of github.com:guard/guard-rails 2011-10-24 11:35:04 -04:00
John Bintz 63c648c035 Merge pull request #8 from tehpeh/reload_instead_of_run_all
Reload instead of run_all
2011-10-18 06:29:44 -07:00
Tim Preston 3ac650799c Swapped run_all for reload.
This means hitting return will not reload rails server,
instead 'r' or 'reload' must be issued.
2011-10-17 14:33:27 +11:00
John Bintz 39e1e4045b add reload method 2011-10-10 11:55:32 -04:00
John Bintz 412a6b69a4 fix b0rken test, i owe you ice cream 2011-09-14 14:19:54 -04:00
John Bintz cda46a0d88 update docs 2011-09-14 14:06:07 -04:00
John Bintz 0a82cb086e Merge pull request #2 from joelmoss/debugger
Added support for setting the debugger (-u flag)
2011-08-25 08:08:11 -07:00
Joel Moss 3d897a7665 debugger is false by default 2011-08-25 15:53:20 +01:00
Joel Moss 7a81802b8c Doh! APpending -u flag instead of iincluding in default 2011-08-25 15:42:39 +01:00
Joel Moss 1dcbbd4d11 Updated README 2011-08-25 15:30:30 +01:00
Joel Moss 585dc242d6 Added support for setting the debugger (-u flag) 2011-08-25 15:26:04 +01:00
John Bintz 3dd64624d1 bump version 2011-08-04 11:32:16 -04:00
John Bintz 16fe8bab53 clean up rake and gem files 2011-08-04 11:31:42 -04:00
John Bintz 45b8b6c4a2 Merge pull request #5 from tehpeh/custom_server
Add custom server to options (:server => 'thin').
2011-08-04 08:28:55 -07:00
Tim Preston 372e2cd24a Add custom server to options (:server => 'thin'). 2011-07-12 22:59:26 +10:00
9 changed files with 95 additions and 57 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
.bundle .bundle
Gemfile.lock Gemfile.lock
pkg/* pkg/*
.rvmrc

View File

@ -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', '0.8.7' gem 'rake'
gem 'fakefs', :require => nil gem 'fakefs', :require => nil
gem 'guard', :git => 'https://github.com/guard/guard.git' gem 'guard'
gem 'guard-rspec' gem 'guard-rspec'
require 'rbconfig' require 'rbconfig'
if Config::CONFIG['target_os'] =~ /darwin/i if RbConfig::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 Config::CONFIG['target_os'] =~ /linux/i if RbConfig::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

View File

@ -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) [![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!
@ -14,7 +16,9 @@ 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.

View File

@ -15,23 +15,10 @@ 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
current = %x{rvm-prompt v} prefix = "rvm 1.8.7,1.9.2,ree,1.9.3 do"
system %{#{prefix} bundle}
fail = false system %{#{prefix} bundle exec rake spec}
%w{1.8.7 1.9.2 ree}.each do |version| exit $?.exitstatus if $?.exitstatus != 0
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

View File

@ -12,7 +12,9 @@ module Guard
:environment => 'development', :environment => 'development',
:start_on_start => true, :start_on_start => true,
:force_run => false, :force_run => false,
:timeout => 20 :timeout => 30,
:server => nil,
:debugger => false
} }
def initialize(watchers = [], options = {}) def initialize(watchers = [], options = {})
@ -23,19 +25,21 @@ module Guard
end end
def start def start
UI.info "Guard::Rails will now restart your app on port #{options[:port]} using #{options[:environment]} environment." server = options[:server] ? "#{options[:server]} and " : ""
run_all if options[:start_on_start] 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 end
def run_all def reload(action = "restart")
UI.info "Restarting Rails..." action_cap = action.capitalize
Notifier.notify("Rails restarting on port #{options[:port]} in #{options[:environment]} environment...", :title => "Restarting Rails...", :image => :pending) 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 if runner.restart
UI.info "Rails restarted, pid #{runner.pid}" UI.info "Rails #{action}ed, pid #{runner.pid}"
Notifier.notify("Rails restarted on port #{options[:port]}.", :title => "Rails restarted!", :image => :success) Notifier.notify("Rails #{action}ed on port #{options[:port]}.", :title => "Rails #{action}ed!", :image => :success)
else else
UI.info "Rails NOT restarted, check your log files." UI.info "Rails NOT #{action}ed, check your log files."
Notifier.notify("Rails NOT restarted, check your log files.", :title => "Rails NOT restarted!", :image => :failed) Notifier.notify("Rails NOT #{action}ed, check your log files.", :title => "Rails NOT #{action}ed!", :image => :failed)
end end
end end
@ -44,9 +48,11 @@ module Guard
runner.stop runner.stop
end end
def run_on_change(paths) def run_on_changes(paths)
run_all reload
end end
alias :run_on_change :run_on_changes
end end
end end

View File

@ -18,12 +18,12 @@ module Guard
def stop def stop
if File.file?(pid_file) 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 wait_for_no_pid if $?.exitstatus == 0
FileUtils.rm pid_file FileUtils.rm pid_file, :force => true
end end
end end
def restart def restart
stop stop
start start
@ -37,8 +37,10 @@ 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 s #{rails_options.join(' ')} &'} %{sh -c 'cd #{Dir.pwd} && RAILS_ENV=#{options[:environment]} rails s #{rails_options.join(' ')} &'}
end end
def pid_file def pid_file

View File

@ -1,4 +1,4 @@
module GuardRails module GuardRails
VERSION = '0.0.3' VERSION = '0.1.1'
end end

View File

@ -17,6 +17,7 @@ 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
@ -46,6 +47,22 @@ 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

View File

@ -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(:run_all).once guard.expects(:reload).once
ui_expectation ui_expectation
guard.start guard.start
end end
@ -29,52 +29,73 @@ 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(:run_all).never guard.expects(:reload).never
ui_expectation ui_expectation
guard.start guard.start
end end
end end
end end
describe '#run_all' do describe '#reload' 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 'with pid file' do context 'at start' do
before 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) runner_stub.returns(true)
end 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::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
end end
context 'no pid file' do context 'after start' do
before 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 end
it "should restart and show the pid file" do context 'with pid file' do
Guard::UI.expects(:info).with(regexp_matches(/#{pid}/)).never before do
Guard::UI.expects(:info).with(regexp_matches(/Rails NOT restarted/)) runner_stub.returns(true)
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails NOT restarted/), has_entry(:image => :failed)) 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 end
end end
describe '#stop' do describe '#stop' do
it "should stop correctly" do it "should stop correctly" do
Guard::Notifier.expects(:notify).with('Until next time...', anything) Guard::Notifier.expects(:notify).with('Until next time...', anything)
@ -83,8 +104,8 @@ describe Guard::Rails do
end end
describe '#run_on_change' do describe '#run_on_change' do
it "should run on change" do it "should reload on change" do
guard.expects(:run_all).once guard.expects(:reload).once
guard.run_on_change([]) guard.run_on_change([])
end end
end end