Skip to content

Commit

Permalink
Update Guard::Resque to work with Guard versions after 2.9.0
Browse files Browse the repository at this point in the history
The `Guard::Resque` plugin was inheriting from `Guard::Guard` which was
deprecated and then later removed in guard version 2.9.0. This commit
adjusts the plugin to inherit from `Guard::Plugin` to allow it to work
with versions of guard after 2.9.0.
  • Loading branch information
Keith Thompson committed Dec 5, 2014
1 parent 5531705 commit 534030c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/guard/resque.rb
@@ -1,9 +1,9 @@
require 'guard'
require 'guard/guard'
require 'guard/plugin'
require 'timeout'

module Guard
class Resque < Guard
class Resque < Plugin

DEFAULT_SIGNAL = :QUIT
DEFAULT_QUEUE = '*'.freeze
Expand All @@ -21,7 +21,7 @@ class Resque < Guard
# - :vverbose e.g. true
# - :trace e.g. true
# - :stop_signal e.g. :QUIT or :SIGQUIT
def initialize(watchers = [], options = {})
def initialize(options = {})
@options = options
@pid = nil
@stop_signal = options[:stop_signal] || DEFAULT_SIGNAL
Expand Down
35 changes: 26 additions & 9 deletions spec/guard/resque_spec.rb
@@ -1,54 +1,71 @@
require 'spec_helper'

describe Guard::Resque do

let(:default) { instance_double("Guard::Group") }
let(:test) { instance_double("Guard::Group") }

let(:session) { instance_double("Guard::Internals::Session") }
let(:groups) { instance_double("Guard::Internals::Groups") }
let(:state) { instance_double("Guard::Internals::State") }

before do
allow(groups).to receive(:add).with(:default).and_return(default)
allow(groups).to receive(:add).with(:test).and_return(test)

allow(session).to receive(:groups).and_return(groups)
allow(state).to receive(:session).and_return(session)
allow(Guard).to receive(:state).and_return(state)
end

describe 'start' do

it 'should accept :environment option' do
environment = :foo

obj = Guard::Resque.new [], :environment => environment
obj = Guard::Resque.new :environment => environment
obj.send(:env).should include 'RAILS_ENV' => environment.to_s
end

it 'should accept :queue option' do
queue = :foo

obj = Guard::Resque.new [], :queue => queue
obj = Guard::Resque.new :queue => queue
obj.send(:env).should include 'QUEUE' => queue.to_s
end

it 'should accept :count option' do
count = 2

obj = Guard::Resque.new [], :count => count
obj = Guard::Resque.new :count => count
obj.send(:env).should include 'COUNT' => count.to_s
end

it 'should accept :vverbose option' do
obj = Guard::Resque.new [], :vverbose => true
obj = Guard::Resque.new :vverbose => true
obj.send(:env).should include 'VVERBOSE'
end

it 'should accept :verbose option' do
obj = Guard::Resque.new [], :verbose => true
obj = Guard::Resque.new :verbose => true
obj.send(:env).should include 'VERBOSE'
end

it 'should accept :trace option' do
obj = Guard::Resque.new [], :trace => true
obj = Guard::Resque.new :trace => true
obj.send(:cmd).should include '--trace'
end

it 'should accept :task option' do
task = 'environment foo'

obj = Guard::Resque.new [], :task => task
obj = Guard::Resque.new :task => task
obj.send(:cmd).should include task
obj.send(:cmd).should_not include Guard::Resque::DEFAULT_TASK_SINGLE
end

it 'should provide default options' do
obj = Guard::Resque.new []
obj = Guard::Resque.new
obj.send(:env).should include 'QUEUE' => Guard::Resque::DEFAULT_QUEUE.to_s
obj.send(:env).should include 'COUNT' => Guard::Resque::DEFAULT_COUNT.to_s
obj.send(:cmd).should include Guard::Resque::DEFAULT_TASK_SINGLE
Expand All @@ -57,7 +74,7 @@
it 'should provide different default options when :count is multiple' do
count = 2

obj = Guard::Resque.new [], :count => count
obj = Guard::Resque.new :count => count
obj.send(:env).should include 'QUEUE' => Guard::Resque::DEFAULT_QUEUE.to_s
obj.send(:env).should include 'COUNT' => count.to_s
obj.send(:cmd).should include Guard::Resque::DEFAULT_TASK_MULTIPLE
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -4,7 +4,6 @@
ENV['GUARD_ENV'] = 'test'

RSpec.configure do |config|
config.color_enabled = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
end

0 comments on commit 534030c

Please sign in to comment.