statsd-instrument 3.0.0.pre1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lint.yml +22 -0
  3. data/.github/workflows/tests.yml +31 -0
  4. data/.rubocop.yml +3 -13
  5. data/CHANGELOG.md +50 -0
  6. data/Gemfile +8 -2
  7. data/README.md +6 -3
  8. data/Rakefile +7 -7
  9. data/benchmark/send-metrics-to-dev-null-log +12 -11
  10. data/benchmark/send-metrics-to-local-udp-receiver +16 -15
  11. data/bin/rake +29 -0
  12. data/bin/rubocop +29 -0
  13. data/lib/statsd-instrument.rb +1 -1
  14. data/lib/statsd/instrument.rb +112 -145
  15. data/lib/statsd/instrument/assertions.rb +200 -208
  16. data/lib/statsd/instrument/batched_udp_sink.rb +154 -0
  17. data/lib/statsd/instrument/capture_sink.rb +23 -19
  18. data/lib/statsd/instrument/client.rb +410 -306
  19. data/lib/statsd/instrument/datagram.rb +69 -65
  20. data/lib/statsd/instrument/datagram_builder.rb +81 -77
  21. data/lib/statsd/instrument/dogstatsd_datagram.rb +76 -72
  22. data/lib/statsd/instrument/dogstatsd_datagram_builder.rb +68 -64
  23. data/lib/statsd/instrument/environment.rb +88 -77
  24. data/lib/statsd/instrument/expectation.rb +96 -96
  25. data/lib/statsd/instrument/helpers.rb +11 -7
  26. data/lib/statsd/instrument/log_sink.rb +20 -16
  27. data/lib/statsd/instrument/matchers.rb +93 -74
  28. data/lib/statsd/instrument/null_sink.rb +12 -8
  29. data/lib/statsd/instrument/railtie.rb +11 -7
  30. data/lib/statsd/instrument/rubocop.rb +8 -8
  31. data/lib/statsd/instrument/rubocop/measure_as_dist_argument.rb +1 -1
  32. data/lib/statsd/instrument/rubocop/metaprogramming_positional_arguments.rb +2 -2
  33. data/lib/statsd/instrument/rubocop/metric_prefix_argument.rb +1 -1
  34. data/lib/statsd/instrument/rubocop/metric_return_value.rb +2 -2
  35. data/lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb +1 -1
  36. data/lib/statsd/instrument/rubocop/positional_arguments.rb +4 -4
  37. data/lib/statsd/instrument/rubocop/singleton_configuration.rb +1 -1
  38. data/lib/statsd/instrument/rubocop/splat_arguments.rb +2 -2
  39. data/lib/statsd/instrument/statsd_datagram_builder.rb +12 -8
  40. data/lib/statsd/instrument/strict.rb +1 -6
  41. data/lib/statsd/instrument/udp_sink.rb +49 -47
  42. data/lib/statsd/instrument/version.rb +1 -1
  43. data/statsd-instrument.gemspec +4 -8
  44. data/test/assertions_test.rb +205 -161
  45. data/test/benchmark/clock_gettime.rb +1 -1
  46. data/test/benchmark/default_tags.rb +9 -9
  47. data/test/benchmark/metrics.rb +8 -8
  48. data/test/benchmark/tags.rb +4 -4
  49. data/test/capture_sink_test.rb +14 -14
  50. data/test/client_test.rb +96 -96
  51. data/test/datagram_builder_test.rb +55 -55
  52. data/test/datagram_test.rb +5 -5
  53. data/test/dogstatsd_datagram_builder_test.rb +37 -37
  54. data/test/environment_test.rb +30 -21
  55. data/test/helpers/rubocop_helper.rb +12 -9
  56. data/test/helpers_test.rb +15 -15
  57. data/test/integration_test.rb +7 -7
  58. data/test/log_sink_test.rb +4 -4
  59. data/test/matchers_test.rb +54 -54
  60. data/test/null_sink_test.rb +4 -4
  61. data/test/rubocop/measure_as_dist_argument_test.rb +2 -2
  62. data/test/rubocop/metaprogramming_positional_arguments_test.rb +2 -2
  63. data/test/rubocop/metric_prefix_argument_test.rb +2 -2
  64. data/test/rubocop/metric_return_value_test.rb +6 -6
  65. data/test/rubocop/metric_value_keyword_argument_test.rb +3 -3
  66. data/test/rubocop/positional_arguments_test.rb +12 -12
  67. data/test/rubocop/singleton_configuration_test.rb +8 -8
  68. data/test/rubocop/splat_arguments_test.rb +2 -2
  69. data/test/statsd_datagram_builder_test.rb +6 -6
  70. data/test/statsd_instrumentation_test.rb +122 -122
  71. data/test/statsd_test.rb +69 -67
  72. data/test/test_helper.rb +19 -10
  73. data/test/udp_sink_test.rb +122 -50
  74. metadata +12 -92
  75. data/.github/workflows/ci.yml +0 -56
  76. data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
@@ -1,16 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  class IntegrationTest < Minitest::Test
6
6
  def setup
7
7
  @server = UDPSocket.new
8
- @server.bind('localhost', 0)
8
+ @server.bind("localhost", 0)
9
9
 
10
10
  @env = StatsD::Instrument::Environment.new(
11
- 'STATSD_ADDR' => "#{@server.addr[2]}:#{@server.addr[1]}",
12
- 'STATSD_IMPLEMENTATION' => 'dogstatsd',
13
- 'STATSD_ENV' => 'production',
11
+ "STATSD_ADDR" => "#{@server.addr[2]}:#{@server.addr[1]}",
12
+ "STATSD_IMPLEMENTATION" => "dogstatsd",
13
+ "STATSD_ENV" => "production",
14
14
  )
15
15
 
16
16
  @old_client = StatsD.singleton_client
@@ -23,7 +23,7 @@ class IntegrationTest < Minitest::Test
23
23
  end
24
24
 
25
25
  def test_live_local_udp_socket
26
- StatsD.increment('counter')
27
- assert_equal "counter:1|c", @server.recvfrom(100).first
26
+ StatsD.increment("counter")
27
+ assert_equal("counter:1|c", @server.recvfrom(100).first)
28
28
  end
29
29
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  class LogSinkTest < Minitest::Test
6
6
  def test_log_sink
@@ -10,9 +10,9 @@ class LogSinkTest < Minitest::Test
10
10
  end
11
11
 
12
12
  log_sink = StatsD::Instrument::LogSink.new(logger)
13
- log_sink << 'foo:1|c' << 'bar:1|c'
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
@@ -1,116 +1,116 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
4
- require 'statsd/instrument/matchers'
3
+ require "test_helper"
4
+ 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
- matcher_1 = StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['a'])
19
- matcher_2 = StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['b'])
18
+ matcher_1 = StatsD::Instrument::Matchers::Increment.new(:c, "counter", tags: ["a"])
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 {
22
- StatsD.increment('counter', tags: ['a'])
23
- StatsD.increment('counter', tags: ['b'])
24
- }
21
+ assert(RSpec::Matchers::BuiltIn::Compound::And.new(matcher_1, matcher_2).matches?(lambda {
22
+ StatsD.increment("counter", tags: ["a"])
23
+ StatsD.increment("counter", tags: ["b"])
24
+ }))
25
25
  end
26
26
 
27
27
  def test_statsd_increment_compound_not_matched
28
- matcher_1 = StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['a'])
29
- matcher_2 = StatsD::Instrument::Matchers::Increment.new(:c, 'counter', tags: ['b'])
28
+ matcher_1 = StatsD::Instrument::Matchers::Increment.new(:c, "counter", tags: ["a"])
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 {
32
- StatsD.increment('counter', tags: ['a'])
33
- StatsD.increment('counter', tags: ['a'])
34
- }
31
+ refute(RSpec::Matchers::BuiltIn::Compound::And.new(matcher_1, matcher_2).matches?(lambda {
32
+ StatsD.increment("counter", tags: ["a"])
33
+ StatsD.increment("counter", tags: ["a"])
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 {
64
- StatsD.increment('counter', 2)
65
- StatsD.increment('counter', 1)
66
- })
63
+ assert(StatsD::Instrument::Matchers::Increment.new(:c, "counter", value: 1).matches?(lambda {
64
+ StatsD.increment("counter", 2)
65
+ StatsD.increment("counter", 1)
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 {
71
- StatsD.increment('counter', 2)
72
- StatsD.increment('counter', 3)
73
- })
70
+ refute(StatsD::Instrument::Matchers::Increment.new(:c, "counter", value: 1).matches?(lambda {
71
+ StatsD.increment("counter", 2)
72
+ StatsD.increment("counter", 3)
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 {
93
- StatsD.increment('counter', 1)
94
- StatsD.increment('counter', 1)
95
- })
92
+ assert(StatsD::Instrument::Matchers::Increment.new(:c, "counter", times: 2, value: 1).matches?(lambda {
93
+ StatsD.increment("counter", 1)
94
+ StatsD.increment("counter", 1)
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 {
100
- StatsD.increment('counter', 1)
101
- StatsD.increment('counter', 2)
102
- })
99
+ refute(StatsD::Instrument::Matchers::Increment.new(:c, "counter", times: 2, value: 1).matches?(lambda {
100
+ StatsD.increment("counter", 1)
101
+ StatsD.increment("counter", 2)
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
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  class NullSinkTest < Minitest::Test
6
6
  def test_null_sink
7
7
  null_sink = StatsD::Instrument::NullSink.new
8
- null_sink << 'foo:1|c' << 'bar:1|c'
8
+ null_sink << "foo:1|c" << "bar:1|c"
9
9
  pass # We don't have anything to assert, except that no exception was raised
10
10
  end
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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
4
- require 'statsd/instrument/rubocop'
3
+ require "test_helper"
4
+ require "statsd/instrument/rubocop"
5
5
 
6
6
  module Rubocop
7
7
  class MeasureAsDistArgumentTest < Minitest::Test
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
4
- require 'statsd/instrument/rubocop'
3
+ require "test_helper"
4
+ require "statsd/instrument/rubocop"
5
5
 
6
6
  module Rubocop
7
7
  class MetaprogrammingPositionalArgumentsTest < Minitest::Test
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
4
- require 'statsd/instrument/rubocop'
3
+ require "test_helper"
4
+ require "statsd/instrument/rubocop"
5
5
 
6
6
  module Rubocop
7
7
  class MetricPrefixArgumentTest < Minitest::Test
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
4
- require 'statsd/instrument/rubocop'
3
+ require "test_helper"
4
+ require "statsd/instrument/rubocop"
5
5
 
6
6
  module Rubocop
7
7
  class MetricReturnValueTest < Minitest::Test
@@ -12,7 +12,7 @@ module Rubocop
12
12
  end
13
13
 
14
14
  def test_ok_for_non_metric_method
15
- assert_no_offenses('backend = StatsD.backend')
15
+ assert_no_offenses("backend = StatsD.backend")
16
16
  end
17
17
 
18
18
  def test_ok_as_naked_statement
@@ -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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
4
- require 'statsd/instrument/rubocop'
3
+ require "test_helper"
4
+ require "statsd/instrument/rubocop"
5
5
 
6
6
  module Rubocop
7
7
  class MetricValueKeywordArgumentTest < Minitest::Test
@@ -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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
4
- require 'statsd/instrument/rubocop'
3
+ require "test_helper"
4
+ require "statsd/instrument/rubocop"
5
5
 
6
6
  module Rubocop
7
7
  class PositionalArgumentsTest < Minitest::Test
@@ -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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
4
- require 'statsd/instrument/rubocop'
3
+ require "test_helper"
4
+ require "statsd/instrument/rubocop"
5
5
 
6
6
  module Rubocop
7
7
  class SingletonConfigurationTest < Minitest::Test
@@ -13,7 +13,7 @@ module Rubocop
13
13
 
14
14
  def test_offense_statsd_backend
15
15
  assert_offense('StatsD.backend = "foo"')
16
- assert_offense('old_backend = StatsD.backend')
16
+ assert_offense("old_backend = StatsD.backend")
17
17
  end
18
18
 
19
19
  def test_offense_statsd_prefix
@@ -23,21 +23,21 @@ module Rubocop
23
23
 
24
24
  def test_offense_statsd_default_tags
25
25
  assert_offense('StatsD.default_tags = ["foo"]')
26
- assert_offense('StatsD.default_tags.empty?')
26
+ assert_offense("StatsD.default_tags.empty?")
27
27
  end
28
28
 
29
29
  def test_offense_statsd_default_sample_rate
30
- assert_offense('StatsD.default_sample_rate = 1.0')
31
- assert_offense('should_sample = StatsD.default_sample_rate > rand')
30
+ assert_offense("StatsD.default_sample_rate = 1.0")
31
+ assert_offense("should_sample = StatsD.default_sample_rate > rand")
32
32
  end
33
33
 
34
34
  def test_no_offense_for_other_methods
35
- assert_no_offenses('StatsD.singleton_client = my_client')
35
+ assert_no_offenses("StatsD.singleton_client = my_client")
36
36
  assert_no_offenses('StatsD.logger.info("foo")')
37
37
  end
38
38
 
39
39
  def test_no_offense_for_constant_reference
40
- assert_no_offenses('legacy_client = StatsD')
40
+ assert_no_offenses("legacy_client = StatsD")
41
41
  end
42
42
  end
43
43
  end