Skip to content

Commit

Permalink
+ simplified test logging, + guard in picky-client
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian René Hanke committed Oct 22, 2012
1 parent 3b31d0e commit c2485e0
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 35 deletions.
6 changes: 4 additions & 2 deletions client/lib/picky-client/extensions/object.rb
Expand Up @@ -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
2 changes: 1 addition & 1 deletion server/lib/picky.rb
Expand Up @@ -71,7 +71,7 @@ class << self
# * Loggers::Silent
# * Loggers::Concise (default)
# * Loggers::Verbose
#
#
self.logger = Loggers::Default

end
12 changes: 11 additions & 1 deletion server/lib/picky/extensions/object.rb
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions server/lib/picky/generators/similarity/phonetic.rb
Expand Up @@ -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

Expand Down
25 changes: 14 additions & 11 deletions server/spec/lib/extensions/object_spec.rb
@@ -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')
Expand All @@ -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
Expand Down
21 changes: 14 additions & 7 deletions server/spec/lib/generators/similarity/phonetic_spec.rb
Expand Up @@ -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
Expand Down
15 changes: 4 additions & 11 deletions server/spec/spec_helper.rb
Expand Up @@ -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
Expand Down

0 comments on commit c2485e0

Please sign in to comment.