rspec-log_split 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rspec +4 -0
- data/Gemfile +7 -0
- data/README.md +38 -0
- data/lib/rspec/log_split.rb +86 -0
- data/rspec-log_split.gemspec +14 -0
- data/spec/demo_spec.rb +13 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/support/demo.rb +5 -0
- data/spec/support/shared_examples/win.rb +11 -0
- data/spec/things_spec.rb +5 -0
- data/spec/zebra_spec.rb +5 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5cfa9a2c014cdb42432ed297b6b897b820439434
|
4
|
+
data.tar.gz: e17667ebffecdc092667bac01fda8b2ac8a12d8c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a4c517387368117d737aa329c1b80377c0e05fb8fdb48d9bcc7b86c887ac5ca4706c24720618e851074670629628a4aab6eac1c0350fa49c1ec0ab60a925d496
|
7
|
+
data.tar.gz: 067283ce6ab856860ed27152136071d2ce46f847f8b4afbac48aa35f133200e45526363d08771b64fbf8194708185e9168db00e86938cfae89146e85844fa11c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -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,86 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
module LogSplit
|
6
|
+
class MyExample
|
7
|
+
def initialize(logger, mod, example, example_logger)
|
8
|
+
@logger = logger
|
9
|
+
@mod = mod
|
10
|
+
@example = example
|
11
|
+
@example_logger = example_logger
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
@mod.logger = @example_logger
|
16
|
+
begin
|
17
|
+
error "starting #{description}"
|
18
|
+
yield
|
19
|
+
rescue Exception => e
|
20
|
+
error "error with #{description}: #{e.inspect}"
|
21
|
+
raise e
|
22
|
+
ensure
|
23
|
+
error "finishing #{description}"
|
24
|
+
@mod.logger = nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def description
|
29
|
+
@example.full_description
|
30
|
+
end
|
31
|
+
|
32
|
+
def error(message)
|
33
|
+
@logger.error message
|
34
|
+
@mod.logger.error message
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Config
|
39
|
+
def initialize(mod, dir)
|
40
|
+
@mod = mod
|
41
|
+
|
42
|
+
@path = Pathname.new(dir)
|
43
|
+
@path.mkpath
|
44
|
+
@logger = logger(@path.join("main"))
|
45
|
+
end
|
46
|
+
|
47
|
+
def run(example, &block)
|
48
|
+
example_path = @path.join(example.location)
|
49
|
+
example_path.parent.mkpath
|
50
|
+
example_logger = logger(example_path.to_path)
|
51
|
+
MyExample.new(@logger, @mod, example, example_logger).run(&block)
|
52
|
+
end
|
53
|
+
|
54
|
+
def logger(path)
|
55
|
+
file = File.open(path, "a")
|
56
|
+
file.sync = true
|
57
|
+
Logger.new(file)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.apply
|
62
|
+
RSpec.configure do |config|
|
63
|
+
config.add_setting :log_split_module
|
64
|
+
config.add_setting :log_split_dir
|
65
|
+
config.add_setting :log_split
|
66
|
+
|
67
|
+
config.before(:suite) do
|
68
|
+
RSpec.configuration.log_split= Config.new(
|
69
|
+
RSpec.configuration.log_split_module,
|
70
|
+
RSpec.configuration.log_split_dir,
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
config.around(:each) do |block|
|
75
|
+
RSpec.configuration.log_split.run(example, &block)
|
76
|
+
end
|
77
|
+
|
78
|
+
config.after(:suite) do
|
79
|
+
MyExample.list_logs if $DEBUG
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
RSpec::LogSplit.apply
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "rspec-log_split"
|
3
|
+
spec.version = "0.0.1"
|
4
|
+
spec.authors = ["Tim Carey-Smith"]
|
5
|
+
spec.email = ["tim@spork.in"]
|
6
|
+
spec.description = %q{A new logger for each example}
|
7
|
+
spec.summary = %q{Separate the logs between examples to allow for easier understanding}
|
8
|
+
spec.homepage = "https://github.com/halorgium/rspec-log_split"
|
9
|
+
spec.license = "MIT"
|
10
|
+
|
11
|
+
spec.files = `git ls-files`.split($/)
|
12
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
13
|
+
spec.require_paths = ["lib"]
|
14
|
+
end
|
data/spec/demo_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'pry'
|
2
|
+
|
3
|
+
require 'rspec/log_split'
|
4
|
+
|
5
|
+
Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.filter_run :focus => true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
|
11
|
+
config.log_split_module = Demo
|
12
|
+
config.log_split_dir = File.expand_path("../../log", __FILE__)
|
13
|
+
end
|
data/spec/things_spec.rb
ADDED
data/spec/zebra_spec.rb
ADDED
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-log_split
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Carey-Smith
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A new logger for each example
|
14
|
+
email:
|
15
|
+
- tim@spork.in
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- .gitignore
|
21
|
+
- .rspec
|
22
|
+
- Gemfile
|
23
|
+
- README.md
|
24
|
+
- lib/rspec/log_split.rb
|
25
|
+
- rspec-log_split.gemspec
|
26
|
+
- spec/demo_spec.rb
|
27
|
+
- spec/spec_helper.rb
|
28
|
+
- spec/support/demo.rb
|
29
|
+
- spec/support/shared_examples/win.rb
|
30
|
+
- spec/things_spec.rb
|
31
|
+
- spec/zebra_spec.rb
|
32
|
+
homepage: https://github.com/halorgium/rspec-log_split
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
metadata: {}
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 2.0.3
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: Separate the logs between examples to allow for easier understanding
|
56
|
+
test_files:
|
57
|
+
- spec/demo_spec.rb
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
- spec/support/demo.rb
|
60
|
+
- spec/support/shared_examples/win.rb
|
61
|
+
- spec/things_spec.rb
|
62
|
+
- spec/zebra_spec.rb
|