Skip to content

Commit

Permalink
Fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
rymai committed Jul 3, 2013
1 parent 3ff7e06 commit ede9f91
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 33 deletions.
2 changes: 1 addition & 1 deletion lib/guard/dsl.rb
Expand Up @@ -331,7 +331,7 @@ def logger(options)
end
end

::Guard::UI.options = ::Guard::UI.options.merge options
::Guard::UI.options = ::Guard::UI.options.marshal_dump.merge options
end

# Sets the default scope on startup
Expand Down
6 changes: 1 addition & 5 deletions lib/guard/options.rb
Expand Up @@ -6,18 +6,14 @@ module Guard
#
class Options < OpenStruct

attr_accessor :options

# Initializes an Guard::Options object. `default_opts` is merged into
# `opts`.
#
# @param [Hash] opts the options
# @param [Hash] default_opts the default options
#
def initialize(opts = {}, default_opts = {})
opts = default_opts.dup.merge(opts.dup)

super(opts)
super(default_opts.dup.merge(opts.dup))
end

end
Expand Down
22 changes: 11 additions & 11 deletions lib/guard/ui.rb
Expand Up @@ -20,8 +20,8 @@ class << self
#
def logger
@logger ||= begin
options = self.options.dup
Lumberjack::Logger.new(options.delete(:device) || $stderr, options)
opts = options.marshal_dump
Lumberjack::Logger.new(opts.delete(:device) { $stderr }, opts)
end
end

Expand All @@ -30,7 +30,7 @@ def logger
# @return [Hash] the logger options
#
def options
@options ||= { :level => :info, :template => ':time - :severity - :message', :time_format => '%H:%M:%S' }
@options ||= ::Guard::Options.new(level: :info, template: ':time - :severity - :message', time_format: '%H:%M:%S')
end

# Set the logger options
Expand All @@ -41,7 +41,7 @@ def options
# @option options [String] time_format the time format
#
def options=(options)
@options = options
@options = ::Guard::Options.new(options)
end

# Show an info message.
Expand All @@ -53,7 +53,7 @@ def options=(options)
def info(message, options = {})
filter(options[:plugin]) do |plugin|
reset_line if options[:reset]
self.logger.info(message, plugin)
logger.info(message, plugin)
end
end

Expand All @@ -66,7 +66,7 @@ def info(message, options = {})
def warning(message, options = {})
filter(options[:plugin]) do |plugin|
reset_line if options[:reset]
self.logger.warn(color(message, :yellow), plugin)
logger.warn(color(message, :yellow), plugin)
end
end

Expand All @@ -79,7 +79,7 @@ def warning(message, options = {})
def error(message, options = {})
filter(options[:plugin]) do |plugin|
reset_line if options[:reset]
self.logger.error(color(message, :red), plugin)
logger.error(color(message, :red), plugin)
end
end

Expand All @@ -95,7 +95,7 @@ def deprecation(message, options = {})

filter(options[:plugin]) do |plugin|
reset_line if options[:reset]
self.logger.warn(color(message, :yellow), plugin)
logger.warn(color(message, :yellow), plugin)
end
end

Expand All @@ -108,7 +108,7 @@ def deprecation(message, options = {})
def debug(message, options = {})
filter(options[:plugin]) do |plugin|
reset_line if options[:reset]
self.logger.debug(color(message, :yellow), plugin)
logger.debug(color(message, :yellow), plugin)
end
end

Expand Down Expand Up @@ -164,8 +164,8 @@ def action_with_scopes(action, scopes)
# @yieldparam [String] param the calling plugin name
#
def filter(plugin)
only = self.options[:only]
except = self.options[:except]
only = options.only
except = options.except
plugin = plugin || calling_plugin_name

if (!only && !except) || (only && only.match(plugin)) || (except && !except.match(plugin))
Expand Down
28 changes: 14 additions & 14 deletions spec/guard/dsl_spec.rb
Expand Up @@ -232,57 +232,57 @@ def self.call(plugin, event, args)
end

describe '#logger' do
after { Guard::UI.options = { :level => :info, :template => ':time - :severity - :message', :time_format => '%H:%M:%S' } }
after { Guard::UI.options = { level: :info, template: ':time - :severity - :message', time_format: '%H:%M:%S' } }

