guard-rails-assets/spec/guard/rails-assets_spec.rb

82 lines
2.4 KiB
Ruby
Raw Normal View History

2011-06-17 10:32:50 +00:00
require 'spec_helper'
require 'guard/rails-assets'
describe Guard::RailsAssets do
context 'with any runner' do
2011-06-17 10:32:50 +00:00
let(:options) { {:runner => :cli} }
let(:runner) { mock('runner') }
subject { Guard::RailsAssets.new(['watchers'], options) }
2011-06-17 10:32:50 +00:00
before do
Guard::RailsAssets::CliRunner.stub(:new).and_return runner
end
2011-06-17 10:32:50 +00:00
describe '#start' do
it_behaves_like 'guard command', :command => :start, :run => true
end
2011-06-17 10:32:50 +00:00
describe '#reload' do
it_behaves_like 'guard command', :command => :reload, :run => false
2011-07-16 08:54:35 +00:00
end
describe '#run_all' do
it_behaves_like 'guard command', :command => :run_all, :run => false
2011-07-16 08:54:35 +00:00
end
2011-06-17 10:32:50 +00:00
describe '#run_on_change' do
it_behaves_like 'guard command', :command => :run_on_change, :run => true
end
describe 'run options' do
it 'should allow array of symbols' do
guard = Guard::RailsAssets.new(['watchers'], :run_on => [:start, :change])
guard.run_for?(:start).should be_true
guard.run_for?(:reload).should be_false
end
it 'should allow symbol' do
guard = Guard::RailsAssets.new(['watchers'], :run_on => :start)
guard.run_for?(:start).should be_true
guard.run_for?(:reload).should be_false
end
2011-06-17 10:49:50 +00:00
end
describe 'notifications' do
def stub_system_with result
runner.should_receive(:compile_assets).and_return result
end
it 'should notify on success' do
stub_system_with true
Guard::Notifier.should_receive(:notify).with('Assets compiled')
subject.compile_assets
end
it 'should notify on failure' do
stub_system_with false
Guard::Notifier.should_receive(:notify).with('see the details in the terminal', :title => "Can't compile assets", :image => :failed)
subject.compile_assets
end
2011-06-17 10:49:50 +00:00
end
2011-06-24 04:24:28 +00:00
end # context with any runner
describe 'picking a runner' do
it 'should use Rails runner by default' do
Guard::RailsAssets.new(['watchers']).runner.class.should == ::Guard::RailsAssets::RailsRunner
end
it 'should use CLI runner' do
Guard::RailsAssets.new(['watchers'], :runner => :cli).runner.class.should == ::Guard::RailsAssets::CliRunner
end
it 'should use RailsRunner' do
Guard::RailsAssets.new(['watchers'], :runner => :rails).runner.class.should == ::Guard::RailsAssets::RailsRunner
2011-06-17 10:49:50 +00:00
end
2011-06-17 10:32:50 +00:00
end
end