Commit 4e3bbb54 authored by Balasankar C's avatar Balasankar C

Imported Upstream version 0.1.3

parents
Gemfile.lock
log
*.gem
--color
--format documentation
--order random
--warnings
--require spec_helper
script: rake ci
language: ruby
rvm:
- 2.2.0
- jruby
- ruby-head
- jruby-head
- rbx-2
matrix:
allow_failures:
- rvm: rbx-2
- rvm: ruby-head
- rvm: jruby-head
notifications:
irc: "irc.freenode.org#abstractive"
sudo: false
0.1.1 (2015-04-04)
-----
* Updated to new RSpec syntax.
* Separated classes out into own files.
* Added timestamp to default logging path.
0.0.3
-----
* Initial Release
\ No newline at end of file
source "https://rubygems.org"
gem 'bundler'
gem 'rake'
gem 'rspec', '~> 3.2'
gemspec
group :development do
gem 'pry'
end
\ No newline at end of file
Copyright (c) 2012 Tim Carey-Smith, digitalextremist //
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
# Log Splitter for RSpec
This `RSpec` plugin allows you to change the logger for your library for each
separate example. This gives the ability to see the log output for each
specific test.
## Usage
Currently you must have a `class` or `module` which responds to two methods.
For example, `Rails` responds correctly:
* `Rails.logger`
* `Rails.logger=`
In your `Gemfile`:
``` ruby
gem "rspec-log_split"
```
In your `spec/spec_helper.rb`:
``` ruby
require "rspec/log_split"
RSpec.configure do |config|
config.log_split_dir = File.expand_path("../../log/#{Time.now.iso8601}", __FILE__)
config.log_split_module = Rails
end
```
You will get a log file for each example as follows:
```
log/2013-10-05T00:47:14+13:00/main
log/2013-10-05T00:47:14+13:00/spec/demo_spec.rb:5
log/2013-10-05T00:47:14+13:00/spec/demo_spec.rb:9
log/2013-10-05T00:47:14+13:00/spec/support/shared_examples/win.rb:2
log/2013-10-05T00:47:14+13:00/spec/support/shared_examples/win.rb:7
```
require 'bundler/gem_tasks'
Dir['tasks/**/*.rake'].each { |task| load task }
default_tasks = ['spec']
# default_tasks << 'rubocop' unless ENV['CI']
task default: default_tasks
task ci: %w(spec)
require 'date'
require 'logger'
require 'pathname'
require 'rspec/log_split/handler'
require 'rspec/log_split/config'
module RSpec
module LogSplit
class << self
def apply
RSpec.configure do |config|
config.add_setting :log_split_module
config.add_setting :log_split_dir
config.add_setting :log_split
config.before(:suite) do
RSpec.configuration.log_split= Config.new(
RSpec.configuration.log_split_module,
RSpec.configuration.log_split_dir,
)
end
config.around(:each) do |example|
RSpec.configuration.log_split.run(example)
end
config.after(:suite) do
Handler.list_logs if $DEBUG
end
end
end
end
end
end
RSpec::LogSplit.apply
module RSpec
module LogSplit
class Config
def initialize(mod, dir)
@mod = mod
@path = Pathname.new(dir)
@path.mkpath
@logger = logger(@path.join("main"))
end
def run(example)
example_path = @path.join(example.location)
example_path.parent.mkpath
example_logger = logger(example_path.to_path)
Handler.new(@logger, @mod, example, example_logger).run
end
def logger(path)
file = File.open(path, "a")
file.sync = true
Logger.new(file)
end
end
end
end
module RSpec
module LogSplit
class Handler
def initialize(logger, mod, example, example_logger)
@logger = logger
@mod = mod
@example = example
@example_logger = example_logger
end
def run
@mod.logger = @example_logger
begin
error "starting #{description}"
@example.run
rescue Exception => e
error "error with #{description}: #{e.inspect}"
raise e
ensure
error "finishing #{description}"
@mod.logger = nil
end
end
def description
@example.full_description
end
def error(message)
@logger.error message
@mod.logger.error message
end
end
end
end
module RSpec
module LogSplit
VERSION = "0.1.3"
end
end
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/rspec/log_split/version', __FILE__)
Gem::Specification.new do |gem|
gem.name = "rspec-logsplit"
gem.version = RSpec::LogSplit::VERSION
gem.authors = ["digitalextremist //","Tim Carey-Smith",]
gem.email = ["code@extremist.digital","tim@spork.in"]
gem.description = %q{A new logger for each example}
gem.summary = %q{Separate the logs between examples to allow for easier understanding}
gem.homepage = "https://github.com/abstractive/rspec-logsplit"
gem.license = "MIT"
gem.required_ruby_version = '>= 1.9.2'
gem.required_rubygems_version = '>= 1.3.6'
gem.files = `git ls-files`.split($/)
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
gem.add_development_dependency 'rake'
gem.add_development_dependency 'bundler'
end
require 'spec_helper'
describe "foo" do
context "bar" do
it "baz" do
Demo.logger.info "bar"
end
it "qux" do
Demo.logger.info "qux"
end
end
end
require 'rspec/log_split'
Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
RSpec.configure do |config|
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
config.log_split_module = Demo
config.log_split_dir = File.expand_path("../../log/#{DateTime.now.iso8601}", __FILE__)
end
class Demo
class << self
attr_accessor :logger
end
end
shared_examples "win" do
it "works" do
Demo.logger.info "works"
end
context "mainframe" do
it "hacks" do
Demo.logger.info "hacks"
end
end
end
require 'spec_helper'
describe "things" do
include_examples "win"
end
require 'spec_helper'
describe "zebra" do
include_examples "win"
end
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new
RSpec::Core::RakeTask.new(:rcov) do |task|
task.rcov = true
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment