split_rails_logs 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/split_rails_logs.rb +48 -0
  3. metadata +72 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a85f21f8683101e9832cf2b84f673744a12a3ff5af716d4c34d6afd481eae70b
4
+ data.tar.gz: c5a8d1c28b2a600fdf252edc8971fb55b448b2c2e20bec65279e94017c673831
5
+ SHA512:
6
+ metadata.gz: 63f8ad1af7e53c0221a4d4a43b9edb6215fdcb15d0d6260fb12fca4c6d124c7e96ffaaf399aefbc8da1ad39fc7d65fc3f80f6fa0c66bf6b8b33dd4b5d33bc7c3
7
+ data.tar.gz: c96c0065661c31c68da85226fdd9766a766d16a6c1c2fbe657133356cf369bbea2ff223f40ebda9b53fd2d6c91cfbe1a602adeb2fe6c1b8c42d62b03d0ca7533
@@ -0,0 +1,48 @@
1
+ require "active_support"
2
+ require "fileutils"
3
+ require "logger"
4
+ require "stringio"
5
+
6
+ class SplitRailsLogs
7
+ # Write out logs for each example
8
+ def self.for_all(example)
9
+ capture_logs_for(example) do |path, string|
10
+ write_logs(path, string)
11
+ end
12
+ end
13
+
14
+ # Write out logs only for each failed example
15
+ def self.for_failed(example)
16
+ capture_logs_for(example) do |path, string, failed|
17
+ write_logs(path, string) if failed
18
+ end
19
+ end
20
+
21
+ private_class_method def self.capture_logs_for(example)
22
+ raise "SplitRailsLogs - Must initialize Rails application first" unless defined?(Rails) && Rails.initialized?
23
+
24
+ # reusing the io and logger instances each time prevents
25
+ # runaway memory usage
26
+ @io ||= StringIO.new
27
+ @logger ||= Logger.new(@io).tap do |logger|
28
+ Rails.logger.extend(ActiveSupport::Logger.broadcast(logger))
29
+ end
30
+
31
+ # beause we're reusing the same io and logger
32
+ # we need to truncate and rewind the io each time
33
+ @io.truncate(0)
34
+ @io.rewind
35
+
36
+ example.call
37
+
38
+ log_file_suffix = ":#{example.metadata[:line_number]}.test.log"
39
+ log_path = Rails.root.join("log").join(example.metadata[:file_path] + log_file_suffix)
40
+
41
+ yield log_path, @io.string, example.exception
42
+ end
43
+
44
+ private_class_method def self.write_logs(path, string)
45
+ FileUtils.mkdir_p(File.dirname(path))
46
+ File.write(path, string)
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: split_rails_logs
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - Nick Browne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.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'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3'
41
+ description:
42
+ email:
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/split_rails_logs.rb
48
+ homepage: https://github.com/nickbrowne/split_rails_logs
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">"
64
+ - !ruby/object:Gem::Version
65
+ version: 1.3.1
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.7.3
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Split Rails logs across RSpec examples
72
+ test_files: []