Skip to content

Commit

Permalink
use ruby 2.7 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jan 29, 2024
1 parent 8394cdb commit b711660
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 64 deletions.
4 changes: 2 additions & 2 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ruby_version: 2.1
ruby_version: 2.7
format: progress

ignore:
- 'gemfiles/**/*'
- 'tasks/**/*'
- 'yard/**/*'
- 'yard/**/*'
8 changes: 0 additions & 8 deletions .standard_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
ignore:
- lib/datadog/ci/test_visibility/serializers/base.rb:
- Style/HashExcept
- lib/datadog/ci/contrib/minitest/integration.rb:
- Style/SafeNavigation
- lib/datadog/ci/contrib/cucumber/integration.rb:
- Style/SafeNavigation
- lib/datadog/ci/contrib/rspec/integration.rb:
- Style/SafeNavigation
- lib/datadog/ci/ext/environment.rb:
- Style/SafeNavigation
- spec/support/log_helpers.rb:
- Performance/UnfreezeString
- Appraisals:
Expand Down
19 changes: 6 additions & 13 deletions lib/datadog/ci/contrib/cucumber/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def on_test_case_started(event)
service: configuration[:service_name]
)

if test_span && (parameters = extract_parameters_hash(event.test_case))
test_span.set_parameters(parameters)
if (parameters = extract_parameters_hash(event.test_case))
test_span&.set_parameters(parameters)
end
end

Expand Down Expand Up @@ -100,9 +100,8 @@ def on_test_step_finished(event)
def test_suite_name(test_case)
feature = if test_case.respond_to?(:feature)
test_case.feature
elsif @ast_lookup
gherkin_doc = @ast_lookup.gherkin_document(test_case.location.file)
gherkin_doc.feature if gherkin_doc
else
@ast_lookup&.gherkin_document(test_case.location.file)&.feature
end

if feature
Expand Down Expand Up @@ -150,19 +149,13 @@ def start_test_suite(test_suite_name)
end

def finish_current_test_suite
test_suite = @current_test_suite
return unless test_suite

test_suite.finish
@current_test_suite&.finish

@current_test_suite = nil
end

def same_test_suite_as_current?(test_suite_name)
test_suite = @current_test_suite
return false unless test_suite

test_suite.name == test_suite_name
@current_test_suite&.name == test_suite_name
end

def extract_parameters_hash(test_case)
Expand Down
3 changes: 1 addition & 2 deletions lib/datadog/ci/contrib/cucumber/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class Integration
register_as :cucumber

def self.version
Gem.loaded_specs["cucumber"] \
&& Gem.loaded_specs["cucumber"].version
Gem.loaded_specs["cucumber"]&.version
end

def self.loaded?
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/contrib/minitest/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Integration
register_as :minitest

def self.version
Gem.loaded_specs["minitest"] && Gem.loaded_specs["minitest"].version
Gem.loaded_specs["minitest"]&.version
end

def self.loaded?
Expand Down
38 changes: 18 additions & 20 deletions lib/datadog/ci/contrib/rspec/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,26 @@ def run(*)
) do |test_span|
result = super

if test_span
test_span.set_parameters({}, {"scoped_id" => metadata[:scoped_id]})

case execution_result.status
when :passed
test_span.passed!
test_suite_span.passed! if test_suite_span
when :failed
test_span.failed!(exception: execution_result.exception)
test_suite_span.failed! if test_suite_span
else
# :pending or nil
test_span.skipped!(
reason: execution_result.pending_message,
exception: execution_result.pending_exception
)

test_suite_span.skipped! if test_suite_span
end
test_span&.set_parameters({}, {"scoped_id" => metadata[:scoped_id]})

case execution_result.status
when :passed
test_span&.passed!
test_suite_span&.passed!
when :failed
test_span&.failed!(exception: execution_result.exception)
test_suite_span&.failed!
else
# :pending or nil
test_span&.skipped!(
reason: execution_result.pending_message,
exception: execution_result.pending_exception
)

test_suite_span&.skipped!
end

test_suite_span.finish if test_suite_span
test_suite_span&.finish

result
end
Expand Down
3 changes: 1 addition & 2 deletions lib/datadog/ci/contrib/rspec/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class Integration
register_as :rspec

def self.version
Gem.loaded_specs["rspec-core"] \
&& Gem.loaded_specs["rspec-core"].version
Gem.loaded_specs["rspec-core"]&.version
end

def self.loaded?
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/ext/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def validate_git_sha(git_sha)
return
end

unless HEX_NUMBER_REGEXP =~ git_sha
unless HEX_NUMBER_REGEXP.match?(git_sha)
message += " Expected SHA to be a valid HEX number, got #{git_sha}."
Datadog.logger.error(message)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/ext/environment/providers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def set_branch_and_tag
@branch = @tag = nil

# @type var branch_or_tag_string: untyped
if branch_or_tag_string && branch_or_tag_string.include?("tags/")
if branch_or_tag_string&.include?("tags/")
@tag = branch_or_tag_string
else
@branch = branch_or_tag_string
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/ext/environment/providers/bitbucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def provider_name
end

def pipeline_id
env["BITBUCKET_PIPELINE_UUID"] ? env["BITBUCKET_PIPELINE_UUID"].tr("{}", "") : nil
env["BITBUCKET_PIPELINE_UUID"]&.tr("{}", "")
end

def pipeline_name
Expand Down
3 changes: 1 addition & 2 deletions lib/datadog/ci/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ def set_parameters(arguments, metadata = {})
private

def record_test_result(datadog_status)
suite = test_suite
suite.record_test_result(datadog_status) if suite
test_suite&.record_test_result(datadog_status)
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/datadog/ci/test_visibility/context/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ def active_test_suite(test_suite_name)

def service
@mutex.synchronize do
# thank you RBS for this weirdness
test_session = @test_session
test_session.service if test_session
@test_session&.service
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/test_visibility/null_recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def active_test_suite(test_suite_name)
private

def skip_tracing(block = nil)
block.call(nil) if block
block&.call(nil)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/ci/test_visibility/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ def deactivate_test_suite(test_suite_name)
private

def skip_tracing(block = nil)
block.call(nil) if block
block&.call(nil)
end

# Sets trace's origin to ciapp-test
def set_trace_origin(trace)
trace.origin = Ext::Test::CONTEXT_ORIGIN if trace
trace&.origin = Ext::Test::CONTEXT_ORIGIN
end

def build_test_session(tracer_span, tags)
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/test_visibility/serializers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def to_s
end

def to_integer(value)
value.to_i if value
value&.to_i
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/datadog/ci/test_visibility/null_recorder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
recorder.trace_test("my test", "my suite") do |test_span|
spy_under_test.call

test_span.passed! if test_span
test_span&.passed!
end
end

Expand Down Expand Up @@ -71,7 +71,7 @@
recorder.trace("step", "my step") do |span|
spy_under_test.call

span.set_metric("my.metric", 42) if span
span&.set_metric("my.metric", 42)
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/support/tracer_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def produce_test_trace(
end
end

Datadog::CI.active_test.set_tag("test_owner", "my_team") if Datadog::CI.active_test
Datadog::CI.active_test.set_metric("memory_allocations", 16) if Datadog::CI.active_test
Datadog::CI.active_test&.set_tag("test_owner", "my_team")
Datadog::CI.active_test&.set_metric("memory_allocations", 16)

set_result(test, result: result, exception: exception, skip_reason: skip_reason) if test

Expand Down

0 comments on commit b711660

Please sign in to comment.