Permalink
Browse files

+ simplified test logging, + guard in picky-client

  • Loading branch information...
1 parent 3b31d0e commit c2485e06e4b43d555d7de4d416947aae91014ced Florian René Hanke committed Oct 22, 2012
@@ -2,8 +2,10 @@ class Object # :nodoc:all
# Puts a text that informs the user of a missing gem.
#
- def warn_gem_missing gem_name, message
- warn "#{gem_name} gem missing!\nTo use #{message}, you need to:\n 1. Add the following line to Gemfile:\n gem '#{gem_name}'\n 2. Then, run:\n bundle update\n"
+ unless instance_methods.include? :warn_gem_missing
+ def warn_gem_missing gem_name, message
+ warn "#{gem_name} gem missing!\nTo use #{message}, you need to:\n 1. Add the following line to Gemfile:\n gem '#{gem_name}'\n 2. Then, run:\n bundle update\n"
+ end
end
end
View
@@ -71,7 +71,7 @@ class << self
# * Loggers::Silent
# * Loggers::Concise (default)
# * Loggers::Verbose
- #
+ #
self.logger = Loggers::Default
end
@@ -19,7 +19,17 @@ def exclaim text
# Puts a text that informs the user of a missing gem.
#
def warn_gem_missing gem_name, message
- Picky.logger.warn "#{gem_name} gem missing!\nTo use #{message}, you need to:\n 1. Add the following line to Gemfile:\n gem '#{gem_name}'\n or\n require '#{gem_name}'\n for example at the top of your app.rb file.\n 2. Then, run:\n bundle update\n"
+ Picky.logger.warn <<-WARNING
+Warning: #{gem_name} gem missing!
+To use #{message}, you need to:
+ 1. Add the following line to Gemfile:
+ gem '#{gem_name}'
+ or
+ require '#{gem_name}'
+ for example at the top of your app.rb file.
+ 2. Then, run:
+ bundle update
+WARNING
end
# Indents each line by <tt>amount=2</tt> spaces.
@@ -20,8 +20,6 @@ class Phonetic < Strategy
#
def initialize amount = 3
check_gem
-
- raise "In Picky 2.0+, the Similarity::Phonetic has been renamed to Similarity::DoubleMetaphone. Please use that one. Thanks!" if self.class == Phonetic
@amount = amount
end
@@ -1,19 +1,12 @@
require 'spec_helper'
+require 'time'
+
describe Object do
context 'basic object' do
let(:object) { described_class.new }
- # describe "exclaim" do
- # it "delegates to puts" do
- # STDOUT.should_receive(:puts).once.with :bla
- # STDOUT.should_receive(:flush).once.with
- #
- # object.exclaim :bla
- # end
- # end
-
describe "timed_exclaim" do
it "should exclaim right" do
Time.stub! :now => Time.parse('07-03-1977 12:34:56')
@@ -25,8 +18,18 @@
describe 'warn_gem_missing' do
it 'should warn right' do
- object.should_receive(:warn).once.with "gnorf gem missing!\nTo use gnarble gnarf, you need to:\n 1. Add the following line to Gemfile:\n gem 'gnorf'\n 2. Then, run:\n bundle update\n"
-
+ Picky.logger.should_receive(:warn).once.with <<-EXPECTED
+Warning: gnorf gem missing!
+To use gnarble gnarf, you need to:
+ 1. Add the following line to Gemfile:
+ gem 'gnorf'
+ or
+ require 'gnorf'
+ for example at the top of your app.rb file.
+ 2. Then, run:
+ bundle update
+EXPECTED
+
object.warn_gem_missing 'gnorf', 'gnarble gnarf'
end
end
@@ -2,20 +2,27 @@
#
require 'spec_helper'
-describe Picky::Generators::Similarity::Phonetic do
+require 'text'
- it 'raises if you try to use Phonetic directly' do
- expect {
- described_class.new
- }.to raise_error("In Picky 2.0+, the Similarity::Phonetic has been renamed to Similarity::DoubleMetaphone. Please use that one. Thanks!")
- end
+describe Picky::Generators::Similarity::Phonetic do
it "raises when you don't have the text gem" do
instance = Class.new(described_class).allocate
instance.should_receive(:require).any_number_of_times.and_raise LoadError
+
+ Picky.logger.should_receive(:warn).once.with <<-EXPECTED
+Warning: text gem missing!
+To use a phonetic Similarity, you need to:
+ 1. Add the following line to Gemfile:
+ gem 'text'
+ or
+ require 'text'
+ for example at the top of your app.rb file.
+ 2. Then, run:
+ bundle update
+EXPECTED
- instance.should_receive(:warn).once.with "text gem missing!\nTo use a phonetic Similarity, you need to:\n 1. Add the following line to Gemfile:\n gem 'text'\n 2. Then, run:\n bundle update\n"
instance.should_receive(:exit).once.with 1
instance.send :initialize
View
@@ -14,19 +14,12 @@
# Set some spec preconditions.
#
-Picky.root = 'spec/test_directory'
-# puts "Redefined Picky.root to '#{Picky.root}' for the tests."
-
-Picky.logger = Picky::Loggers::Silent.new STDOUT
-# puts "Using Picky::Loggers::Silent.new(STDOUT) as test logger."
-
-class Object
- def exclaim(*)
- # The sound of silence.
- end
-end
+Picky.root = 'spec/test_directory'
+Picky.logger = Picky::Loggers::Silent.new
begin
+ # Remove this file for the default.
+ #
require File.expand_path '../performance_ratio', __FILE__
rescue LoadError => e
# Default is for slower computers and

0 comments on commit c2485e0

Please sign in to comment.