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

Delegate child session assertions to parent session #32143

Merged
merged 1 commit into from Dec 18, 2019

Conversation

sambostock
Copy link
Contributor

Summary

This fixes #32142, in which assertions made in sub-sessions in ActionDispatch::IntegrationTest are not counted in the test run report.

By overriding the assertions accessor methods on the child session to use the parent's assertions, the count is accurately tracked.

Other Information

  • Is this the appropriate fix, or is there a better way to delegate to the parent session?
  • Is this the appropriate test? Should test report output be asserted on instead?

cc. @aud

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rafaelfranca (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@sambostock sambostock force-pushed the bubble-up-session-assertions branch 2 times, most recently from fadac84 to 6ebf151 Compare March 1, 2018 05:33
@sambostock
Copy link
Contributor Author

@rafaelfranca I've made the changes you requested. Let me know what you think, and I can squash the commits down.

@sambostock sambostock force-pushed the bubble-up-session-assertions branch 2 times, most recently from fc337ec to bc8156c Compare April 18, 2018 13:59
@sambostock sambostock force-pushed the bubble-up-session-assertions branch 2 times, most recently from 7afeff0 to 4fabf25 Compare May 7, 2019 03:00
@sambostock
Copy link
Contributor Author

sambostock commented May 7, 2019

I found myself working on some integration tests and realized this never shipped 😅

  • I've rebased on latest master, and squashed my previous commits.
  • I realized that in that a grandchild session is opened by opening a session inside a child session, the delegation is indirect. Therefore, I pushed another commit which switches to storing the root session, not the parent one.
  • I noticed another relevant accessor that could result in miscounts would be failures. Should it also be proxied to the root_session? What about the various other related variables?

@rafaelfranca
Copy link
Member

  • I noticed another relevant accessor that could result in miscounts would be failures. Should it also be proxied to the root_session? What about the various other related variables?

I think we should make sure all of them work.

`IntegrationTest#open_session` uses `dup` to create the new session,
which meant it had its own copy of `@assertions`. This prevented the
assertions from being correctly counted and reported.

Child sessions now have their `attr_accessor` overriden to delegate to
the root session.
@sambostock sambostock force-pushed the bubble-up-session-assertions branch from 4fabf25 to affe3e2 Compare May 9, 2019 00:06
@sambostock
Copy link
Contributor Author

I did some experimenting, and it turns out I was wrong about all those variables.

As far as I can tell, they're defined on the report, not the test itself. The only relevant instance variables are @assertions and @failures.

@assertions is already handled, and the following test (adapted from #32142's example) shows that @failures already works on Rails 5.2.3.

@failures test
#! /usr/bin/env ruby
# frozen_string_literal: true

begin
  require "bundler/inline"
rescue LoadError => e
  $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
  raise e
end

gemfile(true) { gem 'rails', source: 'https://rubygems.org' }
require 'rails/all'
require "minitest/autorun"

class FailuresTest < ActionDispatch::IntegrationTest
  test('flunk outside session') { assert(true) } # control
  test('flunk in session') { open_session.assert(true) }
end

class BugTest < Minitest::Test
  def test_control
    test_instance = FailuresTest.new('flunk_outside_session').run
    refute_predicate test_instance.failures, :empty?
  end

  def test_actual
    test_instance = FailuresTest.new('flunk_in_session').run
    refute_predicate test_instance.failures, :empty?
  end
end

I suspect this is because failures already bubble up due to their use of exceptions.


I have once again squashed and rebased, so unless there is other feedback, this should be good to go!

@rails-bot
Copy link

rails-bot bot commented Dec 17, 2019

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Dec 17, 2019
rafaelfranca added a commit that referenced this pull request Dec 18, 2019
Delegate child session assertions to parent session
rafaelfranca added a commit that referenced this pull request Dec 18, 2019
Delegate child session assertions to parent session
@rafaelfranca rafaelfranca merged commit affe3e2 into rails:master Dec 18, 2019
@eugeneius eugeneius removed the stale label Nov 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assertions in IntegrationTest sessions incorrectly reported
5 participants