guard-compat 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a717c9cc74638fef19735c7029e547853fd957d0
4
- data.tar.gz: 4e2f952d70ce108ec8cf2b473f98499690a45285
3
+ metadata.gz: dac5757ac72c5138cbe1e418d03c0940369134f9
4
+ data.tar.gz: 742bdf3df8a9dad0ff0ba6e625aa2357b0a000c8
5
5
  SHA512:
6
- metadata.gz: 857bca959b9ffd37e30537cea11574dfb3d6c4a402f59375e435da8548ac43e9d22e1276e7c0aee5217634606906441807389d5b1548942e2b8c2eb7af782037
7
- data.tar.gz: db48127d844b15360e34e787226e70b3cf4bac4f89a688373c3a38b4c184ad0a2bf6fa26de465530b453c72212bc974541213d4c72f356fbface2f8aaa363035
6
+ metadata.gz: e25d27e907b888ee18a59d227b96ad7f5a728fcaf0370e995b8567d101171a0946e038093cc5c918198be3f8e2e16912b10cb5c79cc5e3dd876943057ceecfdc
7
+ data.tar.gz: d2082d551d671421e7f30e60017f86e6f9d842263b7bbc65731109dece82d101ca5e8fbed56753f669a06be3cc313aaf714e22347a07a05ec9c6c055ed23004a
data/README.md CHANGED
@@ -40,6 +40,10 @@ require 'guard/myplugin'
40
40
 
41
41
  # And your tests instantiating your plugin go here...
