Class: BrainzLab::Testing::MetricExpectation

Inherits:
Object
  • Object
show all
Defined in:
lib/brainzlab/testing/helpers.rb

Overview

Fluent expectation builder for metrics

Instance Method Summary collapse

Constructor Details

#initialize(type, name, store) ⇒ MetricExpectation

Returns a new instance of MetricExpectation.



507
508
509
510
511
512
513
# File 'lib/brainzlab/testing/helpers.rb', line 507

def initialize(type, name, store)
  @type = type.to_sym
  @name = name.to_s
  @store = store
  @expected_value = nil
  @expected_tags = nil
end

Instance Method Details

#failure_messageObject



545
546
547
548
549
550
551
# File 'lib/brainzlab/testing/helpers.rb', line 545

def failure_message
  parts = ["expected metric #{@type}('#{@name}')"]
  parts << "with value #{@expected_value.inspect}" if @expected_value
  parts << "with tags #{@expected_tags.inspect}" if @expected_tags
  parts << ", but got: #{@store.metrics_named(@name).inspect}"
  parts.join
end

#failure_message_when_negatedObject



553
554
555
# File 'lib/brainzlab/testing/helpers.rb', line 553

def failure_message_when_negated
  "expected metric #{@type}('#{@name}') not to be recorded, but it was"
end

#satisfied?Boolean Also known as: matches?

Check if the expectation is satisfied

Returns:

  • (Boolean)


539
540
541
# File 'lib/brainzlab/testing/helpers.rb', line 539

def satisfied?
  @store.metric_recorded?(@type, @name, value: @expected_value, tags: @expected_tags)
end

#with_tags(tags) ⇒ self

Specify expected tags

Parameters:

  • tags (Hash)

    Tags to match

Returns:

  • (self)


530
531
532
533
# File 'lib/brainzlab/testing/helpers.rb', line 530

def with_tags(tags)
  @expected_tags = tags
  self
end

#with_value(value) ⇒ self

Specify expected value

Parameters:

  • value (Numeric)

    Value to match

Returns:

  • (self)


520
521
522
523
# File 'lib/brainzlab/testing/helpers.rb', line 520

def with_value(value)
  @expected_value = value
  self
end