context 'with valid options' do
it 'sets the logger log level' do
described_class.evaluate_guardfile(:guardfile_contents => 'logger :level => :error')
Guard::UI.options[:level].should eq :error
Guard::UI.options.level.should eq :error
end

it 'sets the logger log level and convert to a symbol' do
described_class.evaluate_guardfile(:guardfile_contents => 'logger :level => \'error\'')
Guard::UI.options[:level].should eq :error
Guard::UI.options.level.should eq :error
end

it 'sets the logger template' do
described_class.evaluate_guardfile(:guardfile_contents => 'logger :template => \':message - :severity\'')
Guard::UI.options[:template].should eq ':message - :severity'
Guard::UI.options.template.should eq ':message - :severity'
end

it 'sets the logger time format' do
described_class.evaluate_guardfile(:guardfile_contents => 'logger :time_format => \'%Y\'')
Guard::UI.options[:time_format].should eq '%Y'
Guard::UI.options.time_format.should eq '%Y'
end

it 'sets the logger only filter from a symbol' do
described_class.evaluate_guardfile(:guardfile_contents => 'logger :only => :cucumber')
Guard::UI.options[:only].should eq(/cucumber/i)
Guard::UI.options.only.should eq(/cucumber/i)
end

it 'sets the logger only filter from a string' do
described_class.evaluate_guardfile(:guardfile_contents => 'logger :only => \'jasmine\'')
Guard::UI.options[:only].should eq(/jasmine/i)
Guard::UI.options.only.should eq(/jasmine/i)
end

it 'sets the logger only filter from an array of symbols and string' do
described_class.evaluate_guardfile(:guardfile_contents => 'logger :only => [:rspec, \'cucumber\']')
Guard::UI.options[:only].should eq(/rspec|cucumber/i)
Guard::UI.options.only.should eq(/rspec|cucumber/i)
end

it 'sets the logger except filter from a symbol' do
described_class.evaluate_guardfile(:guardfile_contents => 'logger :except => :jasmine')
Guard::UI.options[:except].should eq(/jasmine/i)
Guard::UI.options.except.should eq(/jasmine/i)
end

it 'sets the logger except filter from a string' do
described_class.evaluate_guardfile(:guardfile_contents => 'logger :except => \'jasmine\'')
Guard::UI.options[:except].should eq(/jasmine/i)
Guard::UI.options.except.should eq(/jasmine/i)
end

it 'sets the logger except filter from an array of symbols and string' do
described_class.evaluate_guardfile(:guardfile_contents => 'logger :except => [:rspec, \'cucumber\', :jasmine]')
Guard::UI.options[:except].should eq(/rspec|cucumber|jasmine/i)
Guard::UI.options.except.should eq(/rspec|cucumber|jasmine/i)
end
end

Expand All @@ -295,7 +295,7 @@ def self.call(plugin, event, args)

it 'does not set the invalid value' do
described_class.evaluate_guardfile(:guardfile_contents => 'logger :level => :baz')
Guard::UI.options[:level].should eq :info
Guard::UI.options.level.should eq :info
end
end

Expand All @@ -307,8 +307,8 @@ def self.call(plugin, event, args)

it 'removes the options' do
described_class.evaluate_guardfile(:guardfile_contents => 'logger :only => :jasmine, :except => :rspec')
Guard::UI.options[:only].should be_nil
Guard::UI.options[:except].should be_nil
Guard::UI.options.only.should be_nil
Guard::UI.options.except.should be_nil
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/guard/ui_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Guard::UI do
after { Guard::UI.options = ::Guard::Options.new(level: :info, device: $stderr, template: ':time - :severity - :message', time_format: '%H:%M:%S') }
after { Guard::UI.options = { level: :info, device: $stderr, template: ':time - :severity - :message', time_format: '%H:%M:%S' } }

before do
# The spec helper stubs all UI classes, so other specs doesn't have
Expand Down Expand Up @@ -40,7 +40,7 @@

describe '.options=' do
it 'sets the logger options' do
Guard::UI.options = ::Guard::Options.new(hi: :ho)
Guard::UI.options = { hi: :ho }
Guard::UI.options.hi.should eq :ho
end
end
Expand Down

0 comments on commit ede9f91

Please sign in to comment.