ramaze-fnordmetric 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ require 'bacon'
2
+ require File.expand_path('../bacon/color_output', __FILE__)
3
+ require 'ramaze/spec/bacon'
4
+
5
+ Bacon.extend(Bacon::ColorOutput)
6
+ Bacon.summary_on_exit
data/pkg/.gitkeep ADDED
File without changes
@@ -0,0 +1,25 @@
1
+ path = File.expand_path('../', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'ramaze-fnordmetric'
5
+ s.version = '0.0.9'
6
+ s.date = '2012-06-21'
7
+ s.authors = ['Michel Blanc']
8
+ s.email = 'mblanc@erasme.org'
9
+ s.summary = 'A simple fnordmetric helper for Ramaze.'
10
+ s.homepage = 'https://github.com/leucos/ramaze-fnordmetric'
11
+ s.description = s.summary
12
+ s.files = `cd #{path}; git ls-files`.split("\n").sort
13
+ s.has_rdoc = 'yard'
14
+
15
+ s.add_dependency('ramaze', ['>= 2011.07.25'])
16
+ s.add_dependency('redis', ['>= 2.2.0'])
17
+ s.add_dependency('fnordmetric', ['>= 0.9.7'])
18
+
19
+ s.add_development_dependency('rake' , ['>= 0.9.2'])
20
+ s.add_development_dependency('yard' , ['>= 0.7.2'])
21
+ s.add_development_dependency('bacon' , ['>= 1.1.0'])
22
+ s.add_development_dependency('rdiscount', ['>= 1.6.8'])
23
+ s.add_development_dependency('rack-test', ['>= 0.6.1'])
24
+ s.add_development_dependency('simplecov')
25
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,2 @@
1
+ require File.expand_path('../../lib/ramaze/helper/fnordmetric', __FILE__)
2
+ require File.expand_path('../../lib/ramaze/helper/fnordmetric/spec/helper', __FILE__)
@@ -0,0 +1,209 @@
1
+ require File.expand_path('../../helper', __FILE__)
2
+
3
+ # re-open logging stuff so we can trap when R:H:Fnordmetric spits out errors on
4
+ # console
5
+ module Innate
6
+ class LogHub
7
+ # Override error so we can be sure something broke
8
+ def error(message)
9
+ @@last_error = message
10
+ end
11
+
12
+ def last_error
13
+ @@last_error
14
+ end
15
+ end
16
+ end
17
+
18
+ # Re-open helper class to mock redis-related methods
19
+ module Ramaze
20
+
21
+ module Helper
22
+ module Fnordmetric
23
+
24
+ def self.redis
25
+ @@redis
26
+ end
27
+
28
+ def self.fnord
29
+ @@fnord
30
+ end
31
+
32
+ # Redis mocking class
33
+ class RedisMock
34
+ attr_accessor :list
35
+
36
+ def initialize(whatever)
37
+ @list = Array.new
38
+ end
39
+
40
+ def lpush(key, value)
41
+ # We just don't care about key
42
+ @list.push value
43
+ end
44
+
45
+ def lpop(key)
46
+ @list.pop
47
+ end
48
+
49
+ def expire(key, ttl)
50
+ # don't care
51
+ end
52
+
53
+ def llen(key)
54
+ @list.count
55
+ end
56
+
57
+ def del(key)
58
+ @list = []
59
+ end
60
+
61
+ def [](index)
62
+ @list[index]
63
+ end
64
+ end
65
+
66
+ # Fnordmetric mocking class
67
+ class FnordMock
68
+ attr_accessor :last
69
+
70
+ def initialize(whatever)
71
+ @last = nil
72
+ end
73
+
74
+ # This is called by Ramaze::Helper::Fnordmetric
75
+ # and already formatted Fnordmetric-style
76
+ def event(evt, args = {})
77
+ @last = evt
78
+ end
79
+ end
80
+
81
+ def _connect
82
+ @@fnord = FnordMock.new(:redis_url => "mocked, muahahah")
83
+ @@redis = RedisMock.new(:url => "mocked too, niark niark")
84
+ end
85
+
86
+ end
87
+ end
88
+ end
89
+
90
+ # TODO: may be we should check if a redis server is available, and if not load
91
+ # the above code from a specific file
92
+
93
+ # guinea pig controller
94
+ class GuineaPig < Ramaze::Controller
95
+ map '/'
96
+ helper :fnordmetric
97
+
98
+ def event_test(key, value)
99
+ event(key, { :somefield => value })
100
+ end
101
+
102
+ def set_picture_test(url)
103
+ set_picture(url)
104
+ end
105
+
106
+ def set_name_test(name)
107
+ set_name(name)
108
+ end
109
+
110
+ def pageview_test(url)
111
+ pageview(url)
112
+ end
113
+
114
+ def push_pop_test(name, value)
115
+ push_timer(name, :somevalue => value)
116
+ # noop
117
+ pop_timer
118
+ end
119
+
120
+ def times_test(key, value)
121
+ times(key, :somevalue => value) do
122
+ true
123
+ end
124
+ end
125
+
126
+ def clock_test
127
+ end
128
+ clock :clock_test, :i_like_to_clock_it_clock_it, :somevalue => "clo(a)cked !"
129
+
130
+ def clear_timers_test
131
+ clear_timers
132
+ end
133
+
134
+ def push_only_test(name, value)
135
+ # This will leave an un-popped key in the redis stack
136
+ push_timer(name, value)
137
+ end
138
+
139
+ def pop_only_test
140
+ pop_timer
141
+ end
142
+ end
143
+
144
+ # Convenience function to test multiple values
145
+ def check(args)
146
+ args.each_pair do |k,v|
147
+ Ramaze::Helper::Fnordmetric.fnord.last[k].should == v
148
+ end
149
+ end
150
+
151
+ # Convenience debugging function
152
+ def debug(what)
153
+ what = what.class == Array ? what : [ what ]
154
+ pp Ramaze::Helper::Fnordmetric.fnord.last if what.include?(:fnord)
155
+ pp Ramaze::Helper::Fnordmetric.redis.list if what.include?(:redis)
156
+ end
157
+
158
+
159
+ describe('Ramaze::Helper::Fnordmetric') do
160
+ behaves_like :rack_test
161
+
162
+ should 'send events' do
163
+ get('/event_test/abcd/12').status.should == 200
164
+ check({:_type => "abcd", :somefield => "12"})
165
+ end
166
+
167
+ should 'set picture' do
168
+ get('/set_picture_test/this_is_my_pic_url').status.should == 200
169
+ check({:_type => "_set_picture", :url => "this_is_my_pic_url"})
170
+ end
171
+
172
+ should 'set name' do
173
+ get('/set_name_test/this_is_my_name').status.should == 200
174
+ check({:_type => "_set_name", :name => "this_is_my_name"})
175
+ end
176
+
177
+ should 'handle pageview' do
178
+ get('/pageview_test/my_fancy_url').status.should == 200
179
+ check({:_type => "_pageview", :url => "my_fancy_url"})
180
+ end
181
+
182
+ should 'handle push_pop' do
183
+ get('/push_pop_test/push_pop_url/push_pop_value').status.should == 200
184
+ check({:_type => "push_pop_url", "somevalue" => "push_pop_value"})
185
+ Ramaze::Helper::Fnordmetric.fnord.last[:time].should > 0
186
+ end
187
+
188
+ should 'handle clocking a block with times' do
189
+ get('/times_test/times_url/times_value').status.should == 200
190
+ check({:_type => "times_url", "somevalue" => "times_value"})
191
+ end
192
+
193
+ should 'handle clocking a block with times' do
194
+ get('/clock_test').status.should == 200
195
+ check({:_type => "i_like_to_clock_it_clock_it", "somevalue" => "clo(a)cked !"})
196
+ end
197
+
198
+ should 'clear timers' do
199
+ get('/push_only_test/abcd/12').status.should == 200
200
+ get('/clear_timers_test').status.should == 200
201
+ Ramaze::Helper::Fnordmetric.redis.list.should.be.empty
202
+ end
203
+
204
+ should 'handle popping and empty stack gracefuly' do
205
+ get('/pop_only_test').status.should == 200
206
+ Ramaze::Log.last_error.should =~ /Unable to pop timer/
207
+ end
208
+
209
+ end
data/task/bacon.rake ADDED
@@ -0,0 +1,16 @@
1
+ desc "Runs bacon tests with code coverage"
2
+ task :bacon do
3
+ require 'simplecov'
4
+ require 'bacon'
5
+
6
+ Bacon.const_set :Backtraces, false unless ENV['BACON_MUTE'].nil?
7
+
8
+ SimpleCov.command_name 'bacon'
9
+ SimpleCov.start do
10
+ add_filter "spec/"
11
+ add_filter "vendor/"
12
+ add_filter "config"
13
+ end if ENV["COVERAGE"]
14
+
15
+ require File.expand_path('spec/ramaze_fnordmetric/fnordmetric.rb')
16
+ end
data/task/build.rake ADDED
@@ -0,0 +1,34 @@
1
+ # Task group used for building various elements such as the Gem and the
2
+ # documentation.
3
+ namespace :build do
4
+ desc 'Builds the documentation using YARD'
5
+ task :doc do
6
+ gem_path = File.expand_path('../../', __FILE__)
7
+ command = "yard doc #{gem_path}/lib -m markdown -M rdiscount -o #{gem_path}/doc "
8
+ command += "-r #{gem_path}/README.md --private --protected"
9
+
10
+ sh(command)
11
+ end
12
+
13
+ desc 'Builds a new Gem'
14
+ task :gem do
15
+ gem_path = File.expand_path('../../', __FILE__)
16
+ gemspec_path = File.join(
17
+ gem_path,
18
+ "#{Ramaze::Helper::Fnordmetric::Gemspec.name}-" \
19
+ "#{Ramaze::Helper::Fnordmetric::Gemspec.version.version}.gem"
20
+ )
21
+
22
+ pkg_path = File.join(
23
+ gem_path,
24
+ 'pkg',
25
+ "#{Ramaze::Helper::Fnordmetric::Gemspec.name}-" \
26
+ "#{Ramaze::Helper::Fnordmetric::Gemspec.version.version}.gem"
27
+ )
28
+
29
+ # Build and install the gem
30
+ sh('gem', 'build' , File.join(gem_path, 'ramaze-fnordmetric.gemspec'))
31
+ sh('mv' , gemspec_path, pkg_path)
32
+ end
33
+ end # namespace :build
34
+
data/task/clean.rake ADDED
@@ -0,0 +1,4 @@
1
+ require 'rake/clean'
2
+
3
+ CLOBBER.include('coverage/', 'doc/', '.yardoc/')
4
+
data/task/test.rake ADDED
@@ -0,0 +1,8 @@
1
+ desc 'Runs all the tests'
2
+ task :test do
3
+ files = Dir.glob(File.expand_path('../../spec/ramaze_fnordmetric/*.rb', __FILE__))
4
+
5
+ files.each do |file|
6
+ require(file)
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,215 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ramaze-fnordmetric
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michel Blanc
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ramaze
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2011.07.25
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2011.07.25
30
+ - !ruby/object:Gem::Dependency
31
+ name: redis
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 2.2.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.2.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: fnordmetric
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.7
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.7
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.9.2
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.9.2
78
+ - !ruby/object:Gem::Dependency
79
+ name: yard
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 0.7.2
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.7.2
94
+ - !ruby/object:Gem::Dependency
95
+ name: bacon
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: 1.1.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 1.1.0
110
+ - !ruby/object:Gem::Dependency
111
+ name: rdiscount
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 1.6.8
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 1.6.8
126
+ - !ruby/object:Gem::Dependency
127
+ name: rack-test
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: 0.6.1
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: 0.6.1
142
+ - !ruby/object:Gem::Dependency
143
+ name: simplecov
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ description: A simple fnordmetric helper for Ramaze.
159
+ email: mblanc@erasme.org
160
+ executables: []
161
+ extensions: []
162
+ extra_rdoc_files: []
163
+ files:
164
+ - .gitignore
165
+ - .rvmrc
166
+ - Gemfile
167
+ - LICENSE
168
+ - README.md
169
+ - Rakefile
170
+ - examples/README.md
171
+ - examples/example.rb
172
+ - examples/fn.rb
173
+ - lib/ramaze/helper/fnordmetric.rb
174
+ - lib/ramaze/helper/fnordmetric/spec/bacon/color_output.rb
175
+ - lib/ramaze/helper/fnordmetric/spec/helper.rb
176
+ - pkg/.gitkeep
177
+ - ramaze-fnordmetric.gemspec
178
+ - spec/helper.rb
179
+ - spec/ramaze_fnordmetric/fnordmetric.rb
180
+ - task/bacon.rake
181
+ - task/build.rake
182
+ - task/clean.rake
183
+ - task/test.rake
184
+ homepage: https://github.com/leucos/ramaze-fnordmetric
185
+ licenses: []
186
+ post_install_message:
187
+ rdoc_options: []
188
+ require_paths:
189
+ - lib
190
+ required_ruby_version: !ruby/object:Gem::Requirement
191
+ none: false
192
+ requirements:
193
+ - - ! '>='
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ segments:
197
+ - 0
198
+ hash: 3737029466321666576
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
+ none: false
201
+ requirements:
202
+ - - ! '>='
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ segments:
206
+ - 0
207
+ hash: 3737029466321666576
208
+ requirements: []
209
+ rubyforge_project:
210
+ rubygems_version: 1.8.23
211
+ signing_key:
212
+ specification_version: 3
213
+ summary: A simple fnordmetric helper for Ramaze.
214
+ test_files: []
215
+ has_rdoc: yard