hotch 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fbe8d78ac8f8fef080af36b0e270cf254d09d74
4
- data.tar.gz: 5dff4be305ecff6f3b6fbe8be8380485d356441e
3
+ metadata.gz: fe917b25f6086e27f2ee1a3480a9799cf544a7b7
4
+ data.tar.gz: cfa25132e4ce2f7ac32a4c11d58890a9f9baba1f
5
5
  SHA512:
6
- metadata.gz: 9ef50419b126cfbbe35018b9deed68c448a085695f8b3c6564e3ee22c20d6dd30be2a23afbb6ed7d2526f90901b98bf3184a98cb105f95374ad97381ff2c809f
7
- data.tar.gz: e8dcff3496fe2cc11ed99eb00b3d173ba347a7d9f0c8540a07c675f9bbbb852519912de9416329c64bb1b5c9d94ebe4f238f64786019d9b6b5a02e6cbf4ac59e
6
+ metadata.gz: 108abb9f4f02c719daa08a3789ab3371063c46b6ba3490a8d3d254d09434791fb7c21bb923907a8aae80cd83d735e9a24e3b22d510ce25418b93c40250da3ab3
7
+ data.tar.gz: 42ded157f0a1c13c15877033be0538780f4a0d04a87e5865fb33a878f5584e203d4c51ec9f65b835b5696f1818faaf69b688a424f91a57bfab20c2db17276186
data/README.md CHANGED
@@ -81,6 +81,11 @@ Load `hotch/minitest` in your `test/test_helper.rb` like this:
81
81
  ```ruby
82
82
  require 'minitest/autorun'
83
83
  require 'hotch/minitest'
84
+
85
+ Hotch::Minitest.run
86
+ Hotch::Minitest.run(filter: /MyClass/)
87
+ Hotch::Minitest.run(options: <stackprof options>)
88
+ Hotch::Minitest.run(options: { limit: 200 })
84
89
  ```
85
90
 
86
91
  ## Caveat
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "stackprof", "~> 0.2.7"
21
+ spec.add_runtime_dependency "stackprof", "~> 0.2.8"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.7"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
@@ -4,13 +4,15 @@ require 'tmpdir'
4
4
  require 'hotch/monkey_patches'
5
5
 
6
6
  class Hotch
7
- attr_reader :name, :viewer, :filter
7
+ attr_reader :name, :viewer, :filter, :options
8
8
 
9
- def initialize(name, viewer: nil, filter: nil)
9
+ def initialize(name, viewer: nil, filter: nil, options: {})
10
10
  @name = name
11
11
  @viewer = viewer
12
- @filter = filter
12
+ @options = options
13
13
  @reports = []
14
+
15
+ @options[:filter] = Regexp.new(filter) if filter
14
16
  end
15
17
 
16
18
  def start(*args)
@@ -73,19 +75,15 @@ class Hotch
73
75
  end
74
76
 
75
77
  def report_dump(report, dir, file)
76
- path = File.join(dir, file)
77
- File.open(path, 'wb') do |fh|
78
+ write_file(dir, file) do |fh|
78
79
  report.print_dump(fh)
79
80
  end
80
- path
81
81
  end
82
82
 
83
83
  def report_dot(report, dir, file)
84
- path = File.join(dir, file)
85
- File.open(path, 'wb') do |fh|
86
- report.print_graphviz(filter && Regexp.new(filter), fh)
84
+ write_file(dir, file) do |fh|
85
+ report.print_graphviz(options, fh)
87
86
  end
88
- path
89
87
  end
90
88
 
91
89
  def convert_svg(dir, dot, file)
@@ -93,14 +91,23 @@ class Hotch
93
91
  system("dot", "-Tsvg", "-o", svg, dot) or raise "dot failed"
94
92
  svg
95
93
  end
94
+
95
+ def write_file(dir, file)
96
+ path = File.join(dir, file)
97
+ File.open(path, 'wb') do |fh|
98
+ yield fh
99
+ end
100
+ path
101
+ end
96
102
  end
97
103
 
98
- def Hotch(name: $0, aggregate: true, viewer: ENV['HOTCH_VIEWER'], filter: ENV['HOTCH_FILTER'])
104
+ def Hotch(name: $0, aggregate: true, viewer: ENV['HOTCH_VIEWER'], filter: ENV['HOTCH_FILTER'], options: {})
99
105
  hotch = if aggregate
100
- $hotch ||= Hotch.new(name, viewer: viewer, filter: filter)
106
+ $hotch ||= Hotch.new(name, viewer: viewer, filter: filter, options: options)
101
107
  else
102
108
  caller = Kernel.caller_locations(1).first
103
- Hotch.new("#{name}:#{caller.path}:#{caller.lineno}", viewer: viewer, filter: filter)
109
+ name = "#{name}:#{caller.path}:#{caller.lineno}"
110
+ Hotch.new(name, viewer: viewer, filter: filter, options: options)
104
111
  end
105
112
 
106
113
  hotch.report_at_exit
@@ -1,13 +1,25 @@
1
+ require "hotch"
2
+
1
3
  class Hotch
2
4
  module Minitest
3
5
  # Usage in test/test_helper.rb:
4
6
  #
5
7
  # require 'hotch/minitest'
6
8
  #
7
- def self.aggregate
9
+ # Hotch::Minitest.run
10
+ # Hotch::Minitest.run(filter: /MyClass/)
11
+ # Hotch::Minitest.run(options: <stackprof options>)
12
+ # Hotch::Minitest.run(options: { limit: 200 })
13
+ #
14
+ def self.run(**options)
15
+ ::Minitest.singleton_class.prepend Hotch::Minitest.aggregate(**options)
16
+ end
17
+
18
+ def self.aggregate(**options)
8
19
  Module.new do
9
- def run_one_method(*args)
10
- Hotch(aggregate: true) do
20
+ define_method(:run_one_method) do |*args|
21
+ options[:aggregate] = true
22
+ Hotch(**options) do
11
23
  super(*args)
12
24
  end
13
25
  end
@@ -15,6 +27,3 @@ class Hotch
15
27
  end
16
28
  end
17
29
  end
18
-
19
- require "hotch"
20
- Minitest.singleton_class.prepend Hotch::Minitest.aggregate
@@ -1,3 +1,3 @@
1
1
  class Hotch
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Suschlik
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.7
19
+ version: 0.2.8
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.7
26
+ version: 0.2.8
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -92,9 +92,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 2.5.1
95
+ rubygems_version: 2.4.8
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: Profile helper
99
99
  test_files: []
100
- has_rdoc: