From 2b0d43bd01c32363b4919bca372973224b3cbab1 Mon Sep 17 00:00:00 2001 From: Roberto Vasquez Angel Date: Sat, 4 Aug 2012 15:19:53 +0200 Subject: [PATCH] Added rails_root option for engine support. --- README.md | 1 + lib/guard/rails.rb | 3 ++- lib/guard/rails/runner.rb | 12 ++++++++++-- spec/lib/guard/rails/runner_spec.rb | 8 ++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2bf3cb5..4402e77 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Lots of fun options! * `: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`). +* `:rails_root` lets you specify the root directory of your app (try `:rails_root => 'test/dummy` for engines). 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. diff --git a/lib/guard/rails.rb b/lib/guard/rails.rb index dab9058..ffa78cf 100644 --- a/lib/guard/rails.rb +++ b/lib/guard/rails.rb @@ -14,7 +14,8 @@ module Guard :force_run => false, :timeout => 30, :server => nil, - :debugger => false + :debugger => false, + :rails_root => nil } def initialize(watchers = [], options = {}) diff --git a/lib/guard/rails/runner.rb b/lib/guard/rails/runner.rb index fea5996..27c6ad0 100644 --- a/lib/guard/rails/runner.rb +++ b/lib/guard/rails/runner.rb @@ -40,11 +40,19 @@ module Guard 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 #{build_rails_path} && RAILS_ENV=#{options[:environment]} rails s #{rails_options.join(' ')} &'} + end + + def build_rails_path + if options[:rails_root] + File.join(Dir.pwd, options[:rails_root]) + else + Dir.pwd + end end def pid_file - File.expand_path("tmp/pids/#{options[:environment]}.pid") + File.expand_path(File.join(options[:rails_root].to_s, "tmp/pids/#{options[:environment]}.pid")) end def pid diff --git a/spec/lib/guard/rails/runner_spec.rb b/spec/lib/guard/rails/runner_spec.rb index 182705c..7207040 100644 --- a/spec/lib/guard/rails/runner_spec.rb +++ b/spec/lib/guard/rails/runner_spec.rb @@ -63,6 +63,14 @@ describe Guard::RailsRunner do runner.build_rails_command.should match(%r{thin}) end end + + context 'custom app path' do + let(:options) { default_options.merge(:app_path => 'spec/dummy') } + + it "should have the app path" do + runner.build_rails_command.should match(%r{spec/dummy}) + end + end end describe '#start' do