write some tests

This commit is contained in:
John Bintz 2011-06-03 09:18:16 -04:00
parent 1bc4fb1a99
commit 6439609a8a
3 changed files with 50 additions and 6 deletions

View File

@ -3,5 +3,11 @@ 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', '0.8.7'
gem 'growl'
gem 'fakefs', :require => nil 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'

View File

@ -7,21 +7,23 @@ module Guard
class Rails < ::Guard::Guard class Rails < ::Guard::Guard
attr_reader :options, :runner attr_reader :options, :runner
def initialize(watchers = [], options = {}) DEFAULT_OPTIONS = {
super
@options = {
:port => 3000, :port => 3000,
:environment => 'development', :environment => 'development',
:start_on_start => true, :start_on_start => true,
:force_run => false, :force_run => false,
:timeout => 20 :timeout => 20
}.merge(options) }
def initialize(watchers = [], options = {})
super
@options = DEFAULT_OPTIONS.merge(options)
@runner = RailsRunner.new(@options) @runner = RailsRunner.new(@options)
end end
def start 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] run_all if options[:start_on_start]
end end

View File

@ -14,6 +14,28 @@ describe Guard::Rails do
end end
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 describe '#run_all' do
let(:pid) { '12345' } let(:pid) { '12345' }
@ -52,5 +74,19 @@ describe Guard::Rails do
end end
end 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 end