rspec_log 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/LICENSE +19 -0
- data/README.md +24 -0
- data/lib/rspec_log.rb +58 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 54d9a38887fb52da80082d4445c5a0754a55a4b2
|
4
|
+
data.tar.gz: b1e474547b21fccd021fcf2e4362db6d938ce456
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c44f4becb20f5ed2e3c5c0e8727d39ef9dd410b4621456083533a765dd87064b590ca644fde926063758d99cb1a19e6902569f181fb1be070202a23520bdb2a3
|
7
|
+
data.tar.gz: 0a168639ac58898cf8499b12a501c54e26b33e731be6abdc5bb243c3798222910c4d291e8782980515b95a5029f1769ecc04efa6dba90e2b0d680febd466652b
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
3
|
+
a copy of this software and associated documentation files (the
|
4
|
+
"Software"), to deal in the Software without restriction, including
|
5
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
6
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
7
|
+
permit persons to whom the Software is furnished to do so, subject to
|
8
|
+
the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be
|
11
|
+
included in all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
14
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
15
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
17
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
18
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
19
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# rspec_log
|
2
|
+
RSPEC logging which is persistent accross runs, can be reset on command!
|
3
|
+
|
4
|
+
```ruby
|
5
|
+
gem 'rspec_log'
|
6
|
+
```
|
7
|
+
|
8
|
+
Setup the test this way in your spec_helper.rb file:
|
9
|
+
```ruby
|
10
|
+
config.before :suite do
|
11
|
+
logs = RSpecLog.new(newfile: true) # newfile clears the file if it exists
|
12
|
+
end
|
13
|
+
|
14
|
+
config.after :all do
|
15
|
+
logs.write_file
|
16
|
+
end
|
17
|
+
|
18
|
+
config.after :suite do
|
19
|
+
RSpecLog.print_logs_from_file
|
20
|
+
end
|
21
|
+
```
|
22
|
+
```ruby
|
23
|
+
RSpecLog.add_to_log 'Name log', 'context info'
|
24
|
+
```
|
data/lib/rspec_log.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
DEFAULT_LOG_FILE = '.rspec_log.yml'.freeze
|
5
|
+
|
6
|
+
# Class that allows for displaying logs or general messages at that are consistent across rspec tests
|
7
|
+
class RSpecLog
|
8
|
+
def initialize(filename: DEFAULT_LOG_FILE, newfile: false)
|
9
|
+
@filename = filename
|
10
|
+
RSpecLog.write_hash_to_file({}, @filename) if newfile || !File.exist?(filename)
|
11
|
+
RSpecLog.log_hash_set(YAML.load_file(@filename))
|
12
|
+
end
|
13
|
+
|
14
|
+
# Writes log_hash to, by default, currently set log file or custom file passed to it
|
15
|
+
def write_file(filename: @filename)
|
16
|
+
raise 'Filename is not set, you need to initialize RSpecLog before writing' if filename.nil?
|
17
|
+
RSpecLog.write_hash_to_file(RSpecLog.log_hash, filename)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Parse the YAML log file and print it out in a nice manner
|
21
|
+
def self.print_logs_from_file(filename: DEFAULT_LOG_FILE)
|
22
|
+
file_contents = YAML.load_file(filename)
|
23
|
+
|
24
|
+
return puts 'No logs found'.green if file_contents.empty?
|
25
|
+
puts 'RSpecLogs: '.yellow.bold
|
26
|
+
|
27
|
+
file_contents.each do |key, value|
|
28
|
+
puts key
|
29
|
+
value.each { |v| puts " - #{v.to_s.yellow}" }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# @name - Name of the log message
|
34
|
+
# @value - Content of log message
|
35
|
+
def self.add_to_log(name, value)
|
36
|
+
log_hash[current_node] = [] if log_hash[current_node].nil?
|
37
|
+
log_hash[current_node] << "#{name}, #{value}"
|
38
|
+
log_hash_set(log_hash)
|
39
|
+
end
|
40
|
+
|
41
|
+
private_class_method
|
42
|
+
|
43
|
+
def self.write_hash_to_file(log_hash, filename = DEFAULT_LOG_FILE)
|
44
|
+
File.open(filename, 'w') { |f| f.write(YAML.dump(log_hash, line_width: -1)) }
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.log_hash
|
48
|
+
RSpecLog.instance_variable_get(:@log_hash)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.log_hash_set(item)
|
52
|
+
RSpecLog.instance_variable_set(:@log_hash, item)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.current_node
|
56
|
+
ENV.fetch('TARGET_HOST', "Logged from: #{RSpec.current_example.description.yellow.bold}")
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec_log
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrea Capri
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: colorize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: "\n Provides a Logging system separate to RSpec that can be persistent
|
56
|
+
throughout\n multiple runs of RSpec i.e. multiple files.\n "
|
57
|
+
email:
|
58
|
+
- andrea.a.capri@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
- lib/rspec_log.rb
|
66
|
+
homepage:
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.1.0
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: An RSpec Logger that is persistent throughout multiple rspec files
|
90
|
+
test_files: []
|