Skip to content

Commit

Permalink
ST: Refactoring and added specs
Browse files Browse the repository at this point in the history
  • Loading branch information
rudionrails committed Sep 13, 2012
1 parent 31b7001 commit 5d4041e
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 70 deletions.
2 changes: 1 addition & 1 deletion lib/generators/yell/install/templates/config/yell.yml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ production:
# :level: 'gte.info lte.fatal' # :level: 'gte.info lte.fatal'
:level: 'gte.info' :level: 'gte.info'


# Keep a max of 7 files for every adapter per default. You can leave this option # Keep a max of 7 files for every adapter per default. You can remove this option
# if you wish to keep all files, otherwise, Yell will cleanup any :datefile # if you wish to keep all files, otherwise, Yell will cleanup any :datefile
# after a rollover of 7 times. # after a rollover of 7 times.
:keep: 7 :keep: 7
Expand Down
5 changes: 5 additions & 0 deletions lib/yell-rails.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
# encoding: utf-8

require 'yell'

require File.dirname(__FILE__) + '/yell/railtie' if defined?(Rails)
3 changes: 0 additions & 3 deletions lib/yell/rails.rb → lib/yell/railtie.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,5 @@
# encoding: utf-8 # encoding: utf-8


require 'rails'
require 'yell'

module Yell #:nodoc: module Yell #:nodoc:
class Railtie < ::Rails::Railtie class Railtie < ::Rails::Railtie
railtie_name 'yell-rails' railtie_name 'yell-rails'
Expand Down
42 changes: 2 additions & 40 deletions spec/fixtures/yell.yml
Original file line number Original file line Diff line number Diff line change
@@ -1,42 +1,4 @@
# The following is an example config file for yell with all possible options available. test:
#
# To learn about the possible configuration options via a YAML file, read the wiki
# on github: https://github.com/rudionrails/yell/wiki/101-configuration-with-yaml

development: &development
# Enable colorized log output with the following. It is handy for development
# or testing, but should not be turned on for staging or production. Otherwise
# you will see those annoying ANSI color codes when on the remote production
# machine.
:colors: true

# we use the same settings for test that we defined for development
test: *development

# In production, you should configure yell somewhat more specific. The following
# is an example config - change it at your own will.
production:
# Set the minimum (global) log level for Yell. If you prefer a different setup
# you may comine various log levels, like:
# # this will only log between :info and :fatal level
# :level: 'gte.info lte.fatal'
:level: 'gte.info'

# Keep a max of 7 files for every adapter per default. You can leave this option
# if you wish to keep all files, otherwise, Yell will cleanup any :datefile
# after a rollover of 7 times.
:keep: 7

# define multiple adapters: one for notice and one for error messages
:adapters: :adapters:
# this adapter writes all messages with a log level of warn or lower - :stdout:
# and writes to production.log (because this is your Rails.env)
- :datefile:
:level: 'lte.warn'

# this adapter writes all messages with a log level of error or higher
# and writes to error.log
- :datefile:
:level: 'gte.error'
:filename: 'log/error.log'


12 changes: 9 additions & 3 deletions spec/spec_helper.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,19 +1,25 @@
$:.unshift File.expand_path('..', __FILE__) $:.unshift File.expand_path('..', __FILE__)
$:.unshift File.expand_path('../../lib', __FILE__) $:.unshift File.expand_path('../../lib', __FILE__)


require 'yell/rails' require 'rails'
require 'rails/all' require 'yell-rails'


require 'rspec' require 'rspec'
require 'rr' require 'rr'


require 'ostruct'

RSpec.configure do |config| RSpec.configure do |config|
config.mock_framework = :rr config.mock_framework = :rr


config.after do
Dir[ fixture_path + "/*.log" ].each { |f| File.delete f }
end

private private


def fixture_path def fixture_path
File.dirname(__FILE__) + '/fixtures' File.expand_path( "fixtures", File.dirname(__FILE__) )
end end


end end
Expand Down
41 changes: 25 additions & 16 deletions spec/yell/railtie_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,27 +1,36 @@
require 'spec_helper' require 'spec_helper'


# Yell Rails applicatio class
module Yell
class Application < Rails::Application
end
end

describe Yell::Railtie do describe Yell::Railtie do
let( :file ) { File.join(fixture_path, 'yell.yml') } let( :app ) { FakeApp.new }

let( :railtie ) { Yell::Railtie.send :new }
before do
mock( Rails.root ).join('config', 'yell.yml') { config_file }

Yell::Application.initialize!
end


it "should have the right railtie name" do it "should have the right railtie name" do
Yell::Railtie.railtie_name.should == 'yell-rails' Yell::Railtie.railtie_name.should == 'yell-rails'
end end


# it "should set the rails logger for the Yell::Repository" do context :initialized do
# Rails.logger.should == Yell['rails'] let( :app ) do
# end OpenStruct.new(
:config => OpenStruct.new( :paths => {'log' => [path]} )
)
end

let( :path ) { 'path/to/config' }
let( :file ) { mock }

before do
mock( ::File ).exist?( File.dirname(path) ) { true } # do not create log directory

mock( Rails.root ).join('config', 'yell.yml') { file } # mock config file
mock( file ).file? { false } # do not load the config file

railtie.run_initializers(:all, app )
end

it "should add :rails to the Yell::Repository" do
Yell['rails'].should be_kind_of Yell::Logger
end
end


end end


14 changes: 7 additions & 7 deletions yell-rails.gemspec
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ Gem::Specification.new do |s|
s.authors = ["Rudolf Schmidt"] s.authors = ["Rudolf Schmidt"]


s.homepage = "http://rudionrails.github.com/yell" s.homepage = "http://rudionrails.github.com/yell"
s.summary = %q{yell-rails} s.summary = %q{Yell - Your Extensible Logging Library for Rails}
s.description = %q{Yell for Rails} s.description = %q{Yell - Your Extensible Logging Library. Define multiple adapters, various log level combinations or message formatting options like you've never done before}


s.rubyforge_project = "yell" s.rubyforge_project = "yell"


s.files = `git ls-files`.split("\n") s.files = `git ls-files`.split($\)
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.test_files = s.files.grep(%r{^(test|spec|features)/})

s.require_paths = ["lib"] s.require_paths = ["lib"]


s.add_runtime_dependency "yell", ">= 0.13.2" s.add_runtime_dependency "yell", ">= 0.13.2"

s.add_runtime_dependency "rails", ">= 3.0.0"
s.add_development_dependency "rails", ">= 3.0.0"
end end


0 comments on commit 5d4041e

Please sign in to comment.