Skip to content
This repository has been archived by the owner on Jul 23, 2023. It is now read-only.

Commit

Permalink
write some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbintz committed Jun 3, 2011
1 parent 1bc4fb1 commit 6439609
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
8 changes: 7 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'

12 changes: 7 additions & 5 deletions lib/guard/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 36 additions & 0 deletions spec/lib/guard/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@
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' }

Expand Down Expand Up @@ -52,5 +74,19 @@
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

0 comments on commit 6439609

Please sign in to comment.