statsd-instrument 2.9.2 → 3.0.2

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 (68) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +16 -23
  3. data/.rubocop.yml +3 -13
  4. data/CHANGELOG.md +33 -0
  5. data/Gemfile +8 -0
  6. data/README.md +3 -3
  7. data/Rakefile +1 -1
  8. data/benchmark/send-metrics-to-dev-null-log +5 -2
  9. data/benchmark/send-metrics-to-local-udp-receiver +8 -6
  10. data/bin/rake +29 -0
  11. data/bin/rubocop +29 -0
  12. data/lib/statsd/instrument.rb +80 -144
  13. data/lib/statsd/instrument/assertions.rb +200 -208
  14. data/lib/statsd/instrument/capture_sink.rb +23 -19
  15. data/lib/statsd/instrument/client.rb +414 -320
  16. data/lib/statsd/instrument/datagram.rb +69 -65
  17. data/lib/statsd/instrument/datagram_builder.rb +81 -77
  18. data/lib/statsd/instrument/dogstatsd_datagram.rb +76 -72
  19. data/lib/statsd/instrument/dogstatsd_datagram_builder.rb +68 -64
  20. data/lib/statsd/instrument/environment.rb +79 -98
  21. data/lib/statsd/instrument/expectation.rb +96 -96
  22. data/lib/statsd/instrument/helpers.rb +10 -35
  23. data/lib/statsd/instrument/log_sink.rb +20 -16
  24. data/lib/statsd/instrument/matchers.rb +86 -71
  25. data/lib/statsd/instrument/null_sink.rb +12 -8
  26. data/lib/statsd/instrument/railtie.rb +11 -11
  27. data/lib/statsd/instrument/statsd_datagram_builder.rb +12 -8
  28. data/lib/statsd/instrument/strict.rb +12 -123
  29. data/lib/statsd/instrument/udp_sink.rb +50 -46
  30. data/lib/statsd/instrument/version.rb +1 -1
  31. data/statsd-instrument.gemspec +2 -8
  32. data/test/assertions_test.rb +46 -12
  33. data/test/capture_sink_test.rb +8 -8
  34. data/test/client_test.rb +62 -51
  35. data/test/datagram_builder_test.rb +29 -29
  36. data/test/datagram_test.rb +1 -1
  37. data/test/dogstatsd_datagram_builder_test.rb +28 -28
  38. data/test/environment_test.rb +10 -46
  39. data/test/helpers/rubocop_helper.rb +11 -8
  40. data/test/helpers_test.rb +5 -5
  41. data/test/integration_test.rb +10 -25
  42. data/test/log_sink_test.rb +2 -2
  43. data/test/matchers_test.rb +36 -36
  44. data/test/null_sink_test.rb +2 -2
  45. data/test/rubocop/metric_return_value_test.rb +3 -3
  46. data/test/rubocop/metric_value_keyword_argument_test.rb +1 -1
  47. data/test/rubocop/positional_arguments_test.rb +10 -10
  48. data/test/statsd_instrumentation_test.rb +97 -122
  49. data/test/statsd_test.rb +50 -75
  50. data/test/test_helper.rb +7 -5
  51. data/test/udp_sink_test.rb +8 -8
  52. metadata +7 -125
  53. data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
  54. data/benchmark/datagram-client +0 -40
  55. data/lib/statsd/instrument/backend.rb +0 -18
  56. data/lib/statsd/instrument/backends/capture_backend.rb +0 -32
  57. data/lib/statsd/instrument/backends/logger_backend.rb +0 -20
  58. data/lib/statsd/instrument/backends/null_backend.rb +0 -9
  59. data/lib/statsd/instrument/backends/udp_backend.rb +0 -152
  60. data/lib/statsd/instrument/legacy_client.rb +0 -301
  61. data/lib/statsd/instrument/metric.rb +0 -155
  62. data/test/assertions_on_legacy_client_test.rb +0 -344
  63. data/test/capture_backend_test.rb +0 -26
  64. data/test/compatibility/dogstatsd_datagram_compatibility_test.rb +0 -161
  65. data/test/deprecations_test.rb +0 -139
  66. data/test/logger_backend_test.rb +0 -22
  67. data/test/metric_test.rb +0 -47
  68. data/test/udp_backend_test.rb +0 -228
@@ -12,7 +12,7 @@ class LogSinkTest < Minitest::Test
12
12
  log_sink = StatsD::Instrument::LogSink.new(logger)
13
13
  log_sink << 'foo:1|c' << 'bar:1|c'
14
14
 
15
- assert_equal <<~LOG, log.string
15
+ assert_equal(<<~LOG, log.string)
16
16
  DEBUG: [StatsD] foo:1|c
17
17
  DEBUG: [StatsD] bar:1|c
18
18
  LOG
@@ -27,7 +27,7 @@ class LogSinkTest < Minitest::Test
27
27
  log_sink = StatsD::Instrument::LogSink.new(logger)
28
28
  log_sink << "foo:1|c\n" << "bar:1|c\n"
29
29
 
30
- assert_equal <<~LOG, log.string
30
+ assert_equal(<<~LOG, log.string)
31
31
  DEBUG: [StatsD] foo:1|c
32
32
  DEBUG: [StatsD] bar:1|c
33
33
  LOG
@@ -5,112 +5,112 @@ require 'statsd/instrument/matchers'
5
5
 
6
6
  class MatchersTest < Minitest::Test
7
7
  def test_statsd_increment_matched
8
- assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', {})
9
- .matches?(lambda { StatsD.increment('counter') })
8
+ assert(StatsD::Instrument::Matchers::Increment.new(:c, 'counter', {})
9
+ .matches?(lambda { StatsD.increment('counter') }))
10
10
  end
11
11
 
12
12
  def test_statsd_increment_not_matched
13
- refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', {})
14
- .matches?(lambda { StatsD.increment('not_counter') })
13
+ refute(StatsD::Instrument::Matchers::Increment.new(:c, 'counter', {})
14
+ .matches?(lambda { StatsD.increment('not_counter') }))
15
15
  end
16
16
 
17
17
  def test_statsd_increment_compound_matched
18
18
  matcher_1 = StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['a'])
19
19
  matcher_2 = StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['b'])
20
20
 
21
- assert RSpec::Matchers::BuiltIn::Compound::And.new(matcher_1, matcher_2).matches? lambda {
21
+ assert(RSpec::Matchers::BuiltIn::Compound::And.new(matcher_1, matcher_2).matches?(lambda {
22
22
  StatsD.increment('counter', tags: ['a'])
23
23
  StatsD.increment('counter', tags: ['b'])
24
- }
24
+ }))
25
25
  end
26
26
 
27
27
  def test_statsd_increment_compound_not_matched
28
28
  matcher_1 = StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['a'])
29
29
  matcher_2 = StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['b'])
30
30
 
31
- refute RSpec::Matchers::BuiltIn::Compound::And.new(matcher_1, matcher_2).matches? lambda {
31
+ refute(RSpec::Matchers::BuiltIn::Compound::And.new(matcher_1, matcher_2).matches?(lambda {
32
32
  StatsD.increment('counter', tags: ['a'])
33
33
  StatsD.increment('counter', tags: ['a'])
34
- }
34
+ }))
35
35
  end
36
36
 
37
37
  def test_statsd_increment_with_times_matched
38
- assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 1)
39
- .matches?(lambda { StatsD.increment('counter') })
38
+ assert(StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 1)
39
+ .matches?(lambda { StatsD.increment('counter') }))
40
40
  end
41
41
 
42
42
  def test_statsd_increment_with_times_not_matched
43
- refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2)
44
- .matches? lambda { 3.times { StatsD.increment('counter') } }
43
+ refute(StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2)
44
+ .matches?(lambda { 3.times { StatsD.increment('counter') } }))
45
45
  end
46
46
 
47
47
  def test_statsd_increment_with_sample_rate_matched
48
- assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: 0.5)
49
- .matches?(lambda { StatsD.increment('counter', sample_rate: 0.5) })
48
+ assert(StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: 0.5)
49
+ .matches?(lambda { StatsD.increment('counter', sample_rate: 0.5) }))
50
50
  end
51
51
 
52
52
  def test_statsd_increment_with_sample_rate_not_matched
53
- refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: 0.5)
54
- .matches?(lambda { StatsD.increment('counter', sample_rate: 0.7) })
53
+ refute(StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: 0.5)
54
+ .matches?(lambda { StatsD.increment('counter', sample_rate: 0.7) }))
55
55
  end
56
56
 
57
57
  def test_statsd_increment_with_value_matched
58
- assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1)
59
- .matches?(lambda { StatsD.increment('counter') })
58
+ assert(StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1)
59
+ .matches?(lambda { StatsD.increment('counter') }))
60
60
  end
61
61
 
62
62
  def test_statsd_increment_with_value_matched_when_multiple_metrics
63
- assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1).matches?(lambda {
63
+ assert(StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1).matches?(lambda {
64
64
  StatsD.increment('counter', 2)
65
65
  StatsD.increment('counter', 1)
66
- })
66
+ }))
67
67
  end
68
68
 
69
69
  def test_statsd_increment_with_value_not_matched_when_multiple_metrics
70
- refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1).matches?(lambda {
70
+ refute(StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 1).matches?(lambda {
71
71
  StatsD.increment('counter', 2)
72
72
  StatsD.increment('counter', 3)
73
- })
73
+ }))
74
74
  end
75
75
 
76
76
  def test_statsd_increment_with_value_not_matched
77
- refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 3)
78
- .matches?(lambda { StatsD.increment('counter') })
77
+ refute(StatsD::Instrument::Matchers::Increment.new(:c, 'counter', value: 3)
78
+ .matches?(lambda { StatsD.increment('counter') }))
79
79
  end
80
80
 
81
81
  def test_statsd_increment_with_tags_matched
82
- assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['a', 'b'])
83
- .matches?(lambda { StatsD.increment('counter', tags: ['a', 'b']) })
82
+ assert(StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['a', 'b'])
83
+ .matches?(lambda { StatsD.increment('counter', tags: ['a', 'b']) }))
84
84
  end
85
85
 
86
86
  def test_statsd_increment_with_tags_not_matched
87
- refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['a', 'b'])
88
- .matches?(lambda { StatsD.increment('counter', tags: ['c']) })
87
+ refute(StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['a', 'b'])
88
+ .matches?(lambda { StatsD.increment('counter', tags: ['c']) }))
89
89
  end
90
90
 
91
91
  def test_statsd_increment_with_times_and_value_matched
92
- assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2, value: 1).matches?(lambda {
92
+ assert(StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2, value: 1).matches?(lambda {
93
93
  StatsD.increment('counter', 1)
94
94
  StatsD.increment('counter', 1)
95
- })
95
+ }))
96
96
  end
97
97
 
98
98
  def test_statsd_increment_with_times_and_value_not_matched
99
- refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2, value: 1).matches?(lambda {
99
+ refute(StatsD::Instrument::Matchers::Increment.new(:c, 'counter', times: 2, value: 1).matches?(lambda {
100
100
  StatsD.increment('counter', 1)
101
101
  StatsD.increment('counter', 2)
102
- })
102
+ }))
103
103
  end
104
104
 
105
105
  def test_statsd_increment_with_sample_rate_and_argument_matcher_matched
106
106
  between_matcher = RSpec::Matchers::BuiltIn::BeBetween.new(0.4, 0.6).inclusive
107
- assert StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: between_matcher)
108
- .matches?(lambda { StatsD.increment('counter', sample_rate: 0.5) })
107
+ assert(StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: between_matcher)
108
+ .matches?(lambda { StatsD.increment('counter', sample_rate: 0.5) }))
109
109
  end
110
110
 
111
111
  def test_statsd_increment_with_sample_rate_and_argument_matcher_not_matched
112
112
  between_matcher = RSpec::Matchers::BuiltIn::BeBetween.new(0.4, 0.6).inclusive
113
- refute StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: between_matcher)
114
- .matches?(lambda { StatsD.increment('counter', sample_rate: 0.7) })
113
+ refute(StatsD::Instrument::Matchers::Increment.new(:c, 'counter', sample_rate: between_matcher)
114
+ .matches?(lambda { StatsD.increment('counter', sample_rate: 0.7) }))
115
115
  end
116
116
  end
@@ -11,7 +11,7 @@ class NullSinkTest < Minitest::Test
11
11
 
12
12
  def test_null_sink_sample
13
13
  null_sink = StatsD::Instrument::NullSink.new
14
- assert null_sink.sample?(0), "The null sink should always sample"
15
- assert null_sink.sample?(1), "The null sink should always sample"
14
+ assert(null_sink.sample?(0), "The null sink should always sample")
15
+ assert(null_sink.sample?(1), "The null sink should always sample")
16
16
  end
17
17
  end
@@ -21,14 +21,14 @@ module Rubocop
21
21
  end
22
22
 
23
23
  def test_ok_as_multiple_statement
24
- assert_no_offenses <<~RUBY
24
+ assert_no_offenses(<<~RUBY)
25
25
  StatsD.increment 'foo'
26
26
  StatsD.increment 'bar'
27
27
  RUBY
28
28
  end
29
29
 
30
30
  def test_ok_inside_block
31
- assert_no_offenses <<~RUBY
31
+ assert_no_offenses(<<~RUBY)
32
32
  block do
33
33
  StatsD.measure
34
34
  end
@@ -44,7 +44,7 @@ module Rubocop
44
44
  end
45
45
 
46
46
  def test_ok_when_passing_do_end_block
47
- assert_no_offenses <<~RUBY
47
+ assert_no_offenses(<<~RUBY)
48
48
  block_result = StatsD.measure('foo') do
49
49
  return_something_useful
50
50
  end
@@ -31,7 +31,7 @@ module Rubocop
31
31
  def test_offense_with_value_keyword
32
32
  assert_offense("StatsD.increment('foo', value: 1)")
33
33
  assert_offense("StatsD.increment('foo', :value => 1)")
34
- assert_offense("StatsD.increment('foo', 'value' => 1)")
34
+ # assert_offense("StatsD.increment('foo', 'value' => 1)")
35
35
  assert_offense("StatsD.increment('foo', sample_rate: 0.1, value: 1, tags: ['foo'])")
36
36
  assert_offense("StatsD.increment('foo', value: 1, &block)")
37
37
  end
@@ -51,47 +51,47 @@ module Rubocop
51
51
 
52
52
  def test_autocorrect_only_sample_rate
53
53
  corrected = autocorrect_source("StatsD.increment('foo', 2, 0.5)")
54
- assert_equal "StatsD.increment('foo', 2, sample_rate: 0.5)", corrected
54
+ assert_equal("StatsD.increment('foo', 2, sample_rate: 0.5)", corrected)
55
55
  end
56
56
 
57
57
  def test_autocorrect_only_sample_rate_as_int
58
58
  corrected = autocorrect_source("StatsD.increment('foo', 2, 1)")
59
- assert_equal "StatsD.increment('foo', 2, sample_rate: 1)", corrected
59
+ assert_equal("StatsD.increment('foo', 2, sample_rate: 1)", corrected)
60
60
  end
61
61
 
62
62
  def test_autocorrect_only_tags
63
63
  corrected = autocorrect_source("StatsD.increment('foo', 2, nil, ['foo', 'bar'])")
64
- assert_equal "StatsD.increment('foo', 2, tags: ['foo', 'bar'])", corrected
64
+ assert_equal("StatsD.increment('foo', 2, tags: ['foo', 'bar'])", corrected)
65
65
  end
66
66
 
67
67
  def test_autocorrect_sample_rate_and_tags_as_array
68
68
  corrected = autocorrect_source("StatsD.increment('foo', 2, 0.5, ['foo', 'bar'])")
69
- assert_equal "StatsD.increment('foo', 2, sample_rate: 0.5, tags: ['foo', 'bar'])", corrected
69
+ assert_equal("StatsD.increment('foo', 2, sample_rate: 0.5, tags: ['foo', 'bar'])", corrected)
70
70
  end
71
71
 
72
72
  def test_autocorrect_sample_rate_and_tags_as_hash_with_curly_braces
73
73
  corrected = autocorrect_source("StatsD.increment('foo', 2, 0.5, { foo: 'bar' })")
74
- assert_equal "StatsD.increment('foo', 2, sample_rate: 0.5, tags: { foo: 'bar' })", corrected
74
+ assert_equal("StatsD.increment('foo', 2, sample_rate: 0.5, tags: { foo: 'bar' })", corrected)
75
75
  end
76
76
 
77
77
  def test_autocorrect_sample_rate_and_tags_as_hash_without_curly_braces
78
78
  corrected = autocorrect_source("StatsD.increment('foo', 2, 0.5, foo: 'bar')")
79
- assert_equal "StatsD.increment('foo', 2, sample_rate: 0.5, tags: { foo: 'bar' })", corrected
79
+ assert_equal("StatsD.increment('foo', 2, sample_rate: 0.5, tags: { foo: 'bar' })", corrected)
80
80
  end
81
81
 
82
82
  def test_autocorrect_sample_rate_and_block_pass
83
83
  corrected = autocorrect_source("StatsD.distribution('foo', 2, 0.5, &block)")
84
- assert_equal "StatsD.distribution('foo', 2, sample_rate: 0.5, &block)", corrected
84
+ assert_equal("StatsD.distribution('foo', 2, sample_rate: 0.5, &block)", corrected)
85
85
  end
86
86
 
87
87
  def test_autocorrect_sample_rate_tags_and_block_pass
88
88
  corrected = autocorrect_source("StatsD.measure('foo', 2, nil, foo: 'bar', &block)")
89
- assert_equal "StatsD.measure('foo', 2, tags: { foo: 'bar' }, &block)", corrected
89
+ assert_equal("StatsD.measure('foo', 2, tags: { foo: 'bar' }, &block)", corrected)
90
90
  end
91
91
 
92
92
  def test_autocorrect_sample_rate_and_curly_braces_block
93
93
  corrected = autocorrect_source("StatsD.measure('foo', 2, 0.5) { foo }")
94
- assert_equal "StatsD.measure('foo', 2, sample_rate: 0.5) { foo }", corrected
94
+ assert_equal("StatsD.measure('foo', 2, sample_rate: 0.5) { foo }", corrected)
95
95
  end
96
96
 
97
97
  def test_autocorrect_sample_rate_and_do_end_block
@@ -100,7 +100,7 @@ module Rubocop
100
100
  foo
101
101
  end
102
102
  RUBY
103
- assert_equal <<~RUBY, corrected
103
+ assert_equal(<<~RUBY, corrected)
104
104
  StatsD.distribution 'foo', 124, sample_rate: 0.6, tags: ['bar'] do
105
105
  foo
106
106
  end
@@ -73,31 +73,31 @@ class StatsDInstrumentationTest < Minitest::Test
73
73
  include StatsD::Instrument::Assertions
74
74
 
75
75
  def test_statsd_count_if
76
- ActiveMerchant::Gateway.statsd_count_if :ssl_post, 'ActiveMerchant.Gateway.if'
76
+ ActiveMerchant::Gateway.statsd_count_if(:ssl_post, 'ActiveMerchant.Gateway.if')
77
77
 
78
78
  assert_statsd_increment('ActiveMerchant.Gateway.if') do
79
79
  ActiveMerchant::Gateway.new.purchase(true)
80
80
  ActiveMerchant::Gateway.new.purchase(false)
81
81
  end
82
82
  ensure
83
- ActiveMerchant::Gateway.statsd_remove_count_if :ssl_post, 'ActiveMerchant.Gateway.if'
83
+ ActiveMerchant::Gateway.statsd_remove_count_if(:ssl_post, 'ActiveMerchant.Gateway.if')
84
84
  end
85
85
 
86
86
  def test_statsd_count_if_with_method_receiving_block
87
- ActiveMerchant::Base.statsd_count_if :post_with_block, 'ActiveMerchant.Base.post_with_block' do |result|
87
+ ActiveMerchant::Base.statsd_count_if(:post_with_block, 'ActiveMerchant.Base.post_with_block') do |result|
88
88
  result == 'true'
89
89
  end
90
90
 
91
91
  assert_statsd_increment('ActiveMerchant.Base.post_with_block') do
92
- assert_equal 'true', ActiveMerchant::Base.new.post_with_block { 'true' }
93
- assert_equal 'false', ActiveMerchant::Base.new.post_with_block { 'false' }
92
+ assert_equal('true', ActiveMerchant::Base.new.post_with_block { 'true' })
93
+ assert_equal('false', ActiveMerchant::Base.new.post_with_block { 'false' })
94
94
  end
95
95
  ensure
96
- ActiveMerchant::Base.statsd_remove_count_if :post_with_block, 'ActiveMerchant.Base.post_with_block'
96
+ ActiveMerchant::Base.statsd_remove_count_if(:post_with_block, 'ActiveMerchant.Base.post_with_block')
97
97
  end
98
98
 
99
99
  def test_statsd_count_if_with_block
100
- ActiveMerchant::UniqueGateway.statsd_count_if :ssl_post, 'ActiveMerchant.Gateway.block' do |result|
100
+ ActiveMerchant::UniqueGateway.statsd_count_if(:ssl_post, 'ActiveMerchant.Gateway.block') do |result|
101
101
  result[:success]
102
102
  end
103
103
 
@@ -106,11 +106,11 @@ class StatsDInstrumentationTest < Minitest::Test
106
106
  ActiveMerchant::UniqueGateway.new.purchase(false)
107
107
  end
108
108
  ensure
109
- ActiveMerchant::UniqueGateway.statsd_remove_count_if :ssl_post, 'ActiveMerchant.Gateway.block'
109
+ ActiveMerchant::UniqueGateway.statsd_remove_count_if(:ssl_post, 'ActiveMerchant.Gateway.block')
110
110
  end
111
111
 
112
112
  def test_statsd_count_success
113
- ActiveMerchant::Gateway.statsd_count_success :ssl_post, 'ActiveMerchant.Gateway', sample_rate: 0.5
113
+ ActiveMerchant::Gateway.statsd_count_success(:ssl_post, 'ActiveMerchant.Gateway', sample_rate: 0.5)
114
114
 
115
115
  assert_statsd_increment('ActiveMerchant.Gateway.success', sample_rate: 0.5, times: 1) do
116
116
  ActiveMerchant::Gateway.new.purchase(true)
@@ -122,29 +122,29 @@ class StatsDInstrumentationTest < Minitest::Test
122
122
  ActiveMerchant::Gateway.new.purchase(true)
123
123
  end
124
124
  ensure
125
- ActiveMerchant::Gateway.statsd_remove_count_success :ssl_post, 'ActiveMerchant.Gateway'
125
+ ActiveMerchant::Gateway.statsd_remove_count_success(:ssl_post, 'ActiveMerchant.Gateway')
126
126
  end
127
127
 
128
128
  def test_statsd_count_success_with_method_receiving_block
129
- ActiveMerchant::Base.statsd_count_success :post_with_block, 'ActiveMerchant.Base.post_with_block' do |result|
129
+ ActiveMerchant::Base.statsd_count_success(:post_with_block, 'ActiveMerchant.Base.post_with_block') do |result|
130
130
  result == 'successful'
131
131
  end
132
132
 
133
133
  assert_statsd_increment('ActiveMerchant.Base.post_with_block.success', times: 1) do
134
- assert_equal 'successful', ActiveMerchant::Base.new.post_with_block { 'successful' }
135
- assert_equal 'not so successful', ActiveMerchant::Base.new.post_with_block { 'not so successful' }
134
+ assert_equal('successful', ActiveMerchant::Base.new.post_with_block { 'successful' })
135
+ assert_equal('not so successful', ActiveMerchant::Base.new.post_with_block { 'not so successful' })
136
136
  end
137
137
 
138
138
  assert_statsd_increment('ActiveMerchant.Base.post_with_block.failure', times: 1) do
139
- assert_equal 'successful', ActiveMerchant::Base.new.post_with_block { 'successful' }
140
- assert_equal 'not so successful', ActiveMerchant::Base.new.post_with_block { 'not so successful' }
139
+ assert_equal('successful', ActiveMerchant::Base.new.post_with_block { 'successful' })
140
+ assert_equal('not so successful', ActiveMerchant::Base.new.post_with_block { 'not so successful' })
141
141
  end
142
142
  ensure
143
- ActiveMerchant::Base.statsd_remove_count_success :post_with_block, 'ActiveMerchant.Base.post_with_block'
143
+ ActiveMerchant::Base.statsd_remove_count_success(:post_with_block, 'ActiveMerchant.Base.post_with_block')
144
144
  end
145
145
 
146
146
  def test_statsd_count_success_with_block
147
- ActiveMerchant::UniqueGateway.statsd_count_success :ssl_post, 'ActiveMerchant.Gateway' do |result|
147
+ ActiveMerchant::UniqueGateway.statsd_count_success(:ssl_post, 'ActiveMerchant.Gateway') do |result|
148
148
  result[:success]
149
149
  end
150
150
 
@@ -156,17 +156,17 @@ class StatsDInstrumentationTest < Minitest::Test
156
156
  ActiveMerchant::UniqueGateway.new.purchase(false)
157
157
  end
158
158
  ensure
159
- ActiveMerchant::UniqueGateway.statsd_remove_count_success :ssl_post, 'ActiveMerchant.Gateway'
159
+ ActiveMerchant::UniqueGateway.statsd_remove_count_success(:ssl_post, 'ActiveMerchant.Gateway')
160
160
  end
161
161
 
162
162
  def test_statsd_count
163
- ActiveMerchant::Gateway.statsd_count :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
163
+ ActiveMerchant::Gateway.statsd_count(:ssl_post, 'ActiveMerchant.Gateway.ssl_post')
164
164
 
165
165
  assert_statsd_increment('ActiveMerchant.Gateway.ssl_post') do
166
166
  ActiveMerchant::Gateway.new.purchase(true)
167
167
  end
168
168
  ensure
169
- ActiveMerchant::Gateway.statsd_remove_count :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
169
+ ActiveMerchant::Gateway.statsd_remove_count(:ssl_post, 'ActiveMerchant.Gateway.ssl_post')
170
170
  end
171
171
 
172
172
  def test_statsd_count_with_name_as_lambda
@@ -192,33 +192,33 @@ class StatsDInstrumentationTest < Minitest::Test
192
192
  end
193
193
 
194
194
  def test_statsd_count_with_method_receiving_block
195
- ActiveMerchant::Base.statsd_count :post_with_block, 'ActiveMerchant.Base.post_with_block'
195
+ ActiveMerchant::Base.statsd_count(:post_with_block, 'ActiveMerchant.Base.post_with_block')
196
196
 
197
197
  assert_statsd_increment('ActiveMerchant.Base.post_with_block') do
198
- assert_equal 'block called', ActiveMerchant::Base.new.post_with_block { 'block called' }
198
+ assert_equal('block called', ActiveMerchant::Base.new.post_with_block { 'block called' })
199
199
  end
200
200
  ensure
201
- ActiveMerchant::Base.statsd_remove_count :post_with_block, 'ActiveMerchant.Base.post_with_block'
201
+ ActiveMerchant::Base.statsd_remove_count(:post_with_block, 'ActiveMerchant.Base.post_with_block')
202
202
  end
203
203
 
204
204
  def test_statsd_measure
205
- ActiveMerchant::UniqueGateway.statsd_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3
205
+ ActiveMerchant::UniqueGateway.statsd_measure(:ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3)
206
206
 
207
207
  assert_statsd_measure('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3) do
208
208
  ActiveMerchant::UniqueGateway.new.purchase(true)
209
209
  end
210
210
  ensure
211
- ActiveMerchant::UniqueGateway.statsd_remove_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
211
+ ActiveMerchant::UniqueGateway.statsd_remove_measure(:ssl_post, 'ActiveMerchant.Gateway.ssl_post')
212
212
  end
213
213
 
214
214
  def test_statsd_measure_uses_normalized_metric_name
215
- ActiveMerchant::UniqueGateway.statsd_measure :ssl_post, 'ActiveMerchant::Gateway.ssl_post'
215
+ ActiveMerchant::UniqueGateway.statsd_measure(:ssl_post, 'ActiveMerchant::Gateway.ssl_post')
216
216
 
217
217
  assert_statsd_measure('ActiveMerchant.Gateway.ssl_post') do
218
218
  ActiveMerchant::UniqueGateway.new.purchase(true)
219
219
  end
220
220
  ensure
221
- ActiveMerchant::UniqueGateway.statsd_remove_measure :ssl_post, 'ActiveMerchant::Gateway.ssl_post'
221
+ ActiveMerchant::UniqueGateway.statsd_remove_measure(:ssl_post, 'ActiveMerchant::Gateway.ssl_post')
222
222
  end
223
223
 
224
224
  def test_statsd_measure_raises_without_a_provided_block
@@ -228,43 +228,43 @@ class StatsDInstrumentationTest < Minitest::Test
228
228
  end
229
229
 
230
230
  def test_statsd_measure_with_method_receiving_block
231
- ActiveMerchant::Base.statsd_measure :post_with_block, 'ActiveMerchant.Base.post_with_block'
231
+ ActiveMerchant::Base.statsd_measure(:post_with_block, 'ActiveMerchant.Base.post_with_block')
232
232
 
233
233
  assert_statsd_measure('ActiveMerchant.Base.post_with_block') do
234
- assert_equal 'block called', ActiveMerchant::Base.new.post_with_block { 'block called' }
234
+ assert_equal('block called', ActiveMerchant::Base.new.post_with_block { 'block called' })
235
235
  end
236
236
  ensure
237
- ActiveMerchant::Base.statsd_remove_measure :post_with_block, 'ActiveMerchant.Base.post_with_block'
237
+ ActiveMerchant::Base.statsd_remove_measure(:post_with_block, 'ActiveMerchant.Base.post_with_block')
238
238
  end
239
239
 
240
240
  def test_statsd_measure_with_sample_rate
241
- ActiveMerchant::UniqueGateway.statsd_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1
241
+ ActiveMerchant::UniqueGateway.statsd_measure(:ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1)
242
242
 
243
243
  assert_statsd_measure('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1) do
244
244
  ActiveMerchant::UniqueGateway.new.purchase(true)
245
245
  end
246
246
  ensure
247
- ActiveMerchant::UniqueGateway.statsd_remove_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
247
+ ActiveMerchant::UniqueGateway.statsd_remove_measure(:ssl_post, 'ActiveMerchant.Gateway.ssl_post')
248
248
  end
249
249
 
250
250
  def test_statsd_distribution
251
- ActiveMerchant::UniqueGateway.statsd_distribution :ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3
251
+ ActiveMerchant::UniqueGateway.statsd_distribution(:ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3)
252
252
 
253
253
  assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3) do
254
254
  ActiveMerchant::UniqueGateway.new.purchase(true)
255
255
  end
256
256
  ensure
257
- ActiveMerchant::UniqueGateway.statsd_remove_distribution :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
257
+ ActiveMerchant::UniqueGateway.statsd_remove_distribution(:ssl_post, 'ActiveMerchant.Gateway.ssl_post')
258
258
  end
259
259
 
260
260
  def test_statsd_distribution_uses_normalized_metric_name
261
- ActiveMerchant::UniqueGateway.statsd_distribution :ssl_post, 'ActiveMerchant::Gateway.ssl_post'
261
+ ActiveMerchant::UniqueGateway.statsd_distribution(:ssl_post, 'ActiveMerchant::Gateway.ssl_post')
262
262
 
263
263
  assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post') do
264
264
  ActiveMerchant::UniqueGateway.new.purchase(true)
265
265
  end
266
266
  ensure
267
- ActiveMerchant::UniqueGateway.statsd_remove_distribution :ssl_post, 'ActiveMerchant::Gateway.ssl_post'
267
+ ActiveMerchant::UniqueGateway.statsd_remove_distribution(:ssl_post, 'ActiveMerchant::Gateway.ssl_post')
268
268
  end
269
269
 
270
270
  def test_statsd_distribution_raises_without_a_provided_block
@@ -274,87 +274,99 @@ class StatsDInstrumentationTest < Minitest::Test
274
274
  end
275
275
 
276
276
  def test_statsd_distribution_with_method_receiving_block
277
- ActiveMerchant::Base.statsd_distribution :post_with_block, 'ActiveMerchant.Base.post_with_block'
277
+ ActiveMerchant::Base.statsd_distribution(:post_with_block, 'ActiveMerchant.Base.post_with_block')
278
278
 
279
279
  assert_statsd_distribution('ActiveMerchant.Base.post_with_block') do
280
- assert_equal 'block called', ActiveMerchant::Base.new.post_with_block { 'block called' }
280
+ assert_equal('block called', ActiveMerchant::Base.new.post_with_block { 'block called' })
281
281
  end
282
282
  ensure
283
- ActiveMerchant::Base.statsd_remove_distribution :post_with_block, 'ActiveMerchant.Base.post_with_block'
283
+ ActiveMerchant::Base.statsd_remove_distribution(:post_with_block, 'ActiveMerchant.Base.post_with_block')
284
284
  end
285
285
 
286
286
  def test_statsd_distribution_with_tags
287
- ActiveMerchant::UniqueGateway.statsd_distribution :ssl_post, 'ActiveMerchant.Gateway.ssl_post', tags: ['foo']
287
+ ActiveMerchant::UniqueGateway.statsd_distribution(:ssl_post, 'ActiveMerchant.Gateway.ssl_post', tags: ['foo'])
288
288
 
289
289
  assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post', tags: ['foo']) do
290
290
  ActiveMerchant::UniqueGateway.new.purchase(true)
291
291
  end
292
292
  ensure
293
- ActiveMerchant::UniqueGateway.statsd_remove_distribution :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
293
+ ActiveMerchant::UniqueGateway.statsd_remove_distribution(:ssl_post, 'ActiveMerchant.Gateway.ssl_post')
294
294
  end
295
295
 
296
296
  def test_statsd_distribution_with_sample_rate
297
- ActiveMerchant::UniqueGateway.statsd_distribution :ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1
297
+ ActiveMerchant::UniqueGateway.statsd_distribution(:ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1)
298
298
 
299
299
  assert_statsd_distribution('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.1) do
300
300
  ActiveMerchant::UniqueGateway.new.purchase(true)
301
301
  end
302
302
  ensure
303
- ActiveMerchant::UniqueGateway.statsd_remove_distribution :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
303
+ ActiveMerchant::UniqueGateway.statsd_remove_distribution(:ssl_post, 'ActiveMerchant.Gateway.ssl_post')
304
304
  end
305
305
 
306
306
  def test_instrumenting_class_method
307
- ActiveMerchant::Gateway.singleton_class.extend StatsD::Instrument
308
- ActiveMerchant::Gateway.singleton_class.statsd_count :sync, 'ActiveMerchant.Gateway.sync'
307
+ ActiveMerchant::Gateway.singleton_class.extend(StatsD::Instrument)
308
+ ActiveMerchant::Gateway.singleton_class.statsd_count(:sync, 'ActiveMerchant.Gateway.sync')
309
309
 
310
310
  assert_statsd_increment('ActiveMerchant.Gateway.sync') do
311
311
  ActiveMerchant::Gateway.sync
312
312
  end
313
313
  ensure
314
- ActiveMerchant::Gateway.singleton_class.statsd_remove_count :sync, 'ActiveMerchant.Gateway.sync'
314
+ ActiveMerchant::Gateway.singleton_class.statsd_remove_count(:sync, 'ActiveMerchant.Gateway.sync')
315
315
  end
316
316
 
317
317
  def test_statsd_count_with_tags
318
- ActiveMerchant::Gateway.singleton_class.extend StatsD::Instrument
319
- ActiveMerchant::Gateway.singleton_class.statsd_count :sync, 'ActiveMerchant.Gateway.sync', tags: { key: 'value' }
318
+ ActiveMerchant::Gateway.singleton_class.extend(StatsD::Instrument)
319
+ ActiveMerchant::Gateway.singleton_class.statsd_count(:sync, 'ActiveMerchant.Gateway.sync', tags: { key: 'value' })
320
320
 
321
321
  assert_statsd_increment('ActiveMerchant.Gateway.sync', tags: ['key:value']) do
322
322
  ActiveMerchant::Gateway.sync
323
323
  end
324
324
  ensure
325
- ActiveMerchant::Gateway.singleton_class.statsd_remove_count :sync, 'ActiveMerchant.Gateway.sync'
325
+ ActiveMerchant::Gateway.singleton_class.statsd_remove_count(:sync, 'ActiveMerchant.Gateway.sync')
326
326
  end
327
327
 
328
328
  def test_statsd_respects_global_prefix_changes
329
- StatsD.prefix = 'Foo'
330
- ActiveMerchant::Gateway.singleton_class.extend StatsD::Instrument
331
- ActiveMerchant::Gateway.singleton_class.statsd_count :sync, 'ActiveMerchant.Gateway.sync'
332
- StatsD.prefix = 'Quc'
333
-
334
- statsd_calls = capture_statsd_calls { ActiveMerchant::Gateway.sync }
335
- assert_equal 1, statsd_calls.length
336
- assert_equal "Quc.ActiveMerchant.Gateway.sync", statsd_calls.first.name
329
+ old_client = StatsD.singleton_client
330
+
331
+ StatsD.singleton_client = StatsD::Instrument::Client.new(prefix: 'Foo')
332
+ ActiveMerchant::Gateway.singleton_class.extend(StatsD::Instrument)
333
+ ActiveMerchant::Gateway.singleton_class.statsd_count(:sync, 'ActiveMerchant.Gateway.sync')
334
+ StatsD.singleton_client = StatsD::Instrument::Client.new(prefix: 'Quc')
335
+
336
+ datagrams = capture_statsd_calls { ActiveMerchant::Gateway.sync }
337
+ assert_equal(1, datagrams.length)
338
+ assert_equal("Quc.ActiveMerchant.Gateway.sync", datagrams.first.name)
337
339
  ensure
338
- StatsD.prefix = nil
339
- ActiveMerchant::Gateway.singleton_class.statsd_remove_count :sync, 'ActiveMerchant.Gateway.sync'
340
+ StatsD.singleton_client = old_client
341
+ ActiveMerchant::Gateway.singleton_class.statsd_remove_count(:sync, 'ActiveMerchant.Gateway.sync')
342
+ end
343
+
344
+ def test_statsd_count_with_injected_client
345
+ client = StatsD::Instrument::Client.new(prefix: 'prefix')
346
+
347
+ ActiveMerchant::Gateway.statsd_count(:ssl_post, 'ActiveMerchant.Gateway.ssl_post', client: client)
348
+ assert_statsd_increment('prefix.ActiveMerchant.Gateway.ssl_post', client: client) do
349
+ ActiveMerchant::Gateway.new.purchase(true)
350
+ end
351
+ ensure
352
+ ActiveMerchant::Gateway.statsd_remove_count(:ssl_post, 'ActiveMerchant.Gateway.ssl_post')
340
353
  end
341
354
 
342
355
  def test_statsd_macro_can_disable_prefix
343
- StatsD.prefix = 'Foo'
344
- ActiveMerchant::Gateway.singleton_class.extend StatsD::Instrument
345
- ActiveMerchant::Gateway.singleton_class.statsd_count_success :sync, 'ActiveMerchant.Gateway.sync', no_prefix: true
346
- StatsD.prefix = 'Quc'
347
-
348
- statsd_calls = capture_statsd_calls { ActiveMerchant::Gateway.sync }
349
- assert_equal 1, statsd_calls.length
350
- assert_equal "ActiveMerchant.Gateway.sync.success", statsd_calls.first.name
356
+ client = StatsD::Instrument::Client.new(prefix: 'foo')
357
+ ActiveMerchant::Gateway.singleton_class.extend(StatsD::Instrument)
358
+ ActiveMerchant::Gateway.singleton_class.statsd_count_success(:sync,
359
+ 'ActiveMerchant.Gateway.sync', no_prefix: true, client: client)
360
+
361
+ datagrams = client.capture { ActiveMerchant::Gateway.sync }
362
+ assert_equal(1, datagrams.length)
363
+ assert_equal("ActiveMerchant.Gateway.sync.success", datagrams.first.name)
351
364
  ensure
352
- StatsD.prefix = nil
353
- ActiveMerchant::Gateway.singleton_class.statsd_remove_count_success :sync, 'ActiveMerchant.Gateway.sync'
365
+ ActiveMerchant::Gateway.singleton_class.statsd_remove_count_success(:sync, 'ActiveMerchant.Gateway.sync')
354
366
  end
355
367
 
356
368
  def test_statsd_doesnt_change_method_scope_of_public_method
357
- assert_scope InstrumentedClass, :public_and_instrumented, :public
369
+ assert_scope(InstrumentedClass, :public_and_instrumented, :public)
358
370
 
359
371
  assert_statsd_increment('InstrumentedClass.public_and_instrumented') do
360
372
  InstrumentedClass.new.send(:public_and_instrumented)
@@ -362,7 +374,7 @@ class StatsDInstrumentationTest < Minitest::Test
362
374
  end
363
375
 
364
376
  def test_statsd_doesnt_change_method_scope_of_protected_method
365
- assert_scope InstrumentedClass, :protected_and_instrumented, :protected
377
+ assert_scope(InstrumentedClass, :protected_and_instrumented, :protected)
366
378
 
367
379
  assert_statsd_increment('InstrumentedClass.protected_and_instrumented') do
368
380
  InstrumentedClass.new.send(:protected_and_instrumented)
@@ -370,7 +382,7 @@ class StatsDInstrumentationTest < Minitest::Test
370
382
  end
371
383
 
372
384
  def test_statsd_doesnt_change_method_scope_of_private_method
373
- assert_scope InstrumentedClass, :private_and_instrumented, :private
385
+ assert_scope(InstrumentedClass, :private_and_instrumented, :private)
374
386
 
375
387
  assert_statsd_increment('InstrumentedClass.private_and_instrumented') do
376
388
  InstrumentedClass.new.send(:private_and_instrumented)
@@ -378,27 +390,27 @@ class StatsDInstrumentationTest < Minitest::Test
378
390
  end
379
391
 
380
392
  def test_statsd_doesnt_change_method_scope_on_removal_of_public_method
381
- assert_scope InstrumentedClass, :public_and_instrumented, :public
382
- InstrumentedClass.statsd_remove_count :public_and_instrumented, 'InstrumentedClass.public_and_instrumented'
383
- assert_scope InstrumentedClass, :public_and_instrumented, :public
393
+ assert_scope(InstrumentedClass, :public_and_instrumented, :public)
394
+ InstrumentedClass.statsd_remove_count(:public_and_instrumented, 'InstrumentedClass.public_and_instrumented')
395
+ assert_scope(InstrumentedClass, :public_and_instrumented, :public)
384
396
 
385
- InstrumentedClass.statsd_count :public_and_instrumented, 'InstrumentedClass.public_and_instrumented'
397
+ InstrumentedClass.statsd_count(:public_and_instrumented, 'InstrumentedClass.public_and_instrumented')
386
398
  end
387
399
 
388
400
  def test_statsd_doesnt_change_method_scope_on_removal_of_protected_method
389
- assert_scope InstrumentedClass, :protected_and_instrumented, :protected
390
- InstrumentedClass.statsd_remove_count :protected_and_instrumented, 'InstrumentedClass.protected_and_instrumented'
391
- assert_scope InstrumentedClass, :protected_and_instrumented, :protected
401
+ assert_scope(InstrumentedClass, :protected_and_instrumented, :protected)
402
+ InstrumentedClass.statsd_remove_count(:protected_and_instrumented, 'InstrumentedClass.protected_and_instrumented')
403
+ assert_scope(InstrumentedClass, :protected_and_instrumented, :protected)
392
404
 
393
- InstrumentedClass.statsd_count :protected_and_instrumented, 'InstrumentedClass.protected_and_instrumented'
405
+ InstrumentedClass.statsd_count(:protected_and_instrumented, 'InstrumentedClass.protected_and_instrumented')
394
406
  end
395
407
 
396
408
  def test_statsd_doesnt_change_method_scope_on_removal_of_private_method
397
- assert_scope InstrumentedClass, :private_and_instrumented, :private
398
- InstrumentedClass.statsd_remove_count :private_and_instrumented, 'InstrumentedClass.private_and_instrumented'
399
- assert_scope InstrumentedClass, :private_and_instrumented, :private
409
+ assert_scope(InstrumentedClass, :private_and_instrumented, :private)
410
+ InstrumentedClass.statsd_remove_count(:private_and_instrumented, 'InstrumentedClass.private_and_instrumented')
411
+ assert_scope(InstrumentedClass, :private_and_instrumented, :private)
400
412
 
401
- InstrumentedClass.statsd_count :private_and_instrumented, 'InstrumentedClass.private_and_instrumented'
413
+ InstrumentedClass.statsd_count(:private_and_instrumented, 'InstrumentedClass.private_and_instrumented')
402
414
  end
403
415
 
404
416
  def test_statsd_works_with_prepended_modules
@@ -417,43 +429,6 @@ class StatsDInstrumentationTest < Minitest::Test
417
429
  end
418
430
  end
419
431
 
420
- def test_statsd_measure_with_new_client
421
- old_client = StatsD.singleton_client
422
- StatsD.singleton_client = StatsD::Instrument::Client.new
423
-
424
- ActiveMerchant::UniqueGateway.statsd_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3
425
- assert_statsd_measure('ActiveMerchant.Gateway.ssl_post', sample_rate: 0.3) do
426
- ActiveMerchant::UniqueGateway.new.purchase(true)
427
- end
428
- ensure
429
- ActiveMerchant::UniqueGateway.statsd_remove_measure :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
430
- StatsD.singleton_client = old_client
431
- end
432
-
433
- def test_statsd_count_with_new_client
434
- old_client = StatsD.singleton_client
435
- StatsD.singleton_client = StatsD::Instrument::Client.new
436
-
437
- ActiveMerchant::Gateway.statsd_count :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
438
- assert_statsd_increment('ActiveMerchant.Gateway.ssl_post') do
439
- ActiveMerchant::Gateway.new.purchase(true)
440
- end
441
- ensure
442
- ActiveMerchant::Gateway.statsd_remove_count :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
443
- StatsD.singleton_client = old_client
444
- end
445
-
446
- def test_statsd_count_with_injected_client
447
- client = StatsD::Instrument::Client.new(prefix: 'prefix')
448
-
449
- ActiveMerchant::Gateway.statsd_count(:ssl_post, 'ActiveMerchant.Gateway.ssl_post', client: client)
450
- assert_statsd_increment('prefix.ActiveMerchant.Gateway.ssl_post', client: client) do
451
- ActiveMerchant::Gateway.new.purchase(true)
452
- end
453
- ensure
454
- ActiveMerchant::Gateway.statsd_remove_count :ssl_post, 'ActiveMerchant.Gateway.ssl_post'
455
- end
456
-
457
432
  private
458
433
 
459
434
  def assert_scope(klass, method, expected_scope)
@@ -465,6 +440,6 @@ class StatsDInstrumentationTest < Minitest::Test
465
440
  :public
466
441
  end
467
442
 
468
- assert_equal method_scope, expected_scope, "Expected method to be #{expected_scope}"
443
+ assert_equal(method_scope, expected_scope, "Expected method to be #{expected_scope}")
469
444
  end
470
445
  end