statsd-instrument 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +3 -3
  3. data/.rubocop.yml +3 -13
  4. data/CHANGELOG.md +6 -0
  5. data/Gemfile +8 -0
  6. data/README.md +2 -2
  7. data/Rakefile +1 -1
  8. data/bin/rake +29 -0
  9. data/bin/rubocop +29 -0
  10. data/lib/statsd/instrument.rb +4 -1
  11. data/lib/statsd/instrument/assertions.rb +200 -196
  12. data/lib/statsd/instrument/capture_sink.rb +23 -19
  13. data/lib/statsd/instrument/client.rb +414 -410
  14. data/lib/statsd/instrument/datagram.rb +69 -65
  15. data/lib/statsd/instrument/datagram_builder.rb +81 -77
  16. data/lib/statsd/instrument/dogstatsd_datagram.rb +76 -72
  17. data/lib/statsd/instrument/dogstatsd_datagram_builder.rb +68 -64
  18. data/lib/statsd/instrument/environment.rb +80 -77
  19. data/lib/statsd/instrument/expectation.rb +96 -92
  20. data/lib/statsd/instrument/helpers.rb +11 -7
  21. data/lib/statsd/instrument/log_sink.rb +20 -16
  22. data/lib/statsd/instrument/matchers.rb +86 -70
  23. data/lib/statsd/instrument/null_sink.rb +12 -8
  24. data/lib/statsd/instrument/railtie.rb +11 -7
  25. data/lib/statsd/instrument/statsd_datagram_builder.rb +12 -8
  26. data/lib/statsd/instrument/udp_sink.rb +50 -46
  27. data/lib/statsd/instrument/version.rb +1 -1
  28. data/statsd-instrument.gemspec +2 -8
  29. data/test/assertions_test.rb +12 -12
  30. data/test/capture_sink_test.rb +8 -8
  31. data/test/client_test.rb +54 -54
  32. data/test/datagram_builder_test.rb +29 -29
  33. data/test/datagram_test.rb +1 -1
  34. data/test/dogstatsd_datagram_builder_test.rb +28 -28
  35. data/test/environment_test.rb +9 -9
  36. data/test/helpers/rubocop_helper.rb +9 -6
  37. data/test/helpers_test.rb +5 -5
  38. data/test/integration_test.rb +1 -1
  39. data/test/log_sink_test.rb +2 -2
  40. data/test/matchers_test.rb +36 -36
  41. data/test/null_sink_test.rb +2 -2
  42. data/test/rubocop/metric_return_value_test.rb +3 -3
  43. data/test/rubocop/positional_arguments_test.rb +10 -10
  44. data/test/statsd_instrumentation_test.rb +66 -66
  45. data/test/statsd_test.rb +44 -44
  46. data/test/test_helper.rb +6 -4
  47. data/test/udp_sink_test.rb +8 -8
  48. metadata +7 -103
  49. data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
@@ -9,6 +9,6 @@ class DatagramTest < Minitest::Test
9
9
  'multi_currency:false,fulfillment_orders_beta_enabled:false'
10
10
 
11
11
  parsed = StatsD::Instrument::Datagram.new(datagram)
12
- assert_includes parsed.tags, 'code_source:NilController#NilAction'
12
+ assert_includes(parsed.tags, 'code_source:NilController#NilAction')
13
13
  end
14
14
  end
@@ -13,55 +13,55 @@ class DogStatsDDatagramBuilderTest < Minitest::Test
13
13
 
14
14
  def test_simple_service_check
15
15
  datagram = @datagram_builder._sc('service', :ok)
16
- assert_equal '_sc|service|0', datagram
16
+ assert_equal('_sc|service|0', datagram)
17
17
  parsed_datagram = StatsD::Instrument::DogStatsDDatagramBuilder.datagram_class.new(datagram)
18
- assert_equal :_sc, parsed_datagram.type
19
- assert_equal 'service', parsed_datagram.name
20
- assert_equal 0, parsed_datagram.value
18
+ assert_equal(:_sc, parsed_datagram.type)
19
+ assert_equal('service', parsed_datagram.name)
20
+ assert_equal(0, parsed_datagram.value)
21
21
  end
22
22
 
23
23
  def test_complex_service_check
24
24
  datagram = @datagram_builder._sc('service', :warning, timestamp: Time.parse('2019-09-30T04:22:12Z'),
25
25
  hostname: 'localhost', tags: { foo: 'bar|baz' }, message: 'blah')
26
- assert_equal "_sc|service|1|h:localhost|d:1569817332|#foo:barbaz|m:blah", datagram
26
+ assert_equal("_sc|service|1|h:localhost|d:1569817332|#foo:barbaz|m:blah", datagram)
27
27
 
28
28
  parsed_datagram = StatsD::Instrument::DogStatsDDatagramBuilder.datagram_class.new(datagram)
29
- assert_equal :_sc, parsed_datagram.type
30
- assert_equal 'service', parsed_datagram.name
31
- assert_equal 1, parsed_datagram.value
32
- assert_equal 'localhost', parsed_datagram.hostname
33
- assert_equal Time.parse('2019-09-30T04:22:12Z'), parsed_datagram.timestamp
34
- assert_equal ["foo:barbaz"], parsed_datagram.tags
35
- assert_equal 'blah', parsed_datagram.message
29
+ assert_equal(:_sc, parsed_datagram.type)
30
+ assert_equal('service', parsed_datagram.name)
31
+ assert_equal(1, parsed_datagram.value)
32
+ assert_equal('localhost', parsed_datagram.hostname)
33
+ assert_equal(Time.parse('2019-09-30T04:22:12Z'), parsed_datagram.timestamp)
34
+ assert_equal(["foo:barbaz"], parsed_datagram.tags)
35
+ assert_equal('blah', parsed_datagram.message)
36
36
  end
37
37
 
38
38
  def test_simple_event
39
39
  datagram = @datagram_builder._e('hello', "world")
40
- assert_equal '_e{5,5}:hello|world', datagram
40
+ assert_equal('_e{5,5}:hello|world', datagram)
41
41
 
42
42
  parsed_datagram = StatsD::Instrument::DogStatsDDatagramBuilder.datagram_class.new(datagram)
43
- assert_equal :_e, parsed_datagram.type
44
- assert_equal 'hello', parsed_datagram.name
45
- assert_equal 'world', parsed_datagram.value
43
+ assert_equal(:_e, parsed_datagram.type)
44
+ assert_equal('hello', parsed_datagram.name)
45
+ assert_equal('world', parsed_datagram.value)
46
46
  end
47
47
 
48
48
  def test_complex_event
49
49
  datagram = @datagram_builder._e("testing", "with\nnewline", timestamp: Time.parse('2019-09-30T04:22:12Z'),
50
50
  hostname: 'localhost', aggregation_key: 'my-key', priority: 'low', source_type_name: 'source',
51
51
  alert_type: 'success', tags: { foo: 'bar|baz' })
52
- assert_equal '_e{7,13}:testing|with\\nnewline|h:localhost|d:1569817332|k:my-key|' \
53
- 'p:low|s:source|t:success|#foo:barbaz', datagram
52
+ assert_equal('_e{7,13}:testing|with\\nnewline|h:localhost|d:1569817332|k:my-key|' \
53
+ 'p:low|s:source|t:success|#foo:barbaz', datagram)
54
54
 
55
55
  parsed_datagram = StatsD::Instrument::DogStatsDDatagramBuilder.datagram_class.new(datagram)
56
- assert_equal :_e, parsed_datagram.type
57
- assert_equal 'testing', parsed_datagram.name
58
- assert_equal "with\nnewline", parsed_datagram.value
59
- assert_equal 'localhost', parsed_datagram.hostname
60
- assert_equal Time.parse('2019-09-30T04:22:12Z'), parsed_datagram.timestamp
61
- assert_equal ["foo:barbaz"], parsed_datagram.tags
62
- assert_equal "my-key", parsed_datagram.aggregation_key
63
- assert_equal "low", parsed_datagram.priority
64
- assert_equal "source", parsed_datagram.source_type_name
65
- assert_equal "success", parsed_datagram.alert_type
56
+ assert_equal(:_e, parsed_datagram.type)
57
+ assert_equal('testing', parsed_datagram.name)
58
+ assert_equal("with\nnewline", parsed_datagram.value)
59
+ assert_equal('localhost', parsed_datagram.hostname)
60
+ assert_equal(Time.parse('2019-09-30T04:22:12Z'), parsed_datagram.timestamp)
61
+ assert_equal(["foo:barbaz"], parsed_datagram.tags)
62
+ assert_equal("my-key", parsed_datagram.aggregation_key)
63
+ assert_equal("low", parsed_datagram.priority)
64
+ assert_equal("source", parsed_datagram.source_type_name)
65
+ assert_equal("success", parsed_datagram.alert_type)
66
66
  end
67
67
  end
@@ -11,48 +11,48 @@ class EnvironmentTest < Minitest::Test
11
11
  'RACK_ENV' => 'set_from_RACK_ENV',
12
12
  'ENV' => 'set_from_ENV',
13
13
  )
14
- assert_equal 'set_from_STATSD_ENV', env.environment
14
+ assert_equal('set_from_STATSD_ENV', env.environment)
15
15
  end
16
16
 
17
17
  def test_environment_uses_env_when_rails_does_not_respond_to_env_and_statsd_env_is_not_set
18
18
  env = StatsD::Instrument::Environment.new(
19
19
  'ENV' => 'set_from_ENV',
20
20
  )
21
- assert_equal 'set_from_ENV', env.environment
21
+ assert_equal('set_from_ENV', env.environment)
22
22
  end
23
23
 
24
24
  def test_environment_uses_rails_env_when_rails_is_available
25
25
  Rails.stubs(:env).returns('production')
26
- assert_equal 'production', StatsD::Instrument::Environment.environment
26
+ assert_equal('production', StatsD::Instrument::Environment.environment)
27
27
  end
28
28
 
29
29
  def test_environment_defaults_to_development
30
30
  env = StatsD::Instrument::Environment.new({})
31
- assert_equal 'development', env.environment
31
+ assert_equal('development', env.environment)
32
32
  end
33
33
 
34
34
  def test_client_returns_client_instance
35
35
  env = StatsD::Instrument::Environment.new({})
36
- assert_kind_of StatsD::Instrument::Client, env.client
36
+ assert_kind_of(StatsD::Instrument::Client, env.client)
37
37
  end
38
38
 
39
39
  def test_client_from_env_uses_log_sink_in_development_environment
40
40
  env = StatsD::Instrument::Environment.new('STATSD_USE_NEW_CLIENT' => '1', 'STATSD_ENV' => 'development')
41
- assert_kind_of StatsD::Instrument::LogSink, env.client.sink
41
+ assert_kind_of(StatsD::Instrument::LogSink, env.client.sink)
42
42
  end
43
43
 
44
44
  def test_client_from_env_uses_null_sink_in_test_environment
45
45
  env = StatsD::Instrument::Environment.new('STATSD_USE_NEW_CLIENT' => '1', 'STATSD_ENV' => 'test')
46
- assert_kind_of StatsD::Instrument::NullSink, env.client.sink
46
+ assert_kind_of(StatsD::Instrument::NullSink, env.client.sink)
47
47
  end
48
48
 
49
49
  def test_client_from_env_uses_udp_sink_in_staging_environment
50
50
  env = StatsD::Instrument::Environment.new('STATSD_USE_NEW_CLIENT' => '1', 'STATSD_ENV' => 'staging')
51
- assert_kind_of StatsD::Instrument::UDPSink, env.client.sink
51
+ assert_kind_of(StatsD::Instrument::UDPSink, env.client.sink)
52
52
  end
53
53
 
54
54
  def test_client_from_env_uses_udp_sink_in_production_environment
55
55
  env = StatsD::Instrument::Environment.new('STATSD_USE_NEW_CLIENT' => '1', 'STATSD_ENV' => 'production')
56
- assert_kind_of StatsD::Instrument::UDPSink, env.client.sink
56
+ assert_kind_of(StatsD::Instrument::UDPSink, env.client.sink)
57
57
  end
58
58
  end
@@ -7,19 +7,22 @@ module RubocopHelper
7
7
 
8
8
  private
9
9
 
10
+ RUBY_VERSION = 2.5
11
+ private_constant :RUBY_VERSION
12
+
10
13
  def assert_no_offenses(source)
11
- investigate(RuboCop::ProcessedSource.new(source, 2.3, nil))
12
- assert_predicate cop.offenses, :empty?, "Did not expect Rubocop to find offenses"
14
+ investigate(RuboCop::ProcessedSource.new(source, RUBY_VERSION, nil))
15
+ assert_predicate(cop.offenses, :empty?, "Did not expect Rubocop to find offenses")
13
16
  end
14
17
 
15
18
  def assert_offense(source)
16
- investigate(RuboCop::ProcessedSource.new(source, 2.3, nil))
17
- refute_predicate cop.offenses, :empty?, "Expected Rubocop to find offenses"
19
+ investigate(RuboCop::ProcessedSource.new(source, RUBY_VERSION, nil))
20
+ refute_predicate(cop.offenses, :empty?, "Expected Rubocop to find offenses")
18
21
  end
19
22
 
20
23
  def assert_no_autocorrect(source)
21
24
  corrected = autocorrect_source(source)
22
- assert_equal source, corrected
25
+ assert_equal(source, corrected)
23
26
  end
24
27
 
25
28
  def autocorrect_source(source)
@@ -27,7 +30,7 @@ module RubocopHelper
27
30
  RuboCop::Formatter::DisabledConfigFormatter.detected_styles = {}
28
31
  cop.instance_variable_get(:@options)[:auto_correct] = true
29
32
 
30
- processed_source = RuboCop::ProcessedSource.new(source, 2.3, nil)
33
+ processed_source = RuboCop::ProcessedSource.new(source, RUBY_VERSION, nil)
31
34
  investigate(processed_source)
32
35
 
33
36
  corrector = RuboCop::Cop::Corrector.new(processed_source.buffer, cop.corrections)
@@ -17,10 +17,10 @@ class HelpersTest < Minitest::Test
17
17
  end
18
18
  StatsD.gauge('gauge', 15)
19
19
 
20
- assert_equal 2, metrics.length
21
- assert_equal 'counter', metrics[0].name
22
- assert_equal 'gauge', metrics[1].name
23
- assert_equal 12, metrics[1].value
20
+ assert_equal(2, metrics.length)
21
+ assert_equal('counter', metrics[0].name)
22
+ assert_equal('gauge', metrics[1].name)
23
+ assert_equal(12, metrics[1].value)
24
24
  end
25
25
 
26
26
  def test_capture_metrics_with_new_client
@@ -34,7 +34,7 @@ class HelpersTest < Minitest::Test
34
34
  end
35
35
  StatsD.gauge('gauge', 15)
36
36
 
37
- assert_equal 2, metrics.length
37
+ assert_equal(2, metrics.length)
38
38
 
39
39
  ensure
40
40
  StatsD.singleton_client = @old_client
@@ -24,6 +24,6 @@ class IntegrationTest < Minitest::Test
24
24
 
25
25
  def test_live_local_udp_socket
26
26
  StatsD.increment('counter')
27
- assert_equal "counter:1|c", @server.recvfrom(100).first
27
+ assert_equal("counter:1|c", @server.recvfrom(100).first)
28
28
  end
29
29
  end
@@ -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
@@ -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