Sha256: 3a5b8c84ada4e95231b6ca5c9952d1198cce30f17ddbcde87bbf4f1a971925f2

Contents?: true

Size: 1.15 KB

Versions: 34

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require "test_helper"
require "statsd/instrument/rubocop"

module Rubocop
  class SingletonConfigurationTest < Minitest::Test
    include RubocopHelper

    def setup
      @cop = RuboCop::Cop::StatsD::SingletonConfiguration.new
    end

    def test_offense_statsd_backend
      assert_offense('StatsD.backend = "foo"')
      assert_offense("old_backend = StatsD.backend")
    end

    def test_offense_statsd_prefix
      assert_offense('StatsD.prefix = "foo"')
      assert_offense('"#{StatsD.prefix}.foo"')
    end

    def test_offense_statsd_default_tags
      assert_offense('StatsD.default_tags = ["foo"]')
      assert_offense("StatsD.default_tags.empty?")
    end

    def test_offense_statsd_default_sample_rate
      assert_offense("StatsD.default_sample_rate = 1.0")
      assert_offense("should_sample = StatsD.default_sample_rate > rand")
    end

    def test_no_offense_for_other_methods
      assert_no_offenses("StatsD.singleton_client = my_client")
      assert_no_offenses('StatsD.logger.info("foo")')
    end

    def test_no_offense_for_constant_reference
      assert_no_offenses("legacy_client = StatsD")
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
statsd-instrument-3.9.9 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.9.8 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.9.7 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.9.6 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.9.5 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.9.4 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.9.3 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.9.2 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.9.1 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.9.0 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.8.0 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.7.0 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.6.1 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.6.0 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.5.12 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.5.11 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.5.10 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.5.9 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.5.8 test/rubocop/singleton_configuration_test.rb
statsd-instrument-3.5.7 test/rubocop/singleton_configuration_test.rb