logion 0.0.2
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/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +40 -0
- data/config/initializers/logion.rb +1 -0
- data/lib/logion/engine.rb +15 -0
- data/lib/logion/formatter.rb +36 -0
- data/lib/logion/logger_patcher.rb +58 -0
- data/lib/logion/version.rb +3 -0
- data/lib/logion.rb +119 -0
- metadata +81 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: be8e6f2bd8f3e0b454a4d84146da86c40603c4bf
|
|
4
|
+
data.tar.gz: 1eda10f8e112c492920fc8536b8061af7a616033
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6875a5407fe0b56b8efb0381b70308de61f9186c57c18c4377c112d65ed29054149161ac8f0516de9cd89cbd0ef83884a8f7b3885f0b12ae57941f2dd67bdaf8
|
|
7
|
+
data.tar.gz: 8ee522fb25fdf7d100c1f3e78d7a7168af87df3fb29e0ae40d2bdeb4d1312502cb54ae34b2e43c06dad3f2432289b1c9d2ad097b573c275721071ad21637ff59
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2015 YOURNAME
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
begin
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
6
|
+
end
|
|
7
|
+
begin
|
|
8
|
+
require 'rdoc/task'
|
|
9
|
+
rescue LoadError
|
|
10
|
+
require 'rdoc/rdoc'
|
|
11
|
+
require 'rake/rdoctask'
|
|
12
|
+
RDoc::Task = Rake::RDocTask
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
17
|
+
rdoc.title = 'Logion'
|
|
18
|
+
rdoc.options << '--line-numbers'
|
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
|
24
|
+
load 'rails/tasks/engine.rake'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Bundler::GemHelper.install_tasks
|
|
29
|
+
|
|
30
|
+
require 'rake/testtask'
|
|
31
|
+
|
|
32
|
+
Rake::TestTask.new(:test) do |t|
|
|
33
|
+
t.libs << 'lib'
|
|
34
|
+
t.libs << 'test'
|
|
35
|
+
t.pattern = 'test/**/*_test.rb'
|
|
36
|
+
t.verbose = false
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
task :default => :test
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Logion::Logion.new
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Logion
|
|
2
|
+
super_class = if Object.const_defined?('Rails')
|
|
3
|
+
::Rails::Engine
|
|
4
|
+
else
|
|
5
|
+
Object
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class Engine < super_class
|
|
9
|
+
require 'colorize'
|
|
10
|
+
require 'rspec'
|
|
11
|
+
require 'rspec/core/formatters/base_formatter'
|
|
12
|
+
require 'logion/formatter'
|
|
13
|
+
require 'logion/logger_patcher'
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Logion
|
|
2
|
+
class Formatter < RSpec::Core::Formatters::BaseFormatter
|
|
3
|
+
RSpec::Core::Formatters.register self, :example_failed, :dump_failures
|
|
4
|
+
|
|
5
|
+
def initialize(output)
|
|
6
|
+
@output = output
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def example_failed(notification)
|
|
10
|
+
show_failure_debug_info(notification.example)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def dump_failures(notification)
|
|
14
|
+
return if notification.failure_notifications.empty?
|
|
15
|
+
notification.examples.each do |example|
|
|
16
|
+
next unless example.exception
|
|
17
|
+
show_failure_debug_info(example)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def show_failure_debug_info(example)
|
|
24
|
+
@output.puts(::Logion::Logion.colorize('----------------------------', color: :yellow))
|
|
25
|
+
@output.puts(::Logion::Logion.colorize(example.rerun_argument, color: :yellow, background: :blue))
|
|
26
|
+
@output.puts(::Logion::Logion.colorize(example.metadata[:log_location].to_s, color: :white, background: :blue))
|
|
27
|
+
if example.metadata[:screenshot].is_a?(Hash)
|
|
28
|
+
example.metadata[:screenshot].each do |type, path|
|
|
29
|
+
colorful_type = ::Logion::Logion.colorize(type.to_s, color: :black, background: :white)
|
|
30
|
+
colorful_path = ::Logion::Logion.colorize(path.to_s, color: :black, background: :light_blue)
|
|
31
|
+
@output.puts("#{ colorful_type } #{ colorful_path }")
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module Logion
|
|
2
|
+
class LoggerPatcher
|
|
3
|
+
attr_accessor :logger, :logion_instance
|
|
4
|
+
|
|
5
|
+
def initialize(logion_instance)
|
|
6
|
+
self.logion_instance = logion_instance
|
|
7
|
+
self.logger = logion_instance.logger
|
|
8
|
+
|
|
9
|
+
additional_logging = proc do |*args, &block|
|
|
10
|
+
log_to_separate_file *args, &block
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
logger.instance_variable_set '@additional_logging', additional_logging
|
|
14
|
+
|
|
15
|
+
# we don't want to ruin your pretty logger, so lets extend it
|
|
16
|
+
def logger.add(*args, &block)
|
|
17
|
+
@additional_logging.call(*args, &block)
|
|
18
|
+
super
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def severity_colors(severity_name)
|
|
23
|
+
{
|
|
24
|
+
WARN: [:black, :yellow],
|
|
25
|
+
DEBUG: [:white, :blue],
|
|
26
|
+
INFO: [:black, :green],
|
|
27
|
+
FATAL: [:white, :red],
|
|
28
|
+
ERROR: [:black, :light_red],
|
|
29
|
+
UNKNOWN: [:white, :black]
|
|
30
|
+
}[severity_name]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def format_log_entry(severity, message = nil, progname = nil, *_rest)
|
|
34
|
+
message ||= progname
|
|
35
|
+
|
|
36
|
+
severity_name = Logger::Severity.constants.find do |name|
|
|
37
|
+
Logger::Severity.const_get(name) == severity
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
color, background = severity_colors(severity_name)
|
|
41
|
+
|
|
42
|
+
prefix = "#{ Process.pid } #{ '%10s' % "(#{ severity_name })" }:"
|
|
43
|
+
prefix = ::Logion::Logion.colorize(prefix, color: color, background: background)
|
|
44
|
+
|
|
45
|
+
"#{ prefix } #{ message }"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def log_to_separate_file(*args, &block)
|
|
49
|
+
info_file = logion_instance.log_path_holder
|
|
50
|
+
|
|
51
|
+
if File.exists?(info_file)
|
|
52
|
+
separate_log = File.read(info_file)
|
|
53
|
+
formatted_entry = format_log_entry(*args, &block)
|
|
54
|
+
open(separate_log, 'a') { |f| f.puts formatted_entry }
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
data/lib/logion.rb
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
require "logion/engine"
|
|
2
|
+
|
|
3
|
+
module Logion
|
|
4
|
+
class Logion
|
|
5
|
+
attr_accessor :options
|
|
6
|
+
|
|
7
|
+
def self.colorize(string, *args, &block)
|
|
8
|
+
return string if Object.const_defined?(:Colored)
|
|
9
|
+
string.colorize(*args, &block)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
DEFAULT_CONFIG = {
|
|
13
|
+
split_per_occurance: true,
|
|
14
|
+
log_path_holder: -> { Pathname.new('tmp').join ".current_spec_log_path#{ ENV['TEST_ENV_NUMBER'] }" },
|
|
15
|
+
log_base: -> { Pathname.new('tmp').join 'log', "tests#{ ENV['TEST_ENV_NUMBER'] }" },
|
|
16
|
+
add_hooks: ->(logion) { fail "Rspec not present!" },
|
|
17
|
+
logger: -> { fail 'No logger provided' },
|
|
18
|
+
separator: lambda do |logion, example, action|
|
|
19
|
+
logion.logger.debug colorize("#{ example.rerun_argument } #{ action }:", color: :white, background: :red)
|
|
20
|
+
end,
|
|
21
|
+
patcher_class: ::Logion::LoggerPatcher
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
RAILS_DEFAULTS = {
|
|
25
|
+
log_path_holder: -> { Rails.root.join 'tmp', ".current_spec_log_path#{ ENV['TEST_ENV_NUMBER'] }" },
|
|
26
|
+
log_base: -> { Rails.root.join 'tmp', 'log', "tests#{ ENV['TEST_ENV_NUMBER'] }" },
|
|
27
|
+
logger: -> { Rails.logger }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
RSPEC_DEFAULTS = {
|
|
31
|
+
add_hooks: ->(logion) { logion.configure_rspec },
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
[DEFAULT_CONFIG, RAILS_DEFAULTS, RSPEC_DEFAULTS].flat_map(&:keys).each do |param|
|
|
35
|
+
define_method param do |*args|
|
|
36
|
+
if self.options[param].is_a?(Proc)
|
|
37
|
+
proc = self.options[param]
|
|
38
|
+
proc.(*[self, *args].first(proc.arity))
|
|
39
|
+
else
|
|
40
|
+
self.options[param]
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def initialize(init_options = {})
|
|
46
|
+
defaults = DEFAULT_CONFIG
|
|
47
|
+
|
|
48
|
+
if Object.const_defined?('Rails')
|
|
49
|
+
defaults.merge! RAILS_DEFAULTS
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
if Object.const_defined?('RSpec')
|
|
53
|
+
defaults.merge! RSPEC_DEFAULTS
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
self.options = defaults.merge init_options
|
|
57
|
+
add_hooks
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def configure_rspec
|
|
61
|
+
me = self
|
|
62
|
+
formatter_klass = ::Logion::Formatter
|
|
63
|
+
|
|
64
|
+
RSpec.configure do |config|
|
|
65
|
+
config.add_formatter(formatter_klass)
|
|
66
|
+
|
|
67
|
+
config.before(:suite) do
|
|
68
|
+
me.init
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
config.before(:each) do |example|
|
|
72
|
+
me.before(example)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
config.after(:each) do |example|
|
|
76
|
+
me.after(example)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def init
|
|
82
|
+
FileUtils.rm_f log_path_holder
|
|
83
|
+
FileUtils.remove_dir log_base, force: true
|
|
84
|
+
@log_patcher = patcher_class.new self
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def before(example)
|
|
88
|
+
relative_path = example.rerun_argument.sub(/:(\d+)$/, '/\1.log')
|
|
89
|
+
location = log_base.join(relative_path)
|
|
90
|
+
location = safe_location(location, relative_path)
|
|
91
|
+
|
|
92
|
+
location.dirname.mkpath
|
|
93
|
+
example.metadata[:log_location] = location
|
|
94
|
+
File.write(log_path_holder, location.to_s)
|
|
95
|
+
separator example, :start
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def after(example)
|
|
99
|
+
separator example, :end
|
|
100
|
+
FileUtils.rm log_path_holder
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
private
|
|
104
|
+
|
|
105
|
+
def safe_location(location, relative_path)
|
|
106
|
+
uniq_location = location
|
|
107
|
+
if split_per_occurance
|
|
108
|
+
suffix = 0
|
|
109
|
+
|
|
110
|
+
while File.exists? uniq_location
|
|
111
|
+
suffix += 1
|
|
112
|
+
safe_relative_path = relative_path.sub(/\.log$/, ".#{ suffix }.log")
|
|
113
|
+
uniq_location = log_base.join safe_relative_path
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
uniq_location
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: logion
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Valery Guskov
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-02-03 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '>='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
|
21
|
+
requirements:
|
|
22
|
+
- - '>='
|
|
23
|
+
- !ruby/object:Gem::Version
|
|
24
|
+
version: '0'
|
|
25
|
+
prerelease: false
|
|
26
|
+
type: :runtime
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: colorize
|
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ~>
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.7.7
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ~>
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: 0.7.7
|
|
39
|
+
prerelease: false
|
|
40
|
+
type: :runtime
|
|
41
|
+
description: A hacky gem to output per-example logs
|
|
42
|
+
email:
|
|
43
|
+
- valerijs.gusjkovs@gmail.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- MIT-LICENSE
|
|
49
|
+
- README.rdoc
|
|
50
|
+
- Rakefile
|
|
51
|
+
- config/initializers/logion.rb
|
|
52
|
+
- lib/logion.rb
|
|
53
|
+
- lib/logion/engine.rb
|
|
54
|
+
- lib/logion/formatter.rb
|
|
55
|
+
- lib/logion/logger_patcher.rb
|
|
56
|
+
- lib/logion/version.rb
|
|
57
|
+
homepage:
|
|
58
|
+
licenses:
|
|
59
|
+
- MIT
|
|
60
|
+
metadata: {}
|
|
61
|
+
post_install_message:
|
|
62
|
+
rdoc_options: []
|
|
63
|
+
require_paths:
|
|
64
|
+
- lib
|
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - '>='
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - '>='
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
requirements: []
|
|
76
|
+
rubyforge_project:
|
|
77
|
+
rubygems_version: 2.4.6
|
|
78
|
+
signing_key:
|
|
79
|
+
specification_version: 4
|
|
80
|
+
summary: Output logs per example
|
|
81
|
+
test_files: []
|