Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • guard-org/guard
1 result
Show changes
Commits on Source (5)
Feature: setting logger options
In order to customize logging output
As a user
I want to specify the logger options
Background: Guard is installed through bundler
Given Guard is bundled using source
@spawn
Scenario: Customize logger template
Given my Guardfile contains:
"""
require 'guard/plugin'
logger(template: '[Custom - :severity - :time - :progname] :message')
module ::Guard
class Myplugin < Plugin
def run_on_additions(files)
$stdout.puts "Files added: #{files.inspect}"
$stdout.flush
end
end
end
guard :myplugin do
watch('foo')
end
"""
Given I start `bundle exec guard -n f`
And I create a file "foo"
And I wait for Guard to become idle
And I stop guard
Then the output should match /\[Custom - INFO - \d\d:\d\d:\d\d - Guard]/
@spawn
Scenario: Customize logger level
Given my Guardfile contains:
"""
require 'guard/plugin'
logger(level: :warn)
module ::Guard
class Myplugin < Plugin
def run_on_additions(files)
$stdout.puts "Files added: #{files.inspect}"
$stdout.flush
end
end
end
guard :myplugin do
watch('foo')
end
"""
Given I start `bundle exec guard -n f`
And I create a file "foo"
And I wait for Guard to become idle
And I stop guard
Then the output should not contain "INFO"
Loading
Loading
@@ -349,7 +349,7 @@ module Guard
options[name] = Regexp.new(list.join("|"), Regexp::IGNORECASE)
end
 
UI.options.merge!(options)
UI.options = UI.options.merge(options)
end
 
# Sets the default scope on startup
Loading
Loading
module Guard
VERSION = "2.14.1"
VERSION = "2.14.2"
end
Loading
Loading
@@ -464,13 +464,8 @@ RSpec.describe Guard::Dsl do
 
describe "#logger" do
before do
Guard::UI.options = nil
allow(ui_config).to receive(:merge!)
end
after do
Guard::UI.reset_logger
Guard::UI.options = nil
allow(Guard::UI).to receive(:options).and_return({})
allow(Guard::UI).to receive(:options=)
end
 
describe "options" do
Loading
Loading
@@ -480,63 +475,64 @@ RSpec.describe Guard::Dsl do
evaluator.call(contents)
end
 
subject { ui_config }
subject { Guard::UI }
 
context "with logger level :errror" do
context "with logger level :error" do
let(:contents) { "logger level: :error" }
it { is_expected.to have_received(:merge!).with(level: :error) }
it { is_expected.to have_received(:options=).with(level: :error) }
end
 
context "with logger level 'errror'" do
context "with logger level 'error'" do
let(:contents) { 'logger level: \'error\'' }
it { is_expected.to have_received(:merge!).with(level: :error) }
it { is_expected.to have_received(:options=).with(level: :error) }
end
 
context "with logger template" do
let(:contents) { 'logger template: \':message - :severity\'' }
it do
is_expected.to have_received(:merge!).
is_expected.to have_received(:options=).
with(template: ":message - :severity")
end
end
 
context "with a logger time format" do
let(:contents) { 'logger time_format: \'%Y\'' }
it { is_expected.to have_received(:merge!).with(time_format: "%Y") }
it do
is_expected.to have_received(:options=).with(time_format: "%Y")
end
end
 
context "with a logger only filter from a symbol" do
let(:contents) { "logger only: :cucumber" }
it { is_expected.to have_received(:merge!).with(only: /cucumber/i) }
it { is_expected.to have_received(:options=).with(only: /cucumber/i) }
end
 
context "with logger only filter from a string" do
let(:contents) { 'logger only: \'jasmine\'' }
it { is_expected.to have_received(:merge!).with(only: /jasmine/i) }
it { is_expected.to have_received(:options=).with(only: /jasmine/i) }
end
 
context "with logger only filter from an array of symbols and string" do
let(:contents) { 'logger only: [:rspec, \'cucumber\']' }
it do
is_expected.to have_received(:merge!).
with(only: /rspec|cucumber/i)
is_expected.to have_received(:options=).with(only: /rspec|cucumber/i)
end
end
 
context "with logger except filter from a symbol" do
let(:contents) { "logger except: :jasmine" }
it { is_expected.to have_received(:merge!).with(except: /jasmine/i) }
it { is_expected.to have_received(:options=).with(except: /jasmine/i) }
end
 
context "with logger except filter from a string" do
let(:contents) { 'logger except: \'jasmine\'' }
it { is_expected.to have_received(:merge!).with(except: /jasmine/i) }
it { is_expected.to have_received(:options=).with(except: /jasmine/i) }
end
 
context "with logger except filter from array of symbols and string" do
let(:contents) { 'logger except: [:rspec, \'cucumber\', :jasmine]' }
it do
is_expected.to have_received(:merge!).
is_expected.to have_received(:options=).
with(except: /rspec|cucumber|jasmine/i)
end
end
Loading
Loading
@@ -555,7 +551,7 @@ RSpec.describe Guard::Dsl do
end
 
it "does not set the invalid value" do
expect(ui_config).to receive(:merge!).with({})
expect(Guard::UI).to receive(:options=).with({})
evaluator.call(contents)
end
end
Loading
Loading
@@ -571,7 +567,7 @@ RSpec.describe Guard::Dsl do
end
 
it "removes the options" do
expect(ui_config).to receive(:merge!).with({})
expect(Guard::UI).to receive(:options=).with({})
evaluator.call(contents)
end
end
Loading
Loading