Module: Datadog::CI::Contrib::RSpec::AnonymousExampleName

Defined in:
lib/datadog/ci/contrib/rspec/anonymous_example_name.rb

Constant Summary collapse

ISEQ_SIMPLE_DATA_FORMAT =
"YARVInstructionSequence/SimpleDataFormat"
SELF_VALUE =
:__datadog_rspec_self__
EMPTY_ARGUMENTS =
[].freeze
MINIMUM_RUBY_VERSION =
Gem::Version.new("3.2")
EXPECTATION_METHODS =
{
  to: "is expected to",
  not_to: "is expected not to",
  to_not: "is expected not to"
}.freeze
SHOULD_METHODS =
{
  should: "is expected to",
  should_not: "is expected not to"
}.freeze
OPERATOR_METHODS =
%i[== != === =~ !~ < <= > >= + - * / %].each_with_object({}) { |method_name, methods|
  methods[method_name] = true
}.freeze
MATCHER_CHAIN_METHODS =
%i[
  and
  at_least
  at_most
  by
  by_at_least
  by_at_most
  exactly
  from
  of
  once
  or
  times
  to
  twice
  with
  within
].each_with_object({}) { |method_name, methods|
  methods[method_name] = true
}.freeze
PRETTY_MATCHER_PREFIXES =
%w[be_ have_ raise_ respond_ yield_ start_ end_].freeze
PRETTY_MATCHER_METHODS =
%i[
  be
  change
  contain_exactly
  eq
  eql
  equal
  exist
  include
  match
  output
  raise_error
  satisfy
  throw_symbol
].each_with_object({}) { |method_name, methods|
  methods[method_name] = true
}.freeze
MAX_RENDERED_VALUE_LENGTH =
80
MAX_RENDERED_NAME_LENGTH =
180

Class Method Summary collapse

Class Method Details

.call(target) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/datadog/ci/contrib/rspec/anonymous_example_name.rb', line 74

def self.call(target)
  return nil if target.nil?
  return nil unless supported?

  iseq = iseq_for(target)
  return nil unless iseq

  rendered_name = render_iseq(iseq)
  trim(rendered_name, MAX_RENDERED_NAME_LENGTH) if rendered_name
rescue => e
  warn_anonymous_example_name_error(e)
  nil
end

.supported?Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
# File 'lib/datadog/ci/contrib/rspec/anonymous_example_name.rb', line 67

def self.supported?
  return false unless defined?(RubyVM::InstructionSequence)
  return false unless RUBY_ENGINE == "ruby"

  Gem::Version.new(RUBY_VERSION) >= MINIMUM_RUBY_VERSION
end