42
42
  ```
43
+
44
+ (OPTIONAL: if your plugin consists of many files, you may prefer to add the two above requires to your `spec/spec_helper.rb` or test setup files)
45
+
46
+
43
47
  ## Example
44
48
 
45
49
  See [lib/guard/compat/example.rb](https://github.com/guard/guard-compat/blob/master/lib/guard/compat/example.rb ) for an example plugin implementation.
@@ -4,25 +4,30 @@
4
4
  module Guard
5
5
  class MyPlugin < Plugin
6
6
  def start
7
- Guard::Notifier.notify('foo')
7
+ Guard::Compat::UI.notify('foo')
8
+ Guard::Compat::UI.color('foo')
8
9
 
9
- Guard::UI.info('foo')
10
- Guard::UI.warning('foo')
11
- Guard::UI.error('foo')
12
- Guard::UI.debug('foo')
13
- Guard::UI.deprecation('foo')
10
+ Guard::Compat::UI.info('foo')
11
+ Guard::Compat::UI.warning('foo')
12
+ Guard::Compat::UI.error('foo')
13
+ Guard::Compat::UI.debug('foo')
14
+ Guard::Compat::UI.deprecation('foo')
14
15
  end
15
16
 
16
17
  def run_all
17
- Guard::Notifier.notify('foo', title: 'bar')
18
+ Guard::Compat::UI.notify('foo', bar: :baz)
19
+ Guard::Compat::UI.color('foo', :white)
18
20
 
19
- Guard::UI.info('foo', bar: :baz)
20
- Guard::UI.warning('foo', bar: :baz)
21
- Guard::UI.error('foo', bar: :baz)
22
- Guard::UI.debug('foo', bar: :baz)
23
- Guard::UI.deprecation('foo', bar: :baz)
21
+ Guard::Compat::UI.info('foo', bar: :baz)
22
+ Guard::Compat::UI.warning('foo', bar: :baz)
23
+ Guard::Compat::UI.error('foo', bar: :baz)
24
+ Guard::Compat::UI.debug('foo', bar: :baz)
25
+ Guard::Compat::UI.deprecation('foo', bar: :baz)
26
+ end
24
27
 
25
- Guard::UI.color_enabled?
28
+ def run_on_modifications
29
+ Guard::Compat::UI.color_enabled?
30
+ Guard::Compat.matching_files(self, ['foo'])
26
31
  end
27
32
  end
28
33
  end
@@ -11,8 +11,60 @@ unless Guard.const_defined?('Plugin')
11
11
  # (e.g. when added to a Gemfile without `require: false`)
12
12
  module Guard
13
13
  class Plugin
14
- def initialize
15
- fail NotImplementedError
14
+ def initialize(_options = {})
15
+ msg = 'either Guard has not been required or you did not' \
16
+ ' include guard/compat/test/helper'
17
+ fail NotImplementedError, msg
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ module Guard
24
+ module Compat
25
+ # TODO: this is just a temporary workaround to allow plugins
26
+ # to use watcher patterns in run_all
27
+ def self.matching_files(plugin, files)
28
+ unless Guard.const_defined?('Watcher')
29
+ msg = 'either Guard has not been required or you did not' \
30
+ ' stub this method in your plugin tests'
31
+ fail NotImplementedError, msg
32
+ end
33
+
34
+ Guard::Watcher.match_files(plugin, files)
35
+ end
36
+
37
+ module UI
38
+ def self.color(text, *colors)
39
+ Guard::UI.send(:color, text, *colors)
40
+ end
41
+
42
+ def self.color_enabled?
43
+ Guard::UI.send(:color_enabled?)
44
+ end
45
+
46
+ def self.info(message, options = {})
47
+ Guard::UI.info(message, options)
48
+ end
49
+
50
+ def self.warning(message, options = {})
51
+ Guard::UI.warning(message, options)
52
+ end
53
+
54
+ def self.error(message, options = {})
55
+ Guard::UI.warning(message, options)
56
+ end
57
+
58
+ def self.debug(message, options = {})
59
+ Guard::UI.warning(message, options)
60
+ end
61
+
62
+ def self.deprecation(message, options = {})
63
+ Guard::UI.warning(message, options)
64
+ end
65
+
66
+ def self.notify(message, options = {})
67
+ Guard::Notifier.notify(message, options)
16
68
  end
17
69
  end
18
70
  end
@@ -3,9 +3,12 @@
3
3
  require 'guard/compat/plugin'
4
4
 
5
5
  module Guard
6
+ # Monkey patch Plugin to just keep the interface
6
7
  class Plugin
7
8
  attr_reader :options
8
9
 
10
+ remove_method(:initialize)
11
+
9
12
  def initialize(options = {})
10
13
  @options = options
11
14
  end
@@ -15,9 +18,8 @@ module Guard
15
18
  # is while guard-process is being tested
16
19
  unless Guard.const_defined?('Notifier')
17
20
  module Notifier
18
- def self.notify(_msg, _options = {})
19
- fail NotImplementedError, 'stub this method in your tests'
20
- end
21
+ # NOTE: do not implement anything here, so using any UI methods
22
+ # causes tests to fail
21
23
  end
22
24
  end
23
25
 
@@ -25,29 +27,8 @@ module Guard
25
27
  # through using Guard::Notifier
26
28
  unless Guard.const_defined?('UI')
27
29
  module UI
28
- def self.info(_msg, _options = {})
29
- fail NotImplementedError, 'stub this method in your tests'
30
- end
31
-
32
- def self.warning(_msg, _options = {})
33
- fail NotImplementedError, 'stub this method in your tests'
34
- end
35
-
36
- def self.error(_msg, _options = {})
37
- fail NotImplementedError, 'stub this method in your tests'
38
- end
39
-
40
- def self.debug(_msg, _options = {})
41
- fail NotImplementedError, 'stub this method in your tests'
42
- end
43
-
44
- def self.deprecation(_msg, _options = {})
45
- fail NotImplementedError, 'stub this method in your tests'
46
- end
47
-
48
- def self.color_enabled?
49
- fail NotImplementedError, 'stub this method in your tests'
50
- end
30
+ # NOTE: do not implement anything here, so using any UI methods
31
+ # causes tests to fail
51
32
  end
52
33
  end
53
34
  end
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module Compat
3
- VERSION = '0.3.0'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
@@ -7,12 +7,10 @@ RSpec.describe Guard::MyPlugin, exclude_stubs: [Guard::Plugin] do
7
7
  subject { described_class.new(options) }
8
8
 
9
9
  before do
10
- allow(Guard::Notifier).to receive(:notify)
11
- %w(info warning error deprecation debug).each do |type|
12
- allow(Guard::UI).to receive(type.to_sym)
10
+ meths = %w(info warning error deprecation debug notify color color_enabled?)
11
+ meths.each do |type|
12
+ allow(Guard::Compat::UI).to receive(type.to_sym)
13
13
  end
14
-
15
- allow(Guard::UI).to receive(:color_enabled?).and_return(false)
16
14
  end
17
15
 
18
16
  it 'passes options' do
@@ -23,31 +21,32 @@ RSpec.describe Guard::MyPlugin, exclude_stubs: [Guard::Plugin] do
23
21
  expect { described_class.new }.to_not raise_error
24
22
  end
25
23
 
26
- it 'uses the notifier' do
27
- expect(Guard::Notifier).to receive(:notify).with('foo')
28
- subject.start
29
- end
30
-
31
- it 'uses the notifier with options' do
32
- expect(Guard::Notifier).to receive(:notify).with('foo', title: 'bar')
33
- subject.run_all
24
+ describe '#start' do
25
+ before { subject.start }
26
+ %w(info warning error deprecation debug notify).each do |type|
27
+ specify do
28
+ expect(Guard::Compat::UI).to have_received(type.to_sym).with('foo')
29
+ end
30
+ end
34
31
  end
35
32
 
36
- %w(info warning error deprecation debug).each do |type|
37
- it "outputs #{type} messages" do
38
- expect(Guard::UI).to receive(type.to_sym).with('foo')
39
- subject.start
33
+ describe '#run_all' do
34
+ before { subject.run_all }
35
+ %w(info warning error deprecation debug notify).each do |type|
36
+ specify do
37
+ expect(Guard::Compat::UI).to have_received(type.to_sym)
38
+ .with('foo', bar: :baz)
39
+ end
40
40
  end
41
+ end
41
42
 
42
- it "outputs #{type} messages with options" do
43
- expect(Guard::UI).to receive(type.to_sym).with('foo', bar: :baz)
44
- subject.run_all
43
+ describe '#run_on_modifications' do
44
+ before do
45
+ allow(Guard::Compat).to receive(:matching_files)
45
46
  end
46
- end
47
47
 
48
- it 'uses the UI color_enabled? method' do
49
- expect(Guard::UI).to receive(:color_enabled?).and_return(true)
50
- subject.run_all
48
+ before { subject.run_on_modifications }
49
+ specify { expect(Guard::Compat::UI).to have_received(:color_enabled?) }
50
+ specify { expect(Guard::Compat).to have_received(:matching_files) }
51
51
  end
52
-
53
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-compat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cezary Baginski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-06 00:00:00.000000000 Z
11
+ date: 2014-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler