rspec-logsplit 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9f1eb473d08eea42d3a20ad731973c8833fb9865
4
+ data.tar.gz: 2ea49c5e889b82d6ba08a61b5f8610a9b9518d1d
5
+ SHA512:
6
+ metadata.gz: 74c9d8eedb3247104a976f61314b426f240afa361814cd73f29236dcd0d2a6aeacf1fdb238941383510923fc891caa8afbe7432f691ba7372a1a605a1faa0096
7
+ data.tar.gz: 1791156c70537faef69c003c2cdb43352b091657d7b1599b938d54cb1ed24b5cfed245c0cfe62464e335820680cfb14bcfcee64415c6d2921675e4cb8b5ba460
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ log
3
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ --format documentation
3
+ --order random
4
+ --warnings
5
+ --require spec_helper
@@ -0,0 +1,19 @@
1
+ script: rake ci
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.0
5
+ - jruby
6
+ - ruby-head
7
+ - jruby-head
8
+ - rbx-2
9
+
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: rbx-2
13
+ - rvm: ruby-head
14
+ - rvm: jruby-head
15
+
16
+ notifications:
17
+ irc: "irc.freenode.org#abstractive"
18
+
19
+ sudo: false
@@ -0,0 +1,10 @@
1
+ 0.1.1 (2015-04-04)
2
+ -----
3
+
4
+ * Updated to new RSpec syntax.
5
+ * Separated classes out into own files.
6
+ * Added timestamp to default logging path.
7
+
8
+ 0.0.3
9
+ -----
10
+ * Initial Release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'bundler'
4
+ gem 'rake'
5
+
6
+ gem 'rspec', '~> 3.2'
7
+
8
+ gemspec
9
+
10
+ group :development do
11
+ gem 'pry'
12
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Tim Carey-Smith, digitalextremist //
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # Log Splitter for RSpec
2
+
3
+ This `RSpec` plugin allows you to change the logger for your library for each
4
+ separate example. This gives the ability to see the log output for each
5
+ specific test.
6
+
7
+ ## Usage
8
+
9
+ Currently you must have a `class` or `module` which responds to two methods.
10
+ For example, `Rails` responds correctly:
11
+ * `Rails.logger`
12
+ * `Rails.logger=`
13
+
14
+ In your `Gemfile`:
15
+
16
+ ``` ruby
17
+ gem "rspec-log_split"
18
+ ```
19
+
20
+ In your `spec/spec_helper.rb`:
21
+
22
+ ``` ruby
23
+ require "rspec/log_split"
24
+
25
+ RSpec.configure do |config|
26
+ config.log_split_dir = File.expand_path("../../log/#{Time.now.iso8601}", __FILE__)
27
+ config.log_split_module = Rails
28
+ end
29
+ ```
30
+
31
+ You will get a log file for each example as follows:
32
+ ```
33
+ log/2013-10-05T00:47:14+13:00/main
34
+ log/2013-10-05T00:47:14+13:00/spec/demo_spec.rb:5
35
+ log/2013-10-05T00:47:14+13:00/spec/demo_spec.rb:9
36
+ log/2013-10-05T00:47:14+13:00/spec/support/shared_examples/win.rb:2
37
+ log/2013-10-05T00:47:14+13:00/spec/support/shared_examples/win.rb:7
38
+ ```
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ Dir['tasks/**/*.rake'].each { |task| load task }
4
+
5
+ default_tasks = ['spec']
6
+ # default_tasks << 'rubocop' unless ENV['CI']
7
+ task default: default_tasks
8
+
9
+ task ci: %w(spec)
@@ -0,0 +1,38 @@
1
+ require 'date'
2
+ require 'logger'
3
+ require 'pathname'
4
+
5
+ require 'rspec/log_split/handler'
6
+ require 'rspec/log_split/config'
7
+
8
+ module RSpec
9
+ module LogSplit
10
+ class << self
11
+
12
+ def apply
13
+ RSpec.configure do |config|
14
+ config.add_setting :log_split_module
15
+ config.add_setting :log_split_dir
16
+ config.add_setting :log_split
17
+
18
+ config.before(:suite) do
19
+ RSpec.configuration.log_split= Config.new(
20
+ RSpec.configuration.log_split_module,
21
+ RSpec.configuration.log_split_dir,
22
+ )
23
+ end
24
+
25
+ config.around(:each) do |example|
26
+ RSpec.configuration.log_split.run(example)
27
+ end
28
+
29
+ config.after(:suite) do
30
+ Handler.list_logs if $DEBUG
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ RSpec::LogSplit.apply
@@ -0,0 +1,25 @@
1
+ module RSpec
2
+ module LogSplit
3
+ class Config
4
+ def initialize(mod, dir)
5
+ @mod = mod
6
+ @path = Pathname.new(dir)
7
+ @path.mkpath
8
+ @logger = logger(@path.join("main"))
9
+ end
10
+
11
+ def run(example)
12
+ example_path = @path.join(example.location)
13
+ example_path.parent.mkpath
14
+ example_logger = logger(example_path.to_path)
15
+ Handler.new(@logger, @mod, example, example_logger).run
16
+ end
17
+
18
+ def logger(path)
19
+ file = File.open(path, "a")
20
+ file.sync = true
21
+ Logger.new(file)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ module RSpec
2
+ module LogSplit
3
+ class Handler
4
+ def initialize(logger, mod, example, example_logger)
5
+ @logger = logger
6
+ @mod = mod
7
+ @example = example
8
+ @example_logger = example_logger
9
+ end
10
+
11
+ def run
12
+ @mod.logger = @example_logger
13
+ begin
14
+ error "starting #{description}"
15
+ @example.run
16
+ rescue Exception => e
17
+ error "error with #{description}: #{e.inspect}"
18
+ raise e
19
+ ensure
20
+ error "finishing #{description}"
21
+ @mod.logger = nil
22
+ end
23
+ end
24
+
25
+ def description
26
+ @example.full_description
27
+ end
28
+
29
+ def error(message)
30
+ @logger.error message
31
+ @mod.logger.error message
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module RSpec
2
+ module LogSplit
3
+ VERSION = "0.1.3"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rspec/log_split/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "rspec-logsplit"
6
+ gem.version = RSpec::LogSplit::VERSION
7
+ gem.authors = ["digitalextremist //","Tim Carey-Smith",]
8
+ gem.email = ["code@extremist.digital","tim@spork.in"]
9
+ gem.description = %q{A new logger for each example}
10
+ gem.summary = %q{Separate the logs between examples to allow for easier understanding}
11
+ gem.homepage = "https://github.com/abstractive/rspec-logsplit"
12
+ gem.license = "MIT"
13
+
14
+ gem.required_ruby_version = '>= 1.9.2'
15
+ gem.required_rubygems_version = '>= 1.3.6'
16
+
17
+ gem.files = `git ls-files`.split($/)
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'bundler'
23
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe "foo" do
4
+ context "bar" do
5
+ it "baz" do
6
+ Demo.logger.info "bar"
7
+ end
8
+
9
+ it "qux" do
10
+ Demo.logger.info "qux"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ require 'rspec/log_split'
2
+
3
+ Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
4
+
5
+ RSpec.configure do |config|
6
+ config.filter_run :focus => true
7
+ config.run_all_when_everything_filtered = true
8
+
9
+ config.log_split_module = Demo
10
+ config.log_split_dir = File.expand_path("../../log/#{DateTime.now.iso8601}", __FILE__)
11
+ end
@@ -0,0 +1,5 @@
1
+ class Demo
2
+ class << self
3
+ attr_accessor :logger
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ shared_examples "win" do
2
+ it "works" do
3
+ Demo.logger.info "works"
4
+ end
5
+
6
+ context "mainframe" do
7
+ it "hacks" do
8
+ Demo.logger.info "hacks"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe "things" do
4
+ include_examples "win"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe "zebra" do
4
+ include_examples "win"
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new
4
+
5
+ RSpec::Core::RakeTask.new(:rcov) do |task|
6
+ task.rcov = true
7
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-logsplit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - digitalextremist //
8
+ - Tim Carey-Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-05-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: A new logger for each example
43
+ email:
44
+ - code@extremist.digital
45
+ - tim@spork.in
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - ".rspec"
52
+ - ".travis.yml"
53
+ - CHANGES.md
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/rspec/log_split.rb
59
+ - lib/rspec/log_split/config.rb
60
+ - lib/rspec/log_split/handler.rb
61
+ - lib/rspec/log_split/version.rb
62
+ - rspec-logsplit.gemspec
63
+ - spec/demo_spec.rb
64
+ - spec/spec_helper.rb
65
+ - spec/support/demo.rb
66
+ - spec/support/shared_examples/win.rb
67
+ - spec/things_spec.rb
68
+ - spec/zebra_spec.rb
69
+ - tasks/rspec.rake
70
+ homepage: https://github.com/abstractive/rspec-logsplit
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.9.2
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 1.3.6
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.4.6
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Separate the logs between examples to allow for easier understanding
94
+ test_files:
95
+ - spec/demo_spec.rb
96
+ - spec/spec_helper.rb
97
+ - spec/support/demo.rb
98
+ - spec/support/shared_examples/win.rb
99
+ - spec/things_spec.rb
100
+ - spec/zebra_spec.rb