source_route 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.hound.yml +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +8 -0
- data/lib/source_route.rb +62 -0
- data/lib/source_route/formats/html.rb +19 -0
- data/lib/source_route/formats/html_template.slim +48 -0
- data/lib/source_route/nature_value.rb +29 -0
- data/lib/source_route/tp_result.rb +96 -0
- data/lib/source_route/version.rb +3 -0
- data/lib/source_route/wrapper.rb +94 -0
- data/source_route.gemspec +26 -0
- data/test/fake_app.rb +4 -0
- data/test/sample_app.rb +20 -0
- data/test/test_helper.rb +8 -0
- data/test/wrapper_test.rb +129 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8d7a56268a17ce2f0ea56258f3eaa28afac00dac
|
4
|
+
data.tar.gz: ffd4b43dd9a3b1dfa298695352cec8486c554d21
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c3a6f2c1acf132f9ef1b8efa0463febbd55e62bc4ecf6f36fc89af0f63793bf662bce96dbfff758663b6753de2e12491284e298da0a25d28f998ca63198320c8
|
7
|
+
data.tar.gz: 334f6cd5aafc1091a17c67ced52bd9f865a3154894a6ec72806c52eba0caa4a23ad5539df249c0e636f217d012019eebd223d8c6b297a407f892542e2f807b16
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.hound.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 raykin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# SourceRoute
|
2
|
+
|
3
|
+
Wrapper of TracePoint
|
4
|
+
|
5
|
+
## Dependency
|
6
|
+
|
7
|
+
ruby 2
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'source_route', git: 'https://github.com/raykin/source-route'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install source_route
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
SourceRoute.enable /ActiveRecord/
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it ( https://github.com/[my-github-username]/source_route/fork )
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create a new Pull Request
|
34
|
+
|
35
|
+
|
36
|
+
### TODO
|
37
|
+
|
38
|
+
Following code is a good sample that track file running sequence, how to change it into a good code design and merge into the gem
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
|
42
|
+
files = []
|
43
|
+
tp = TracePoint.new(:line) do |tp|
|
44
|
+
if tp.path =~ /bole_api/
|
45
|
+
unless files.include? tp.path
|
46
|
+
puts "#{tp.path}".inspect
|
47
|
+
files.push(tp.path)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
tp.enable
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
It's better to add html output format, 'cause it can be kept.
|
data/Rakefile
ADDED
data/lib/source_route.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'logger'
|
3
|
+
require 'singleton'
|
4
|
+
|
5
|
+
require 'awesome_print'
|
6
|
+
|
7
|
+
require "source_route/version"
|
8
|
+
require "source_route/wrapper"
|
9
|
+
require "source_route/tp_result"
|
10
|
+
require "source_route/nature_value"
|
11
|
+
|
12
|
+
module SourceRoute
|
13
|
+
extend self
|
14
|
+
|
15
|
+
def wrapper
|
16
|
+
@@wrapper ||= Wrapper.instance
|
17
|
+
end
|
18
|
+
|
19
|
+
def reset
|
20
|
+
wrapper.reset
|
21
|
+
end
|
22
|
+
|
23
|
+
def disable
|
24
|
+
wrapper.reset
|
25
|
+
end
|
26
|
+
|
27
|
+
def enable(match = nil, &block)
|
28
|
+
wrapper.reset
|
29
|
+
|
30
|
+
wrapper.method_id(match) if match # TODO in future future: should add as wrapper.method_id_or(match)
|
31
|
+
|
32
|
+
wrapper.instance_eval(&block) if block_given?
|
33
|
+
|
34
|
+
wrapper.trace
|
35
|
+
end
|
36
|
+
|
37
|
+
# Not implemented. used in irb or pry.
|
38
|
+
def trace(opt, &block)
|
39
|
+
wrapper.reset
|
40
|
+
opt.each do |k, v|
|
41
|
+
wrapper.send(k, v)
|
42
|
+
end
|
43
|
+
wrapper.trace
|
44
|
+
yield
|
45
|
+
wrapper.tp.disable
|
46
|
+
SourceRoute.build_html_output if opt[:output_format] == :html
|
47
|
+
end
|
48
|
+
|
49
|
+
def build_html_output
|
50
|
+
SourceRoute::Formats::Html.render(wrapper)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Not implement yet
|
54
|
+
class Logger < Logger
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module SourceRoute
|
59
|
+
module Formats
|
60
|
+
autoload :Html, 'source_route/formats/html'
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'slim'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module SourceRoute
|
5
|
+
module Formats
|
6
|
+
module Html
|
7
|
+
|
8
|
+
# results is instance of Wrapper
|
9
|
+
def self.render(results)
|
10
|
+
template_path = File.expand_path "../html_template.slim", __FILE__
|
11
|
+
html_output_str = Slim::Template.new(template_path).render(results)
|
12
|
+
File.open("#{Time.now.strftime('%M%S-%H-%m-%d')}-source-route.html", 'w') do |f|
|
13
|
+
f << html_output_str
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end # END Html
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
doctype html
|
2
|
+
html
|
3
|
+
head
|
4
|
+
title Source Route Result
|
5
|
+
link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"
|
6
|
+
script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"
|
7
|
+
script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"
|
8
|
+
|
9
|
+
body(ng-app="SourceRoute")
|
10
|
+
/ workaround for following case:
|
11
|
+
/ pry(main)> ActiveRecord::Inheritance::ClassMethods.to_json => {} # Dont know why
|
12
|
+
ruby:
|
13
|
+
trace_data = @tp_attrs_results.map do |tp_result|
|
14
|
+
tp_result[:defined_class] = tp_result[:defined_class].nature_value
|
15
|
+
tp_result
|
16
|
+
end
|
17
|
+
|
18
|
+
.data-collect
|
19
|
+
#trace-data data-trace="#{trace_data.to_json}"
|
20
|
+
|
21
|
+
.container(ng-controller="MainCtrl")
|
22
|
+
.top-header
|
23
|
+
h4
|
24
|
+
| Event:
|
25
|
+
=< @conditions.event
|
26
|
+
.trace-flow
|
27
|
+
.row
|
28
|
+
.left-info.col-sm-3
|
29
|
+
.well.well-sm(ng-repeat="klass in definedClasses")
|
30
|
+
p.text-center(ng-bind="klass")
|
31
|
+
.center-info.col-sm-5
|
32
|
+
.well.well-lg(ng-repeat="trace in traces")
|
33
|
+
p
|
34
|
+
span(ng-bind="trace.defined_class")
|
35
|
+
span #
|
36
|
+
span(ng-bind="trace.method_id")
|
37
|
+
.right-info.col-sm-3
|
38
|
+
|
39
|
+
script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"
|
40
|
+
|
41
|
+
javascript:
|
42
|
+
sourceRoute = angular.module('SourceRoute', [])
|
43
|
+
sourceRoute.controller('MainCtrl', function($scope) {
|
44
|
+
$scope.traces = angular.element("#trace-data").data('trace')
|
45
|
+
// it is possible to prevent dirty check on definedClasses after it was generated
|
46
|
+
$scope.definedClasses = _.uniq(_.map($scope.traces, 'defined_class'))
|
47
|
+
$scope.definedClasses.unshift('ALL')
|
48
|
+
})
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class NilClass
|
2
|
+
def nature_value
|
3
|
+
nil
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class String
|
8
|
+
def nature_value
|
9
|
+
self
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Class
|
14
|
+
def nature_value
|
15
|
+
self.name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Module
|
20
|
+
def nature_value
|
21
|
+
self.name
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Symbol
|
26
|
+
def nature_value
|
27
|
+
to_s
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module SourceRoute
|
2
|
+
|
3
|
+
class TpResult
|
4
|
+
|
5
|
+
DEFAULT_ATTRS = {
|
6
|
+
call: [:defined_class, :event, :method_id],
|
7
|
+
return: [:defined_class, :event, :method_id, :return_value]
|
8
|
+
}
|
9
|
+
|
10
|
+
def initialize(wrapper)
|
11
|
+
@wrapper = wrapper
|
12
|
+
|
13
|
+
@output_config = @wrapper.conditions.result_config
|
14
|
+
|
15
|
+
@tp_event = @wrapper.conditions.event.to_sym
|
16
|
+
if @output_config[:selected_attrs].nil? and [@wrapper.conditions.event].flatten.size == 1
|
17
|
+
@output_config[:selected_attrs] = DEFAULT_ATTRS[@tp_event] - [:event]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def build(trace_point_instance)
|
22
|
+
@tp = trace_point_instance
|
23
|
+
collect_tp_data
|
24
|
+
collect_local_var_data
|
25
|
+
collect_instance_var_data
|
26
|
+
@collect_data
|
27
|
+
end
|
28
|
+
|
29
|
+
# always run build before it # not a good design
|
30
|
+
def output
|
31
|
+
|
32
|
+
format = @output_config[:output_format].to_sym
|
33
|
+
|
34
|
+
case format
|
35
|
+
when :none
|
36
|
+
# do nothing
|
37
|
+
when :console
|
38
|
+
console_put
|
39
|
+
when :html
|
40
|
+
# I cant solve the problem: to generate html at the end,
|
41
|
+
# I have to know when the application is end
|
42
|
+
when :test
|
43
|
+
# do nothing at now
|
44
|
+
when :Proc
|
45
|
+
# customize not defined yet
|
46
|
+
# format.call(tp)
|
47
|
+
else
|
48
|
+
klass = "SourceRoute::Formats::#{format.to_s.capitalize}"
|
49
|
+
::SourceRoute.const_get(klass).render(self, trace_point_instance)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def collect_tp_data
|
56
|
+
@collect_data = @output_config[:selected_attrs].inject({}) do |memo, key|
|
57
|
+
memo[key.to_sym] = @tp.send(key) if @tp.respond_to?(key)
|
58
|
+
memo
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def collect_local_var_data
|
63
|
+
if @wrapper.conditions.result_config[:include_local_var]
|
64
|
+
local_var_hash = {}
|
65
|
+
|
66
|
+
@tp.binding.eval('local_variables').each do |v|
|
67
|
+
local_var_hash[v] = @tp.binding.local_variable_get v
|
68
|
+
end
|
69
|
+
|
70
|
+
@collect_data.merge!(local_var: local_var_hash)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def collect_instance_var_data
|
75
|
+
if @wrapper.conditions.result_config[:include_instance_var]
|
76
|
+
instance_var_hash = {}
|
77
|
+
@tp.self.instance_variables.each do |key|
|
78
|
+
instance_var_hash[key] = @tp.self.instance_variable_get(key)
|
79
|
+
end
|
80
|
+
@collect_data.merge!(instance_var: instance_var_hash)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def console_put
|
85
|
+
ret = []
|
86
|
+
ret << "#{@collect_data[:defined_class].inspect}##{@collect_data[:method_id]}"
|
87
|
+
left_values = @collect_data.reject { |k, v| %w[defined_class method_id].include? k.to_s }
|
88
|
+
unless left_values == {}
|
89
|
+
ret << left_values
|
90
|
+
end
|
91
|
+
ap ret
|
92
|
+
end
|
93
|
+
|
94
|
+
end # END TpResult
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module SourceRoute
|
2
|
+
|
3
|
+
class Wrapper
|
4
|
+
include Singleton
|
5
|
+
|
6
|
+
attr_accessor :conditions, :tp, :tp_attrs_results
|
7
|
+
attr_accessor :output_include_local_variables, :output_include_instance_variables
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
reset
|
11
|
+
end
|
12
|
+
|
13
|
+
# output_format can be console, html
|
14
|
+
def reset
|
15
|
+
@tp.disable if @tp
|
16
|
+
@conditions = OpenStruct.new(event: :call, negative: {}, positive: {},
|
17
|
+
result_config: { output_format: 'none',
|
18
|
+
selected_attrs: nil,
|
19
|
+
include_local_var: false,
|
20
|
+
include_instance_var: false
|
21
|
+
})
|
22
|
+
@tp_attrs_results = []
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
# TODO: make event can be array
|
27
|
+
def event(v)
|
28
|
+
@conditions.event = v.to_sym unless v.nil?
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_result_config(value)
|
32
|
+
unless value.is_a? Hash
|
33
|
+
conditions.result_config = value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def output_format(data = nil, &block)
|
38
|
+
conditions.result_config[:output_format] = if data.nil?
|
39
|
+
block
|
40
|
+
else
|
41
|
+
data
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def selected_attrs(data)
|
46
|
+
conditions.result_config[:selected_attrs] = [data].flatten
|
47
|
+
end
|
48
|
+
|
49
|
+
def output_include_local_variables
|
50
|
+
conditions.result_config[:include_local_var] = true
|
51
|
+
end
|
52
|
+
|
53
|
+
def output_include_instance_variables
|
54
|
+
conditions.result_config[:include_instance_var] = true
|
55
|
+
end
|
56
|
+
|
57
|
+
TRACE_POINT_METHODS = [:defined_class, :method_id, :path, :lineno]
|
58
|
+
|
59
|
+
TRACE_POINT_METHODS.each do |m|
|
60
|
+
define_method m do |v|
|
61
|
+
@conditions.positive[m] = v
|
62
|
+
end
|
63
|
+
|
64
|
+
define_method "#{m}_not" do |v|
|
65
|
+
@conditions.negative[m] = v
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def trace
|
70
|
+
# dont wanna init it in tp block, cause tp block could run thousands of time in one cycle trace
|
71
|
+
tp_result = TpResult.new(self)
|
72
|
+
|
73
|
+
track = TracePoint.new conditions.event do |tp|
|
74
|
+
negative_break = conditions.negative.any? do |method_key, value|
|
75
|
+
tp.send(method_key).nature_value =~ Regexp.new(value)
|
76
|
+
end
|
77
|
+
next if negative_break
|
78
|
+
positive_break = conditions.positive.any? do |method_key, value|
|
79
|
+
tp.send(method_key).nature_value !~ Regexp.new(value)
|
80
|
+
end
|
81
|
+
next if positive_break
|
82
|
+
|
83
|
+
ret_data = tp_result.build(tp)
|
84
|
+
tp_result.output
|
85
|
+
tp_attrs_results.push(ret_data)
|
86
|
+
end
|
87
|
+
track.enable
|
88
|
+
self.tp = track
|
89
|
+
track
|
90
|
+
end
|
91
|
+
|
92
|
+
end # Wrapper
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'source_route/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "source_route"
|
8
|
+
spec.version = SourceRoute::VERSION
|
9
|
+
spec.authors = ["raykin"]
|
10
|
+
spec.email = ["raykincoldxiao@gmail.com"]
|
11
|
+
spec.summary = %q{Wrapper of TracePoint.}
|
12
|
+
spec.description = %q{Wrapper of TracePoint.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'awesome_print'
|
22
|
+
spec.add_dependency 'colorize'
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency 'slim'
|
26
|
+
end
|
data/test/fake_app.rb
ADDED
data/test/sample_app.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Dont change it, it's used for stardard test
|
2
|
+
# When add more complex test, update FakeApp
|
3
|
+
class SampleApp
|
4
|
+
|
5
|
+
def initialize(cool=nil)
|
6
|
+
@cool = cool if cool
|
7
|
+
end
|
8
|
+
|
9
|
+
def nonsense
|
10
|
+
end
|
11
|
+
|
12
|
+
def nonsense_with_params(param1 = nil)
|
13
|
+
param2 = 5
|
14
|
+
end
|
15
|
+
|
16
|
+
# call it with SampleApp.new(:cool), then the instance var will be init before call it
|
17
|
+
def nonsense_with_instance_var
|
18
|
+
nonsense
|
19
|
+
end
|
20
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module SourceRoute
|
4
|
+
class WrapperTest < Minitest::Test
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@wrapper = Wrapper.instance
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
SourceRoute.reset
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_enable_return_true
|
17
|
+
@source_route = SourceRoute.enable /nnnonsense/
|
18
|
+
assert @source_route
|
19
|
+
assert_equal @wrapper, SourceRoute.wrapper
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_catch_call_event_only
|
23
|
+
SourceRoute.enable do
|
24
|
+
event :call
|
25
|
+
method_id /nonsense/
|
26
|
+
output_format :test
|
27
|
+
end
|
28
|
+
SampleApp.new.nonsense
|
29
|
+
|
30
|
+
assert @wrapper.tp
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_catch_class_name_by_first_parameter
|
34
|
+
skip
|
35
|
+
# not supported yet
|
36
|
+
@source_route = SourceRoute.enable 'sampleapp'
|
37
|
+
SampleApp.new.nonsense
|
38
|
+
|
39
|
+
assert @wrapper.tp_attrs_results.size > 0
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_match_class_name_by_block_define
|
43
|
+
@source_route = SourceRoute.enable do
|
44
|
+
defined_class 'SampleApp'
|
45
|
+
end
|
46
|
+
|
47
|
+
SampleApp.new.nonsense
|
48
|
+
assert @wrapper.tp_attrs_results.size > 0
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_source_route_with_only_one_parameter
|
52
|
+
@source_route = SourceRoute.enable 'nonsense'
|
53
|
+
SampleApp.new.nonsense
|
54
|
+
|
55
|
+
ret_value = @wrapper.tp_attrs_results.last
|
56
|
+
assert_equal SampleApp, ret_value[:defined_class]
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_wrapper_reset
|
60
|
+
SourceRoute.enable 'nonsense'
|
61
|
+
SampleApp.new.nonsense
|
62
|
+
assert_equal 1, @wrapper.tp_attrs_results.size
|
63
|
+
|
64
|
+
SourceRoute.reset
|
65
|
+
SampleApp.new.nonsense
|
66
|
+
|
67
|
+
assert_equal 0, @wrapper.tp_attrs_results.size
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_source_route_with_block
|
71
|
+
SourceRoute.trace method_id: 'nonsense', output_format: :html do
|
72
|
+
SampleApp.new.nonsense
|
73
|
+
end
|
74
|
+
assert_equal 1, @wrapper.tp_attrs_results.size
|
75
|
+
refute @wrapper.tp.enabled?
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_trace_without_condition
|
79
|
+
SourceRoute.trace output_format: :html do
|
80
|
+
SampleApp.new.nonsense
|
81
|
+
end
|
82
|
+
assert @wrapper.tp_attrs_results.size > 0
|
83
|
+
refute @wrapper.tp.enabled?
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_show_local_variables
|
87
|
+
@source_route = SourceRoute.enable 'nonsense_with_params' do
|
88
|
+
output_include_local_variables
|
89
|
+
end
|
90
|
+
|
91
|
+
SampleApp.new.nonsense_with_params(88)
|
92
|
+
assert_equal 1, @wrapper.tp_attrs_results.size
|
93
|
+
|
94
|
+
ret_value = @wrapper.tp_attrs_results.last
|
95
|
+
|
96
|
+
assert_equal 88, ret_value[:local_var][:param1]
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_show_instance_vars
|
100
|
+
@source_route = SourceRoute.enable 'nonsense' do
|
101
|
+
output_include_instance_variables
|
102
|
+
end
|
103
|
+
|
104
|
+
SampleApp.new(:cool).nonsense_with_instance_var
|
105
|
+
|
106
|
+
assert_equal 2, @wrapper.tp_attrs_results.size
|
107
|
+
ret_value = @wrapper.tp_attrs_results.pop
|
108
|
+
|
109
|
+
assert_equal :cool, ret_value[:instance_var][:@cool]
|
110
|
+
end
|
111
|
+
|
112
|
+
# Nothing has tested really
|
113
|
+
def test_html_format_output
|
114
|
+
@source_route = SourceRoute.enable 'nonsense' do
|
115
|
+
output_include_instance_variables
|
116
|
+
end
|
117
|
+
|
118
|
+
SampleApp.new(:cool).nonsense_with_instance_var
|
119
|
+
|
120
|
+
if ENV['ignore_html_generation'] == 'true'
|
121
|
+
# do nothing. it was set in Rakefile, so rake test will not generate html file
|
122
|
+
else
|
123
|
+
SourceRoute.build_html_output
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: source_route
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- raykin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: awesome_print
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
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: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: slim
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Wrapper of TracePoint.
|
84
|
+
email:
|
85
|
+
- raykincoldxiao@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".hound.yml"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/source_route.rb
|
97
|
+
- lib/source_route/formats/html.rb
|
98
|
+
- lib/source_route/formats/html_template.slim
|
99
|
+
- lib/source_route/nature_value.rb
|
100
|
+
- lib/source_route/tp_result.rb
|
101
|
+
- lib/source_route/version.rb
|
102
|
+
- lib/source_route/wrapper.rb
|
103
|
+
- source_route.gemspec
|
104
|
+
- test/fake_app.rb
|
105
|
+
- test/sample_app.rb
|
106
|
+
- test/test_helper.rb
|
107
|
+
- test/wrapper_test.rb
|
108
|
+
homepage: ''
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.2.2
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Wrapper of TracePoint.
|
132
|
+
test_files:
|
133
|
+
- test/fake_app.rb
|
134
|
+
- test/sample_app.rb
|
135
|
+
- test/test_helper.rb
|
136
|
+
- test/wrapper_test.rb
|
137
|
+
has_rdoc:
|