fozzie 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +5 -5
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +5 -5
  6. data/Gemfile +3 -3
  7. data/README.md +288 -276
  8. data/Rakefile +6 -6
  9. data/fozzie.gemspec +29 -29
  10. data/fozzie.yml.example +14 -14
  11. data/lib/core_ext/hash/symbolize_keys.rb +21 -21
  12. data/lib/core_ext/module/alias_method_chain.rb +19 -19
  13. data/lib/core_ext/module/monitor.rb +12 -12
  14. data/lib/core_ext/string/snakecase.rb +9 -9
  15. data/lib/fozzie.rb +67 -67
  16. data/lib/fozzie/adapter/statsd.rb +95 -95
  17. data/lib/fozzie/bulk_dsl.rb +27 -27
  18. data/lib/fozzie/configuration.rb +1 -0
  19. data/lib/fozzie/dsl.rb +18 -18
  20. data/lib/fozzie/exception.rb +4 -4
  21. data/lib/fozzie/interface.rb +139 -139
  22. data/lib/fozzie/rack/middleware.rb +43 -43
  23. data/lib/fozzie/sniff.rb +49 -49
  24. data/lib/fozzie/version.rb +3 -3
  25. data/resources/mill.js.example +26 -26
  26. data/spec/config/fozzie.yml +5 -5
  27. data/spec/lib/core_ext/module/monitor_spec.rb +8 -8
  28. data/spec/lib/fozzie/adapter/statsd_spec.rb +82 -82
  29. data/spec/lib/fozzie/bulk_dsl_spec.rb +46 -46
  30. data/spec/lib/fozzie/configuration_spec.rb +125 -125
  31. data/spec/lib/fozzie/dsl_spec.rb +15 -15
  32. data/spec/lib/fozzie/rack/middleware_spec.rb +69 -69
  33. data/spec/lib/fozzie/rack/sinatra_spec.rb +30 -30
  34. data/spec/lib/fozzie/sniff_spec.rb +131 -131
  35. data/spec/lib/fozzie/version_spec.rb +9 -9
  36. data/spec/lib/fozzie_spec.rb +39 -39
  37. data/spec/shared_examples/fozzie_adapter.rb +7 -7
  38. data/spec/shared_examples/interface.rb +159 -159
  39. data/spec/spec_helper.rb +28 -28
  40. metadata +24 -36
  41. data/.rvmrc +0 -1
@@ -1,125 +1,125 @@
1
- require 'spec_helper'
2
- require 'resolv'
3
-
4
- describe Fozzie::Configuration do
5
- it "#host" do
6
- subject.host.should be_kind_of(String)
7
- end
8
-
9
- it "#port" do
10
- subject.port.should be_kind_of(Fixnum)
11
- end
12
-
13
- it "attempts to load configuration from yaml" do
14
- c = Fozzie::Configuration.new({
15
- env: 'test',
16
- config_path: 'spec/',
17
- adapter: :TestAdapter
18
- })
19
- c.stub(:origin_name => "")
20
- c.host.should eq '1.1.1.1'
21
- c.port.should eq 9876
22
- c.appname.should eq 'fozzie'
23
- c.data_prefix.should eq "fozzie#{c.safe_separator}test"
24
- end
25
-
26
- it "defaults env" do
27
- subject.env.should eq 'test'
28
- end
29
-
30
- describe "#adapter" do
31
- it "throw error on incorrect assignment" do
32
- -> { Fozzie::Configuration.new({:env => 'test', :adapter => 'foo'}) }.should raise_error(Fozzie::AdapterMissing)
33
- end
34
-
35
- it "defaults adapter to Statsd" do
36
- subject.adapter.should be_kind_of(Fozzie::Adapter::Statsd)
37
- end
38
- end
39
-
40
- describe "#disable_prefix" do
41
- it "sets the data_prefix to nil" do
42
- subject.disable_prefix
43
- subject.data_prefix.should be_nil
44
- end
45
- end
46
-
47
- describe "#prefix and #data_prefix" do
48
- it "creates a #data_prefix" do
49
- subject.stub(:origin_name => "")
50
- subject.data_prefix.should eq 'test'
51
- end
52
-
53
- it "creates a #data_prefix with appname when set" do
54
- subject.stub(:origin_name => "")
55
- subject.appname = 'astoria'
56
- subject.data_prefix.should eq 'astoria.test'
57
- end
58
-
59
- it "creates a #data_prefix with origin" do
60
- subject.appname = 'astoria'
61
- subject.data_prefix.should match /^astoria\.(\S+)\.test$/
62
- end
63
-
64
- it "allows dynamic assignment of #prefix to derive #data_prefix" do
65
- subject.prefix = [:foo, :bar, :car]
66
- subject.data_prefix.should eq 'foo.bar.car'
67
- end
68
-
69
- it "allows dynamic injection of value to prefix" do
70
- subject.stub(:origin_name => "")
71
- subject.prefix << 'git-sha-1234'
72
- subject.data_prefix.should eq 'test.git-sha-1234'
73
- end
74
- end
75
-
76
- it "handles missing configuration namespace" do
77
- proc { Fozzie::Configuration.new({:env => 'blbala', :config_path => 'spec/'}) }.should_not raise_error
78
- end
79
-
80
- it "#namespaces" do
81
- subject.namespaces.should be_kind_of(Array)
82
- subject.namespaces.should include("Stats")
83
- subject.namespaces.should include("S")
84
- end
85
-
86
- describe "#sniff?" do
87
- it "defaults to false for testing" do
88
- subject.stub(:env => "test")
89
- subject.sniff?.should be_false
90
- end
91
-
92
- it "defaults true when in development" do
93
- subject.stub(:env => "development")
94
- subject.sniff?.should be_true
95
- end
96
-
97
- it "defaults true when in production" do
98
- subject.stub(:env => "production")
99
- subject.sniff?.should be_true
100
- end
101
- end
102
-
103
- describe "#sniff_envs allows configuration for #sniff?" do
104
- let!(:sniff_envs) { subject.stub(:sniff_envs => ['test']) }
105
-
106
- it "scopes to return false" do
107
- subject.stub(:env => "development")
108
- subject.sniff?.should be_false
109
- end
110
-
111
- it "scopes to return true" do
112
- subject.stub(:env => "test")
113
- subject.sniff?.should be_true
114
- end
115
-
116
- end
117
-
118
- describe "ignoring prefix" do
119
- it "does not use prefix when set to ignore" do
120
- subject.disable_prefix
121
- subject.ignore_prefix.should eq(true)
122
- end
123
- end
124
-
125
- end
1
+ require 'spec_helper'
2
+ require 'resolv'
3
+
4
+ describe Fozzie::Configuration do
5
+ it "#host" do
6
+ subject.host.should be_kind_of(String)
7
+ end
8
+
9
+ it "#port" do
10
+ subject.port.should be_kind_of(Fixnum)
11
+ end
12
+
13
+ it "attempts to load configuration from yaml" do
14
+ c = Fozzie::Configuration.new({
15
+ env: 'test',
16
+ config_path: 'spec/',
17
+ adapter: :TestAdapter
18
+ })
19
+ c.stub(:origin_name => "")
20
+ c.host.should eq '1.1.1.1'
21
+ c.port.should eq 9876
22
+ c.appname.should eq 'fozzie'
23
+ c.data_prefix.should eq "fozzie#{c.safe_separator}test"
24
+ end
25
+
26
+ it "defaults env" do
27
+ subject.env.should eq 'test'
28
+ end
29
+
30
+ describe "#adapter" do
31
+ it "throw error on incorrect assignment" do
32
+ -> { Fozzie::Configuration.new({:env => 'test', :adapter => 'foo'}) }.should raise_error(Fozzie::AdapterMissing)
33
+ end
34
+
35
+ it "defaults adapter to Statsd" do
36
+ subject.adapter.should be_kind_of(Fozzie::Adapter::Statsd)
37
+ end
38
+ end
39
+
40
+ describe "#disable_prefix" do
41
+ it "sets the data_prefix to nil" do
42
+ subject.disable_prefix
43
+ subject.data_prefix.should be_nil
44
+ end
45
+ end
46
+
47
+ describe "#prefix and #data_prefix" do
48
+ it "creates a #data_prefix" do
49
+ subject.stub(:origin_name => "")
50
+ subject.data_prefix.should eq 'test'
51
+ end
52
+
53
+ it "creates a #data_prefix with appname when set" do
54
+ subject.stub(:origin_name => "")
55
+ subject.appname = 'astoria'
56
+ subject.data_prefix.should eq 'astoria.test'
57
+ end
58
+
59
+ it "creates a #data_prefix with origin" do
60
+ subject.appname = 'astoria'
61
+ subject.data_prefix.should match /^astoria\.(\S+)\.test$/
62
+ end
63
+
64
+ it "allows dynamic assignment of #prefix to derive #data_prefix" do
65
+ subject.prefix = [:foo, :bar, :car]
66
+ subject.data_prefix.should eq 'foo.bar.car'
67
+ end
68
+
69
+ it "allows dynamic injection of value to prefix" do
70
+ subject.stub(:origin_name => "")
71
+ subject.prefix << 'git-sha-1234'
72
+ subject.data_prefix.should eq 'test.git-sha-1234'
73
+ end
74
+ end
75
+
76
+ it "handles missing configuration namespace" do
77
+ proc { Fozzie::Configuration.new({:env => 'blbala', :config_path => 'spec/'}) }.should_not raise_error
78
+ end
79
+
80
+ it "#namespaces" do
81
+ subject.namespaces.should be_kind_of(Array)
82
+ subject.namespaces.should include("Stats")
83
+ subject.namespaces.should include("S")
84
+ end
85
+
86
+ describe "#sniff?" do
87
+ it "defaults to false for testing" do
88
+ subject.stub(:env => "test")
89
+ subject.sniff?.should be_false
90
+ end
91
+
92
+ it "defaults true when in development" do
93
+ subject.stub(:env => "development")
94
+ subject.sniff?.should be_true
95
+ end
96
+
97
+ it "defaults true when in production" do
98
+ subject.stub(:env => "production")
99
+ subject.sniff?.should be_true
100
+ end
101
+ end
102
+
103
+ describe "#sniff_envs allows configuration for #sniff?" do
104
+ let!(:sniff_envs) { subject.stub(:sniff_envs => ['test']) }
105
+
106
+ it "scopes to return false" do
107
+ subject.stub(:env => "development")
108
+ subject.sniff?.should be_false
109
+ end
110
+
111
+ it "scopes to return true" do
112
+ subject.stub(:env => "test")
113
+ subject.sniff?.should be_true
114
+ end
115
+
116
+ end
117
+
118
+ describe "ignoring prefix" do
119
+ it "does not use prefix when set to ignore" do
120
+ subject.disable_prefix
121
+ subject.ignore_prefix.should eq(true)
122
+ end
123
+ end
124
+
125
+ end
@@ -1,16 +1,16 @@
1
- require 'spec_helper'
2
- require 'fozzie/interface'
3
-
4
- describe Fozzie::Dsl do
5
-
6
- subject { Fozzie::Dsl.instance }
7
-
8
- it_behaves_like "interface"
9
-
10
- it "acts an a singleton" do
11
- Fozzie.c.namespaces.each do |k|
12
- Kernel.const_get(k).should eq Fozzie::Dsl.instance
13
- end
14
- end
15
-
1
+ require 'spec_helper'
2
+ require 'fozzie/interface'
3
+
4
+ describe Fozzie::Dsl do
5
+
6
+ subject { Fozzie::Dsl.instance }
7
+
8
+ it_behaves_like "interface"
9
+
10
+ it "acts an a singleton" do
11
+ Fozzie.c.namespaces.each do |k|
12
+ Kernel.const_get(k).should eq Fozzie::Dsl.instance
13
+ end
14
+ end
15
+
16
16
  end
@@ -1,70 +1,70 @@
1
- require 'spec_helper'
2
- require 'fozzie/rack/middleware'
3
-
4
- describe Fozzie::Rack::Middleware do
5
-
6
- subject do
7
- unless defined?(RackApp)
8
- RackApp = Class.new { def call(env); env end }
9
- end
10
- Fozzie::Rack::Middleware.new RackApp.new
11
- end
12
-
13
- it { should respond_to(:call) }
14
- it { should respond_to(:generate_key) }
15
-
16
- describe "subject" do
17
- it "returns env on call for testing" do
18
- subject.call({}).should == {}
19
- end
20
- end
21
-
22
- describe "#call" do
23
-
24
- it "ignored stats request when path not valid" do
25
- fake_env = { 'PATH_INFO' => '' }
26
- subject.should_receive(:call_without_timer).with(fake_env)
27
- subject.call(fake_env)
28
- end
29
-
30
- it "passes request with timer on index" do
31
- fake_env = { 'PATH_INFO' => '/' }
32
- subject.should_receive(:call_with_timer).with('index.render', fake_env)
33
- subject.call(fake_env)
34
- end
35
-
36
- it "passes request with timer on full path" do
37
- fake_env = { 'PATH_INFO' => '/somewhere/nice' }
38
- subject.should_receive(:call_with_timer).with('somewhere.nice.render', fake_env)
39
- subject.call(fake_env)
40
- end
41
-
42
- it "passes request onto app" do
43
- envs = ['', '/', '/somewhere/nice'].each do |p|
44
- fake_env = { 'PATH_INFO' => p }
45
- subject.app.should_receive(:call).with(fake_env)
46
- subject.call(fake_env)
47
- end
48
- end
49
- end
50
-
51
- describe "#generate_key" do
52
-
53
- it "returns nil when applicable" do
54
- fake_env = { 'PATH_INFO' => '' }
55
- subject.generate_key(fake_env).should be_nil
56
- end
57
-
58
- it "returns index when root" do
59
- fake_env = { 'PATH_INFO' => '/' }
60
- subject.generate_key(fake_env).should == 'index.render'
61
- end
62
-
63
- it "returns dotted value" do
64
- fake_env = { 'PATH_INFO' => '/somewhere/nice' }
65
- subject.generate_key(fake_env).should == 'somewhere.nice.render'
66
- end
67
-
68
- end
69
-
1
+ require 'spec_helper'
2
+ require 'fozzie/rack/middleware'
3
+
4
+ describe Fozzie::Rack::Middleware do
5
+
6
+ subject do
7
+ unless defined?(RackApp)
8
+ RackApp = Class.new { def call(env); env end }
9
+ end
10
+ Fozzie::Rack::Middleware.new RackApp.new
11
+ end
12
+
13
+ it { should respond_to(:call) }
14
+ it { should respond_to(:generate_key) }
15
+
16
+ describe "subject" do
17
+ it "returns env on call for testing" do
18
+ subject.call({}).should == {}
19
+ end
20
+ end
21
+
22
+ describe "#call" do
23
+
24
+ it "ignored stats request when path not valid" do
25
+ fake_env = { 'PATH_INFO' => '' }
26
+ subject.should_receive(:call_without_timer).with(fake_env)
27
+ subject.call(fake_env)
28
+ end
29
+
30
+ it "passes request with timer on index" do
31
+ fake_env = { 'PATH_INFO' => '/' }
32
+ subject.should_receive(:call_with_timer).with('index.render', fake_env)
33
+ subject.call(fake_env)
34
+ end
35
+
36
+ it "passes request with timer on full path" do
37
+ fake_env = { 'PATH_INFO' => '/somewhere/nice' }
38
+ subject.should_receive(:call_with_timer).with('somewhere.nice.render', fake_env)
39
+ subject.call(fake_env)
40
+ end
41
+
42
+ it "passes request onto app" do
43
+ envs = ['', '/', '/somewhere/nice'].each do |p|
44
+ fake_env = { 'PATH_INFO' => p }
45
+ subject.app.should_receive(:call).with(fake_env)
46
+ subject.call(fake_env)
47
+ end
48
+ end
49
+ end
50
+
51
+ describe "#generate_key" do
52
+
53
+ it "returns nil when applicable" do
54
+ fake_env = { 'PATH_INFO' => '' }
55
+ subject.generate_key(fake_env).should be_nil
56
+ end
57
+
58
+ it "returns index when root" do
59
+ fake_env = { 'PATH_INFO' => '/' }
60
+ subject.generate_key(fake_env).should == 'index.render'
61
+ end
62
+
63
+ it "returns dotted value" do
64
+ fake_env = { 'PATH_INFO' => '/somewhere/nice' }
65
+ subject.generate_key(fake_env).should == 'somewhere.nice.render'
66
+ end
67
+
68
+ end
69
+
70
70
  end
@@ -1,31 +1,31 @@
1
- require 'fozzie/rack/middleware'
2
- require 'sinatra/base'
3
- require 'rack/test'
4
-
5
- describe "Sinatra Server with Middleware" do
6
- include Rack::Test::Methods
7
-
8
- def app
9
- Sinatra.new do
10
- set :environment, :test
11
- use Fozzie::Rack::Middleware
12
- get('/') { "echo" }
13
- get('/somewhere/nice') { "echo" }
14
- end
15
- end
16
-
17
- it "sends stats request on root" do
18
- S.should_receive(:timing).with('index.render', anything, anything)
19
- get '/'
20
- last_response.should be_ok
21
- last_response.body.should == 'echo'
22
- end
23
-
24
- it "sends stats request on nested path" do
25
- S.should_receive(:timing).with('somewhere.nice.render', anything, anything)
26
-
27
- get '/somewhere/nice'
28
- last_response.should be_ok
29
- last_response.body.should == 'echo'
30
- end
1
+ require 'fozzie/rack/middleware'
2
+ require 'sinatra/base'
3
+ require 'rack/test'
4
+
5
+ describe "Sinatra Server with Middleware" do
6
+ include Rack::Test::Methods
7
+
8
+ def app
9
+ Sinatra.new do
10
+ set :environment, :test
11
+ use Fozzie::Rack::Middleware
12
+ get('/') { "echo" }
13
+ get('/somewhere/nice') { "echo" }
14
+ end
15
+ end
16
+
17
+ it "sends stats request on root" do
18
+ S.should_receive(:timing).with('index.render', anything, anything)
19
+ get '/'
20
+ last_response.should be_ok
21
+ last_response.body.should == 'echo'
22
+ end
23
+
24
+ it "sends stats request on nested path" do
25
+ S.should_receive(:timing).with('somewhere.nice.render', anything, anything)
26
+
27
+ get '/somewhere/nice'
28
+ last_response.should be_ok
29
+ last_response.body.should == 'echo'
30
+ end
31
31
  end