Sha256: 23768c6110935f7e2e4ecf00d217bbb4619732ae691537834450e27170fff4db

Contents?: true

Size: 1.15 KB

Versions: 11

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require 'test_helper'
require 'statsd/instrument/rubocop'

module Rubocop
  class MetricValueKeywordArgumentTest < Minitest::Test
    include RubocopHelper

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

    def test_ok_for_method_without_arguments
      assert_no_offenses("StatsD.increment")
    end

    def test_ok_for_non_metric_method
      assert_no_offenses("StatsD.backend('foo', value: 1)")
    end

    def test_ok_with_no_keywords
      assert_no_offenses("StatsD.increment('foo', 1)")
    end

    def test_ok_with_no_matching_keyword
      assert_no_offenses("StatsD.increment('foo', 1, tags: ['foo'])")
      assert_no_offenses("StatsD.increment('foo', 1, tags: { value: 'bar' })")
    end

    def test_offense_with_value_keyword
      assert_offense("StatsD.increment('foo', value: 1)")
      assert_offense("StatsD.increment('foo', :value => 1)")
      assert_offense("StatsD.increment('foo', 'value' => 1)")
      assert_offense("StatsD.increment('foo', sample_rate: 0.1, value: 1, tags: ['foo'])")
      assert_offense("StatsD.increment('foo', value: 1, &block)")
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
statsd-instrument-3.0.1 test/rubocop/metric_value_keyword_argument_test.rb
statsd-instrument-3.0.0 test/rubocop/metric_value_keyword_argument_test.rb
statsd-instrument-3.0.0.pre2 test/rubocop/metric_value_keyword_argument_test.rb
statsd-instrument-2.9.2 test/rubocop/metric_value_keyword_argument_test.rb
statsd-instrument-3.0.0.pre1 test/rubocop/metric_value_keyword_argument_test.rb
statsd-instrument-2.9.1 test/rubocop/metric_value_keyword_argument_test.rb
statsd-instrument-2.9.0 test/rubocop/metric_value_keyword_argument_test.rb
statsd-instrument-2.8.0 test/rubocop/metric_value_keyword_argument_test.rb
statsd-instrument-2.7.1 test/rubocop/metric_value_keyword_argument_test.rb
statsd-instrument-2.7.0 test/rubocop/metric_value_keyword_argument_test.rb
statsd-instrument-2.6.0 test/rubocop/metric_value_keyword_argument_test.rb