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

safe option to around? #32

Closed
jbodah opened this issue Nov 8, 2018 · 2 comments
Closed

safe option to around? #32

jbodah opened this issue Nov 8, 2018 · 2 comments

Comments

@jbodah
Copy link

jbodah commented Nov 8, 2018

I've been using around to run encapsulate some code that ran in begin...ensure blocks. Errors in teardown's however are caught by Minitest and thus the resulting ensure never runs

This feels unexpected to me. I haven't dug into it too much but my gut tells me this is because of the use of Fibers and not ensure'ing the Fiber yield

require 'test_helper'

class HelloTest < Minitest::Spec
  around do |block|
    begin
      block.call
    ensure
      puts "it worked!"
    end
  end

  after do
    raise "woops"
  end

  it "works" do
    assert true
  end
end

With output:

# Running tests with run options --seed 8681:

E

Error:
HelloTest#test_0001_works:
RuntimeError: woops
    /Users/jbodah/repos/cg-ruby-sem/test/unit/hello_test.rb:13:in `block in <class:HelloTest>'


Finished tests in 0.002105s, 475.0594 tests/s, 475.0594 assertions/s.


Slowest tests:

0.000083s test_0001_works#HelloTest

1 tests, 1 assertions, 0 failures, 1 errors, 0 skips
Coverage report generated for Unit Tests to /Users/jbodah/repos/cg-ruby-sem/artifacts/coverage. 439 / 1053 LOC (41.69%) covered.
rake aborted!
Command failed with status (1)
@grosser
Copy link
Collaborator

grosser commented Nov 8, 2018 via email

@jbodah
Copy link
Author

jbodah commented Nov 8, 2018

Sure - I just dug into it a bit; the issue is actually the resume guard clause:

From: /usr/local/bundle/gems/minitest-around-0.4.1/lib/minitest/around/spec.rb @ line 23 self.around:

    18:           raise
    19:         end
    20:       end
    21:       fib.resume(self, lambda { Fiber.yield })
    22:     end
 => 23:     after  { fib.resume unless fib == :failed }
    24:   end
    25:
    26:   # Minitest does not support multiple before/after blocks
    27:   remove_method :before
    28:   def before(type=nil, &block)

[1] pry(#<MsnAccountSyncTest>)> fib == :failed
=> true

@jbodah jbodah closed this as completed Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants