From 6439609a8a4579b7d07ef90843ab0b82c3b4317d Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 3 Jun 2011 09:18:16 -0400 Subject: [PATCH] write some tests --- Gemfile | 8 +++++++- lib/guard/rails.rb | 12 +++++++----- spec/lib/guard/rails_spec.rb | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index c16c965..e070301 100644 --- a/Gemfile +++ b/Gemfile @@ -3,5 +3,11 @@ source "http://rubygems.org" # Specify your gem's dependencies in guard-rails.gemspec gemspec gem 'rake', '0.8.7' -gem 'growl' gem 'fakefs', :require => nil +gem 'guard' +gem 'guard-rspec' + +# TODO: make this more OS-independent...like the rest of the gem +gem 'growl' +gem 'rb-fsevent' + diff --git a/lib/guard/rails.rb b/lib/guard/rails.rb index 4d87c26..fccb19d 100644 --- a/lib/guard/rails.rb +++ b/lib/guard/rails.rb @@ -7,21 +7,23 @@ module Guard class Rails < ::Guard::Guard attr_reader :options, :runner - def initialize(watchers = [], options = {}) - super - @options = { + DEFAULT_OPTIONS = { :port => 3000, :environment => 'development', :start_on_start => true, :force_run => false, :timeout => 20 - }.merge(options) + } + + def initialize(watchers = [], options = {}) + super + @options = DEFAULT_OPTIONS.merge(options) @runner = RailsRunner.new(@options) end def start - UI.info "Guard::Rails restarting app on port #{options[:port]} using #{options[:environment]} environment." + 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 diff --git a/spec/lib/guard/rails_spec.rb b/spec/lib/guard/rails_spec.rb index 2edd7a7..4047e79 100644 --- a/spec/lib/guard/rails_spec.rb +++ b/spec/lib/guard/rails_spec.rb @@ -14,6 +14,28 @@ describe Guard::Rails do end end + describe '#start' do + let(:ui_expectation) { Guard::UI.expects(:info).with(regexp_matches(/#{Guard::Rails::DEFAULT_OPTIONS[:port]}/)) } + + context 'start on start' do + it "should show the right message and run startup" do + guard.expects(:run_all).once + ui_expectation + guard.start + end + end + + context 'no start on start' do + let(:options) { { :start_on_start => false } } + + it "should show the right message and not run startup" do + guard.expects(:run_all).never + ui_expectation + guard.start + end + end + end + describe '#run_all' do let(:pid) { '12345' } @@ -52,5 +74,19 @@ describe Guard::Rails do end end end + + describe '#stop' do + it "should stop correctly" do + Guard::Notifier.expects(:notify).with('Until next time...', anything) + guard.stop + end + end + + describe '#run_on_change' do + it "should run on change" do + guard.expects(:run_all).once + guard.run_on_change([]) + end + end end