Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Rails errors_test to RSpec #1649

Merged
merged 4 commits into from
Aug 13, 2021
Merged

Migrate Rails errors_test to RSpec #1649

merged 4 commits into from
Aug 13, 2021

Conversation

marcotc
Copy link
Member

@marcotc marcotc commented Aug 13, 2021

This PR migrates the last (!) minitest test file to RSpec: test/contrib/rails/errors_test.rb.

All other changes are related to the removal of the last minitest: CI, Gemfile, Rakefile, DevelopmentGuide, and the removal of all support minitest files.

@marcotc marcotc added the dev/testing Involves testing processes (e.g. RSpec) label Aug 13, 2021
@marcotc marcotc self-assigned this Aug 13, 2021
@marcotc marcotc requested a review from a team August 13, 2021 00:12
Comment on lines -313 to 297
# Contrib minitests
# Contrib specs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment situation here was a bit messy before 🧹🧹🧹

@codecov-commenter
Copy link

codecov-commenter commented Aug 13, 2021

Codecov Report

Merging #1649 (e65331a) into master (3802175) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #1649    +/-   ##
========================================
  Coverage   98.32%   98.33%            
========================================
  Files         901      901            
  Lines       43713    43853   +140     
========================================
+ Hits        42980    43121   +141     
+ Misses        733      732     -1     
Impacted Files Coverage Δ
spec/ddtrace/contrib/rails/rails_helper.rb 100.00% <ø> (ø)
spec/ddtrace/contrib/rails/rack_spec.rb 100.00% <100.00%> (+0.80%) ⬆️
spec/ddtrace/profiling/ext/forking_spec.rb 99.38% <0.00%> (-0.62%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3802175...e65331a. Read the comment docs.

Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 🎉 ✅ 👌 💪 🌈 🚀 YES PLEASE THANK YOU

@@ -3,7 +3,6 @@ require 'ddtrace/version'
require 'rubocop/rake_task' if Gem.loaded_specs.key? 'rubocop'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing improvement to this file! :)

Speaking of cleanups, but unrelated, I've secretly been thinking about inversing the test matrix on this file, e.g. rather than going

if 2.1
  run A
  run B
  run C
elsif 2.2
  run B
  run C
  run D

we could go with

run A on: ["2.1"]
run B on: ["2.1", "2.2]

I think I may try to take a stab at it and see how it works in the near future :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The eternal struggle on slicing things up! There's also a bunch that would fit under:

run A on: ["2.5", "2.6", "2.7", "3.0"]
or
run A on: [">= 2.5"]

Always a fun problem 😄

But I agree that inverting the dimension could it more clear: if it looks more clear after the change than it is :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! I'll keep it in mind for my next refactoring-zen-moment :)

Comment on lines +536 to +537
expect(spans).to have(4).items
request_span, controller_span, partial_span, render_span = spans
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Crazy idea: since it seems really common for us to assert on spans before getting and naming them, I wonder if it would make sense to add an expectation as an optional argument to spans, e.g.

request_span, controller_span, partial_span, render_span = spans(expect: have(4))

or

      request_span = spans(expect: have_at_least(1)).first

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of this while writing these. I would be nice if this just worked:

request_span, controller_span, partial_span, render_span = expect(spans).to have(4).items

I like something like this:

spans(expect: have(4))
# or
spans(exactly: 4)
# or
spans(at_least: 4)
# or
spans(match(arbitrary_matcher))

Comment on lines 565 to 566
expect(partial_span).to have_error
expect(partial_span).to have_error_type('ActionView::Template::Error')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is repeated from lines 553->554

Comment on lines 497 to 507
it 'has ActionView error tags' do
is_expected.to be_server_error

if Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('3.2')
expect(spans).to have(5).items
expect(spans).to have(3).items
request_span, controller_span, render_span = spans

expect(request_span).to have_error
expect(request_span).to have_error_type('ActionView::Template::Error')
expect(request_span).to have_error_stack
expect(request_span).to have_error_message
expect(request_span.resource).to_not eq(render_span.resource)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The minispec versions of this and other tests usually had stricter assertions for the request span, e.g.:

    assert_equal(span_request.name, 'rails.action_controller')
    assert_equal(span_request.status, 1)
    assert_equal(span_request.span_type, 'web')
    assert_equal(span_request.resource, 'TracingController#error_template')
    assert_equal(span_request.get_tag('rails.route.action'), 'error_template')
    assert_equal(span_request.get_tag('rails.route.controller'), 'TracingController')
    assert_equal(span_request.get_tag('error.type'), 'ActionView::Template::Error')
    assert_equal(span_request.get_tag('error.msg'), 'divided by 0')

Was the simpler version we have with RSpec intended (because maybe we already have enough coverage elsewhere...?) or is this a gap?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed some of it, was it is rather redundant, specially around the same top-level rack.request span, when we are asserting a nested template.

I don't think there's a meaningful loss of coverage.

spec/ddtrace/contrib/rails/rack_spec.rb Outdated Show resolved Hide resolved
spec/ddtrace/contrib/rails/rack_spec.rb Outdated Show resolved Hide resolved
Comment on lines 300 to 331
it 'traces complete stack' do
is_expected.to be_server_error

expect(spans).to have(4).items

request_span, controller_span, partial_span, template_span = spans

expect(request_span.name).to eq('rack.request')
expect(request_span.resource).to eq('TestController#nonexistent_partial')
expect(request_span).to have_error
expect(request_span).to have_error_type('ActionView::Template::Error')
expect(request_span).to have_error_message(include('Missing partial test/no_partial_here'))
expect(request_span).to have_error_stack

expect(controller_span.name).to eq('rails.action_controller')
expect(controller_span.resource).to eq('TestController#nonexistent_partial')
expect(controller_span).to have_error
expect(controller_span).to have_error_type('ActionView::Template::Error')
expect(controller_span).to have_error_message(include('Missing partial test/no_partial_here'))
expect(controller_span).to have_error_stack

expect(template_span.name).to eq('rails.render_template')
expect(template_span.resource).to eq('partial_does_not_exist.html.erb') # Fallback value due to missing template
expect(template_span.span_type).to eq('template')
expect(template_span.get_tag('rails.template_name')).to eq('partial_does_not_exist.html.erb')
expect(template_span.get_tag('rails.layout')).to eq('layouts/application')
expect(template_span).to have_error
expect(template_span).to have_error_type('ActionView::Template::Error')
expect(template_span).to have_error_message(include('Missing partial test/no_partial_here'))
expect(template_span).to have_error_stack

expect(partial_span.name).to eq('rails.render_partial')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: It's somewhat confusing to follow the expects not being in the same order as we get from spans; e.g. I think it'd be easier to read if they go from request_span --> template_span or in the reverse direction, rather than jumping around.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matched order with spans response.

Copy link
Member Author

@marcotc marcotc Aug 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is much larger now because of it, but it seems easier to read 😅

spec/ddtrace/contrib/rails/rack_spec.rb Outdated Show resolved Hide resolved
@marcotc marcotc merged commit 8360a8c into master Aug 13, 2021
@marcotc marcotc deleted the migrate-last-rails branch August 13, 2021 20:21
@github-actions github-actions bot added this to the 0.53.0 milestone Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev/testing Involves testing processes (e.g. RSpec)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants