nunes 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +150 -0
- data/lib/nunes.rb +39 -0
- data/lib/nunes/adapter.rb +56 -0
- data/lib/nunes/adapters/default.rb +10 -0
- data/lib/nunes/adapters/memory.rb +62 -0
- data/lib/nunes/adapters/timing_aliased.rb +17 -0
- data/lib/nunes/instrumentable.rb +102 -0
- data/lib/nunes/subscriber.rb +69 -0
- data/lib/nunes/subscribers/action_controller.rb +80 -0
- data/lib/nunes/subscribers/action_mailer.rb +33 -0
- data/lib/nunes/subscribers/action_view.rb +44 -0
- data/lib/nunes/subscribers/active_record.rb +33 -0
- data/lib/nunes/subscribers/active_support.rb +58 -0
- data/lib/nunes/subscribers/nunes.rb +24 -0
- data/lib/nunes/version.rb +3 -0
- data/nunes.gemspec +22 -0
- data/script/bootstrap +21 -0
- data/script/test +25 -0
- data/script/watch +30 -0
- data/test/adapter_test.rb +40 -0
- data/test/adapters/default_test.rb +26 -0
- data/test/adapters/timing_aliased_test.rb +26 -0
- data/test/cache_instrumentation_test.rb +79 -0
- data/test/controller_instrumentation_test.rb +88 -0
- data/test/fake_udp_socket_test.rb +26 -0
- data/test/helper.rb +25 -0
- data/test/instrumentable_test.rb +100 -0
- data/test/mailer_instrumentation_test.rb +26 -0
- data/test/model_instrumentation_test.rb +55 -0
- data/test/nunes_test.rb +20 -0
- data/test/rails_app/.gitignore +15 -0
- data/test/rails_app/Rakefile +7 -0
- data/test/rails_app/app/assets/images/rails.png +0 -0
- data/test/rails_app/app/assets/javascripts/application.js +15 -0
- data/test/rails_app/app/assets/stylesheets/application.css +13 -0
- data/test/rails_app/app/controllers/application_controller.rb +3 -0
- data/test/rails_app/app/controllers/posts_controller.rb +28 -0
- data/test/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/rails_app/app/mailers/.gitkeep +0 -0
- data/test/rails_app/app/mailers/post_mailer.rb +11 -0
- data/test/rails_app/app/models/.gitkeep +0 -0
- data/test/rails_app/app/models/post.rb +2 -0
- data/test/rails_app/app/views/layouts/application.html.erb +14 -0
- data/test/rails_app/app/views/post_mailer/created.text.erb +1 -0
- data/test/rails_app/app/views/posts/_post.html.erb +1 -0
- data/test/rails_app/app/views/posts/index.html.erb +5 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/config/application.rb +67 -0
- data/test/rails_app/config/boot.rb +6 -0
- data/test/rails_app/config/database.yml +6 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +31 -0
- data/test/rails_app/config/environments/production.rb +64 -0
- data/test/rails_app/config/environments/test.rb +35 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/force_test_schema_load.rb +3 -0
- data/test/rails_app/config/initializers/inflections.rb +15 -0
- data/test/rails_app/config/initializers/mime_types.rb +5 -0
- data/test/rails_app/config/initializers/secret_token.rb +7 -0
- data/test/rails_app/config/initializers/session_store.rb +8 -0
- data/test/rails_app/config/initializers/wrap_parameters.rb +10 -0
- data/test/rails_app/config/locales/en.yml +5 -0
- data/test/rails_app/config/routes.rb +8 -0
- data/test/rails_app/db/migrate/20130417154459_create_posts.rb +8 -0
- data/test/rails_app/db/schema.rb +22 -0
- data/test/rails_app/db/seeds.rb +7 -0
- data/test/rails_app/lib/assets/.gitkeep +0 -0
- data/test/rails_app/lib/tasks/.gitkeep +0 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +25 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/public/index.html +241 -0
- data/test/rails_app/public/robots.txt +5 -0
- data/test/rails_app/script/rails +6 -0
- data/test/subscriber_test.rb +50 -0
- data/test/support/adapter_test_helpers.rb +33 -0
- data/test/support/fake_udp_socket.rb +50 -0
- data/test/view_instrumentation_test.rb +30 -0
- metadata +205 -0
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "minitest/mock"
|
3
|
+
|
4
|
+
class SubscriberTest < ActiveSupport::TestCase
|
5
|
+
attr_reader :subscriber_class
|
6
|
+
|
7
|
+
setup :setup_subscriber_class
|
8
|
+
|
9
|
+
def setup_subscriber_class
|
10
|
+
@subscriber_class = Class.new(Nunes::Subscriber) do
|
11
|
+
def self.pattern
|
12
|
+
/\.test\Z/
|
13
|
+
end
|
14
|
+
|
15
|
+
def foo(*args)
|
16
|
+
increment "test.foo"
|
17
|
+
end
|
18
|
+
|
19
|
+
# minitest stub works with call, so i change it to just return self, since
|
20
|
+
# all we really want to test in this instance is that things are wired
|
21
|
+
# up right, not that call dispatches events correctly
|
22
|
+
def call(*args)
|
23
|
+
self
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
test "subscribe" do
|
29
|
+
client = {}
|
30
|
+
instance = subscriber_class.new(client)
|
31
|
+
|
32
|
+
subscriber_class.stub :new, instance do
|
33
|
+
mock = Minitest::Mock.new
|
34
|
+
mock.expect :subscribe, :subscriber, [subscriber_class.pattern, instance]
|
35
|
+
|
36
|
+
assert_equal :subscriber,
|
37
|
+
subscriber_class.subscribe(adapter, subscriber: mock)
|
38
|
+
|
39
|
+
mock.verify
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
test "initialize" do
|
44
|
+
adapter = Object.new
|
45
|
+
Nunes::Adapter.stub :wrap, adapter do
|
46
|
+
instance = subscriber_class.new({})
|
47
|
+
assert_equal adapter, instance.adapter
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module AdapterTestHelpers
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
setup :setup_memory_adapter
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :adapter
|
9
|
+
|
10
|
+
def setup_memory_adapter
|
11
|
+
@adapter = Nunes::Adapters::Memory.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def assert_timer(metric)
|
15
|
+
assert adapter.timer?(metric),
|
16
|
+
"Expected the timer #{metric.inspect} to be included in #{adapter.timer_metric_names.inspect}, but it was not."
|
17
|
+
end
|
18
|
+
|
19
|
+
def assert_no_timer(metric)
|
20
|
+
assert ! adapter.timer?(metric),
|
21
|
+
"Expected the timer #{metric.inspect} to not be included in #{adapter.timer_metric_names.inspect}, but it was."
|
22
|
+
end
|
23
|
+
|
24
|
+
def assert_counter(metric)
|
25
|
+
assert adapter.counter?(metric),
|
26
|
+
"Expected the counter #{metric.inspect} to be included in #{adapter.counter_metric_names.inspect}, but it was not."
|
27
|
+
end
|
28
|
+
|
29
|
+
def assert_no_counter(metric)
|
30
|
+
assert ! adapter.counter?(metric),
|
31
|
+
"Expected the counter #{metric.inspect} to not be included in adapter.counter_metric_names.inspect}, but it was."
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class FakeUdpSocket
|
2
|
+
attr_reader :buffer
|
3
|
+
|
4
|
+
TimingRegex = /\:\d+\|ms\Z/
|
5
|
+
CounterRegex = /\:\d+\|c\Z/
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@buffer = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def send(message, *rest)
|
12
|
+
@buffer.push message
|
13
|
+
end
|
14
|
+
|
15
|
+
def recv
|
16
|
+
@buffer.shift
|
17
|
+
end
|
18
|
+
|
19
|
+
def clear
|
20
|
+
@buffer = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def timer_metrics
|
24
|
+
@buffer.grep(TimingRegex)
|
25
|
+
end
|
26
|
+
|
27
|
+
def timer_metric_names
|
28
|
+
timer_metrics.map { |op| op.gsub(TimingRegex, '') }
|
29
|
+
end
|
30
|
+
|
31
|
+
def timer?(metric)
|
32
|
+
timer_metric_names.include?(metric)
|
33
|
+
end
|
34
|
+
|
35
|
+
def counter_metrics
|
36
|
+
@buffer.grep(CounterRegex)
|
37
|
+
end
|
38
|
+
|
39
|
+
def counter_metric_names
|
40
|
+
counter_metrics.map { |op| op.gsub(CounterRegex, '') }
|
41
|
+
end
|
42
|
+
|
43
|
+
def counter?(metric)
|
44
|
+
counter_metric_names.include?(metric)
|
45
|
+
end
|
46
|
+
|
47
|
+
def inspect
|
48
|
+
"<FakeUdpSocket: #{@buffer.inspect}>"
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class ViewInstrumentationTest < ActionController::TestCase
|
4
|
+
tests PostsController
|
5
|
+
|
6
|
+
setup :setup_subscriber
|
7
|
+
teardown :teardown_subscriber
|
8
|
+
|
9
|
+
def setup_subscriber
|
10
|
+
@subscriber = Nunes::Subscribers::ActionView.subscribe(adapter)
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown_subscriber
|
14
|
+
ActiveSupport::Notifications.unsubscribe @subscriber if @subscriber
|
15
|
+
end
|
16
|
+
|
17
|
+
test "render_template" do
|
18
|
+
get :index
|
19
|
+
|
20
|
+
assert_response :success
|
21
|
+
assert_timer "action_view.app.views.posts.index.html.erb"
|
22
|
+
end
|
23
|
+
|
24
|
+
test "render_partial" do
|
25
|
+
get :index
|
26
|
+
|
27
|
+
assert_response :success
|
28
|
+
assert_timer "action_view.app.views.posts._post.html.erb"
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nunes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- John Nunemaker
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
description: The friendly gem that instruments everything for you, like I would if
|
31
|
+
I could.
|
32
|
+
email:
|
33
|
+
- nunemaker@gmail.com
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- lib/nunes.rb
|
43
|
+
- lib/nunes/adapter.rb
|
44
|
+
- lib/nunes/adapters/default.rb
|
45
|
+
- lib/nunes/adapters/memory.rb
|
46
|
+
- lib/nunes/adapters/timing_aliased.rb
|
47
|
+
- lib/nunes/instrumentable.rb
|
48
|
+
- lib/nunes/subscriber.rb
|
49
|
+
- lib/nunes/subscribers/action_controller.rb
|
50
|
+
- lib/nunes/subscribers/action_mailer.rb
|
51
|
+
- lib/nunes/subscribers/action_view.rb
|
52
|
+
- lib/nunes/subscribers/active_record.rb
|
53
|
+
- lib/nunes/subscribers/active_support.rb
|
54
|
+
- lib/nunes/subscribers/nunes.rb
|
55
|
+
- lib/nunes/version.rb
|
56
|
+
- nunes.gemspec
|
57
|
+
- script/bootstrap
|
58
|
+
- script/test
|
59
|
+
- script/watch
|
60
|
+
- test/adapter_test.rb
|
61
|
+
- test/adapters/default_test.rb
|
62
|
+
- test/adapters/timing_aliased_test.rb
|
63
|
+
- test/cache_instrumentation_test.rb
|
64
|
+
- test/controller_instrumentation_test.rb
|
65
|
+
- test/fake_udp_socket_test.rb
|
66
|
+
- test/helper.rb
|
67
|
+
- test/instrumentable_test.rb
|
68
|
+
- test/mailer_instrumentation_test.rb
|
69
|
+
- test/model_instrumentation_test.rb
|
70
|
+
- test/nunes_test.rb
|
71
|
+
- test/rails_app/.gitignore
|
72
|
+
- test/rails_app/Rakefile
|
73
|
+
- test/rails_app/app/assets/images/rails.png
|
74
|
+
- test/rails_app/app/assets/javascripts/application.js
|
75
|
+
- test/rails_app/app/assets/stylesheets/application.css
|
76
|
+
- test/rails_app/app/controllers/application_controller.rb
|
77
|
+
- test/rails_app/app/controllers/posts_controller.rb
|
78
|
+
- test/rails_app/app/helpers/application_helper.rb
|
79
|
+
- test/rails_app/app/mailers/.gitkeep
|
80
|
+
- test/rails_app/app/mailers/post_mailer.rb
|
81
|
+
- test/rails_app/app/models/.gitkeep
|
82
|
+
- test/rails_app/app/models/post.rb
|
83
|
+
- test/rails_app/app/views/layouts/application.html.erb
|
84
|
+
- test/rails_app/app/views/post_mailer/created.text.erb
|
85
|
+
- test/rails_app/app/views/posts/_post.html.erb
|
86
|
+
- test/rails_app/app/views/posts/index.html.erb
|
87
|
+
- test/rails_app/config.ru
|
88
|
+
- test/rails_app/config/application.rb
|
89
|
+
- test/rails_app/config/boot.rb
|
90
|
+
- test/rails_app/config/database.yml
|
91
|
+
- test/rails_app/config/environment.rb
|
92
|
+
- test/rails_app/config/environments/development.rb
|
93
|
+
- test/rails_app/config/environments/production.rb
|
94
|
+
- test/rails_app/config/environments/test.rb
|
95
|
+
- test/rails_app/config/initializers/backtrace_silencers.rb
|
96
|
+
- test/rails_app/config/initializers/force_test_schema_load.rb
|
97
|
+
- test/rails_app/config/initializers/inflections.rb
|
98
|
+
- test/rails_app/config/initializers/mime_types.rb
|
99
|
+
- test/rails_app/config/initializers/secret_token.rb
|
100
|
+
- test/rails_app/config/initializers/session_store.rb
|
101
|
+
- test/rails_app/config/initializers/wrap_parameters.rb
|
102
|
+
- test/rails_app/config/locales/en.yml
|
103
|
+
- test/rails_app/config/routes.rb
|
104
|
+
- test/rails_app/db/migrate/20130417154459_create_posts.rb
|
105
|
+
- test/rails_app/db/schema.rb
|
106
|
+
- test/rails_app/db/seeds.rb
|
107
|
+
- test/rails_app/lib/assets/.gitkeep
|
108
|
+
- test/rails_app/lib/tasks/.gitkeep
|
109
|
+
- test/rails_app/public/404.html
|
110
|
+
- test/rails_app/public/422.html
|
111
|
+
- test/rails_app/public/500.html
|
112
|
+
- test/rails_app/public/favicon.ico
|
113
|
+
- test/rails_app/public/index.html
|
114
|
+
- test/rails_app/public/robots.txt
|
115
|
+
- test/rails_app/script/rails
|
116
|
+
- test/subscriber_test.rb
|
117
|
+
- test/support/adapter_test_helpers.rb
|
118
|
+
- test/support/fake_udp_socket.rb
|
119
|
+
- test/view_instrumentation_test.rb
|
120
|
+
homepage: https://github.com/jnunemaker/nunes
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 1.8.23
|
142
|
+
signing_key:
|
143
|
+
specification_version: 3
|
144
|
+
summary: The friendly gem that instruments everything for you, like I would if I could.
|
145
|
+
test_files:
|
146
|
+
- test/adapter_test.rb
|
147
|
+
- test/adapters/default_test.rb
|
148
|
+
- test/adapters/timing_aliased_test.rb
|
149
|
+
- test/cache_instrumentation_test.rb
|
150
|
+
- test/controller_instrumentation_test.rb
|
151
|
+
- test/fake_udp_socket_test.rb
|
152
|
+
- test/helper.rb
|
153
|
+
- test/instrumentable_test.rb
|
154
|
+
- test/mailer_instrumentation_test.rb
|
155
|
+
- test/model_instrumentation_test.rb
|
156
|
+
- test/nunes_test.rb
|
157
|
+
- test/rails_app/.gitignore
|
158
|
+
- test/rails_app/Rakefile
|
159
|
+
- test/rails_app/app/assets/images/rails.png
|
160
|
+
- test/rails_app/app/assets/javascripts/application.js
|
161
|
+
- test/rails_app/app/assets/stylesheets/application.css
|
162
|
+
- test/rails_app/app/controllers/application_controller.rb
|
163
|
+
- test/rails_app/app/controllers/posts_controller.rb
|
164
|
+
- test/rails_app/app/helpers/application_helper.rb
|
165
|
+
- test/rails_app/app/mailers/.gitkeep
|
166
|
+
- test/rails_app/app/mailers/post_mailer.rb
|
167
|
+
- test/rails_app/app/models/.gitkeep
|
168
|
+
- test/rails_app/app/models/post.rb
|
169
|
+
- test/rails_app/app/views/layouts/application.html.erb
|
170
|
+
- test/rails_app/app/views/post_mailer/created.text.erb
|
171
|
+
- test/rails_app/app/views/posts/_post.html.erb
|
172
|
+
- test/rails_app/app/views/posts/index.html.erb
|
173
|
+
- test/rails_app/config.ru
|
174
|
+
- test/rails_app/config/application.rb
|
175
|
+
- test/rails_app/config/boot.rb
|
176
|
+
- test/rails_app/config/database.yml
|
177
|
+
- test/rails_app/config/environment.rb
|
178
|
+
- test/rails_app/config/environments/development.rb
|
179
|
+
- test/rails_app/config/environments/production.rb
|
180
|
+
- test/rails_app/config/environments/test.rb
|
181
|
+
- test/rails_app/config/initializers/backtrace_silencers.rb
|
182
|
+
- test/rails_app/config/initializers/force_test_schema_load.rb
|
183
|
+
- test/rails_app/config/initializers/inflections.rb
|
184
|
+
- test/rails_app/config/initializers/mime_types.rb
|
185
|
+
- test/rails_app/config/initializers/secret_token.rb
|
186
|
+
- test/rails_app/config/initializers/session_store.rb
|
187
|
+
- test/rails_app/config/initializers/wrap_parameters.rb
|
188
|
+
- test/rails_app/config/locales/en.yml
|
189
|
+
- test/rails_app/config/routes.rb
|
190
|
+
- test/rails_app/db/migrate/20130417154459_create_posts.rb
|
191
|
+
- test/rails_app/db/schema.rb
|
192
|
+
- test/rails_app/db/seeds.rb
|
193
|
+
- test/rails_app/lib/assets/.gitkeep
|
194
|
+
- test/rails_app/lib/tasks/.gitkeep
|
195
|
+
- test/rails_app/public/404.html
|
196
|
+
- test/rails_app/public/422.html
|
197
|
+
- test/rails_app/public/500.html
|
198
|
+
- test/rails_app/public/favicon.ico
|
199
|
+
- test/rails_app/public/index.html
|
200
|
+
- test/rails_app/public/robots.txt
|
201
|
+
- test/rails_app/script/rails
|
202
|
+
- test/subscriber_test.rb
|
203
|
+
- test/support/adapter_test_helpers.rb
|
204
|
+
- test/support/fake_udp_socket.rb
|
205
|
+
- test/view_instrumentation_test.rb
|