Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions lib/guard/compat/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,37 @@
# a stub will be supplied by the test class

module Guard
class MyPlugin < Plugin
def start
Guard::Compat::UI.notify('foo')
Guard::Compat::UI.color('foo')
module MyPlugin
class Plugin
include Compat::API

Guard::Compat::UI.info('foo')
Guard::Compat::UI.warning('foo')
Guard::Compat::UI.error('foo')
Guard::Compat::UI.debug('foo')
Guard::Compat::UI.deprecation('foo')
end
def start
Guard::Compat::UI.notify('foo')
Guard::Compat::UI.color('foo')

def run_all
Guard::Compat::UI.notify('foo', bar: :baz)
Guard::Compat::UI.color('foo', :white)
Guard::Compat::UI.info('foo')
Guard::Compat::UI.warning('foo')
Guard::Compat::UI.error('foo')
Guard::Compat::UI.debug('foo')
Guard::Compat::UI.deprecation('foo')
end

Guard::Compat::UI.info('foo', bar: :baz)
Guard::Compat::UI.warning('foo', bar: :baz)
Guard::Compat::UI.error('foo', bar: :baz)
Guard::Compat::UI.debug('foo', bar: :baz)
Guard::Compat::UI.deprecation('foo', bar: :baz)
end
def run_all
Guard::Compat::UI.notify('foo', bar: :baz)
Guard::Compat::UI.color('foo', :white)

Guard::Compat::UI.info('foo', bar: :baz)
Guard::Compat::UI.warning('foo', bar: :baz)
Guard::Compat::UI.error('foo', bar: :baz)
Guard::Compat::UI.debug('foo', bar: :baz)
Guard::Compat::UI.deprecation('foo', bar: :baz)
end

def run_on_modifications
Guard::Compat::UI.color_enabled?
Guard::Compat.matching_files(self, ['foo'])
Guard::Compat.watched_directories
def run_on_modifications
Guard::Compat::UI.color_enabled?
Guard::Compat.matching_files(self, ['foo'])
Guard::Compat.watched_directories
end
end
end
end
11 changes: 11 additions & 0 deletions lib/guard/compat/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ def self.watched_directories
end
end

module API
def self.included(base)
if base.ancestors.any? { |c| c.name == 'Guard::Plugin' }
fail ArgumentError, 'You cannot include Guard::Compat::API in a'\
" class that inherits from Guard::Plugin: #{base.name}"
end

base.include(Guard::API) if Guard.const_defined?('API')
end
end

module UI
def self.color(text, *colors)
if Guard.const_defined?(:UI)
Expand Down
9 changes: 9 additions & 0 deletions lib/guard/compat/test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ def initialize(options = {})
remove_method(:old_initialize)
end

# Monkey patch API to just keep the interface
module API
attr_reader :options

def initialize(options = {})
@options = options
end
end

# Stub, but allow real Notifier to be used, because e.g. guard-minitest uses
# is while guard-process is being tested
unless Guard.const_defined?('Notifier')
Expand Down
2 changes: 1 addition & 1 deletion spec/guard/compat/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'guard/compat/test/helper'
require 'guard/compat/example'

RSpec.describe Guard::MyPlugin, exclude_stubs: [Guard::Plugin] do
RSpec.describe Guard::MyPlugin::Plugin do
let(:options) { { foo: :bar } }
subject { described_class.new(options) }

Expand Down