producer-core 0.2.8 → 0.2.9

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: e4762ed57bd74293a1017f2ca3410b27642eae90
4
- data.tar.gz: ad1cd8fa2f52b877951503497c5207eb8a39c92e
3
+ metadata.gz: 0288c1cd99933e1e53201413bc0d8c90a6229204
4
+ data.tar.gz: 5d7aaef70745ce1b3396d775adfa94328a092151
5
5
  SHA512:
6
- metadata.gz: f3b81d877cf394644a533673c78f11078446c0f2392178e258e3496eb9a9d29420b017c26efde01250f4f924ecff163a75e9bf92b92f04828c2dba70f3705e6a
7
- data.tar.gz: 02368fc9778bded5100a90a28e1e6ec3bebc1941db706581151d829d6042e9e7ff3a1cd1fea343b0aaed73237d7e58f6e173cbff8a4b25a24a418186fd1a14c8
6
+ metadata.gz: 2ca8cfca02bec39f6732bf697a2d9111119864c4e7a96176fb87669f0fc5215bb8ffd319cf5e39b90fdf984fb7edb3cfe22f75200f9e464ea89a73585cb60dac
7
+ data.tar.gz: 4786539f7a836eee916c4e278ba8b4206d32b5a6349c5c98e85609c638ce86b99300aa3295fab4d80e5c77cd8f8926a2fa32618beaa638b2fde8bed8c4a5011d
@@ -1,11 +1,17 @@
1
1
  Feature: CLI dry run option
2
2
 
3
- Scenario: perfoms a trial run without applying actions
3
+ Background:
4
4
  Given a recipe with:
5
5
  """
6
6
  task :say_hello do
7
7
  echo 'hello'
8
8
  end
9
9
  """
10
+
11
+ Scenario: perfoms a trial run without applying actions
10
12
  When I successfully execute the recipe with option -n
11
13
  Then the output must not contain "hello"
14
+
15
+ Scenario: prints a warning before any output
16
+ When I successfully execute the recipe with option -n
17
+ Then the output must match /\AWarning: running in dry run mode, actions will NOT be applied/
@@ -27,14 +27,14 @@ module Producer
27
27
  def logger
28
28
  @logger ||= begin
29
29
  logger = Logger.new(output)
30
- logger.level = verbose? ? Logger::INFO : Logger::ERROR
30
+ logger.level = verbose? ? Logger::INFO : Logger::WARN
31
31
  logger.formatter = LoggerFormatter.new
32
32
  logger
33
33
  end
34
34
  end
35
35
 
36
- def log(message)
37
- logger.info message
36
+ def log(message, severity = :info)
37
+ logger.send severity, message
38
38
  end
39
39
 
40
40
  def verbose?
@@ -2,7 +2,14 @@ module Producer
2
2
  module Core
3
3
  class LoggerFormatter < Logger::Formatter
4
4
  def call(severity, datetime, progname, message)
5
- message + "\n"
5
+ prefix(severity) + message + "\n"
6
+ end
7
+
8
+
9
+ private
10
+
11
+ def prefix(severity)
12
+ severity == 'WARN' ? 'Warning: ' : ''
6
13
  end
7
14
  end
8
15
  end
@@ -1,5 +1,5 @@
1
1
  module Producer
2
2
  module Core
3
- VERSION = '0.2.8'.freeze
3
+ VERSION = '0.2.9'.freeze
4
4
  end
5
5
  end
@@ -1,6 +1,9 @@
1
1
  module Producer
2
2
  module Core
3
3
  class Worker
4
+ DRY_RUN_WARNING =
5
+ 'running in dry run mode, actions will NOT be applied'.freeze
6
+
4
7
  attr_accessor :env
5
8
 
6
9
  def initialize(env)
@@ -8,6 +11,8 @@ module Producer
8
11
  end
9
12
 
10
13
  def process(tasks)
14
+ env.log DRY_RUN_WARNING, :warn if env.dry_run?
15
+
11
16
  tasks.each { |t| process_task t }
12
17
  end
13
18
 
@@ -113,8 +113,8 @@ module Producer::Core
113
113
  expect(output.string).to include 'some message'
114
114
  end
115
115
 
116
- it 'has a log level of ERROR' do
117
- expect(env.logger.level).to eq Logger::ERROR
116
+ it 'has a log level of WARN' do
117
+ expect(env.logger.level).to eq Logger::WARN
118
118
  end
119
119
 
120
120
  it 'uses our formatter' do
@@ -135,6 +135,13 @@ module Producer::Core
135
135
  expect(env.logger).to receive(:info).with 'message'
136
136
  env.log 'message'
137
137
  end
138
+
139
+ context 'when second argument is :warn' do
140
+ it 'logs a warning message through the assigned logger' do
141
+ expect(env.logger).to receive(:warn).with 'message'
142
+ env.log 'message', :warn
143
+ end
144
+ end
138
145
  end
139
146
 
140
147
  describe '#verbose?' do
@@ -13,6 +13,14 @@ module Producer::Core
13
13
  it 'returns the given message with a line separator' do
14
14
  expect(subject).to eq "#{message}\n"
15
15
  end
16
+
17
+ context 'when severity is WARN' do
18
+ let(:severity) { 'WARN' }
19
+
20
+ it 'prefix the message with `Warning:\'' do
21
+ expect(subject).to match /\AWarning: #{message}/
22
+ end
23
+ end
16
24
  end
17
25
  end
18
26
  end
@@ -10,6 +10,18 @@ module Producer::Core
10
10
  expect(worker).to receive(:process_task).with(:some_task)
11
11
  worker.process [:some_task]
12
12
  end
13
+
14
+ context 'when dry run is enabled' do
15
+ before { allow(env).to receive(:dry_run?) { true } }
16
+
17
+ it 'warns dry run is enabled' do
18
+ expect(env).to receive(:log).with(
19
+ /\Arunning in dry run mode, actions will NOT be applied\z/,
20
+ :warn
21
+ )
22
+ worker.process []
23
+ end
24
+ end
13
25
  end
14
26
 
15
27
  describe '#process_task' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: producer-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan