tendersearls / tldr

A Ruby test framework for people who don't have time for slow tests 💣💥
MIT License
250 stars 4 forks source link

Not playing nice with mocktail #5

Closed bensie closed 1 year ago

bensie commented 1 year ago

Playing with tldr and trying to move some Minitest mocks over. The following exception is raised just by having the Mocktail gem loaded (without even using it). Remove gem "mocktail" and the test below works as expected.

Gemfile

source "https://rubygems.org"

gem "mocktail"
gem "tldr"

test/my_class_test.rb

require "bundler/setup"
Bundler.require(:default, :test)

class MyClassTest < TLDR
  def test_things
    assert true
  end
end
➜  tldrmocktail bundle exec tldr
bundler: failed to load command: tldr (/Users/james/.rbenv/versions/3.2.2/bin/tldr)
/Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/tldr-0.9.3/lib/tldr/sorbet_compatibility.rb:6:in `method': wrong number of arguments (given 0, expected 1) (ArgumentError)
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/tldr-0.9.3/lib/tldr/sorbet_compatibility.rb:6:in `unwrap_method'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/tldr-0.9.3/lib/tldr/value/test.rb:7:in `initialize'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/tldr-0.9.3/lib/tldr/class_util.rb:11:in `new'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/tldr-0.9.3/lib/tldr/class_util.rb:11:in `block in gather_tests'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/tldr-0.9.3/lib/tldr/class_util.rb:10:in `map'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/tldr-0.9.3/lib/tldr/class_util.rb:10:in `gather_tests'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/tldr-0.9.3/lib/tldr/planner.rb:50:in `block in gather_tests'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/tldr-0.9.3/lib/tldr/planner.rb:49:in `each'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/tldr-0.9.3/lib/tldr/planner.rb:49:in `flat_map'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/tldr-0.9.3/lib/tldr/planner.rb:49:in `gather_tests'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/tldr-0.9.3/lib/tldr/planner.rb:17:in `plan'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/tldr-0.9.3/lib/tldr.rb:41:in `tests'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/tldr-0.9.3/lib/tldr.rb:34:in `cli'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/tldr-0.9.3/exe/tldr:5:in `<top (required)>'
    from /Users/james/.rbenv/versions/3.2.2/bin/tldr:25:in `load'
    from /Users/james/.rbenv/versions/3.2.2/bin/tldr:25:in `<top (required)>'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/lib/bundler/cli/exec.rb:58:in `load'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/lib/bundler/cli/exec.rb:58:in `kernel_load'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/lib/bundler/cli/exec.rb:23:in `run'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/lib/bundler/cli.rb:492:in `exec'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/lib/bundler/cli.rb:34:in `dispatch'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/lib/bundler/cli.rb:28:in `start'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/exe/bundle:37:in `block in <top (required)>'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
    from /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.20/exe/bundle:29:in `<top (required)>'
    from /Users/james/.rbenv/versions/3.2.2/bin/bundle:25:in `load'
    from /Users/james/.rbenv/versions/3.2.2/bin/bundle:25:in `<main>'
searls commented 1 year ago

LOL, embarrassing. Thanks for the report

searls commented 1 year ago

Released a fix in 0.9.4

bensie commented 1 year ago

Good to go, thank you! Is there a proper place to insert a suite-wide teardown Mocktail.reset with TLDR?

searls commented 1 year ago

Just like minitest, in your helper, you can just open up or extend TLDR:

class TLDR
  def teardown
    Mocktail.reset
  end
end

Just remember to call super if any of your tests that extend this also define teardown

bensie commented 1 year ago

Ok cool that works, thanks. With these here though, it throws a warning.

/Users/james/Code/hotsock-ruby/test/helper.rb:23: warning: method redefined; discarding old teardown
/Users/james/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/tldr-0.9.4/lib/tldr.rb:28: warning: previous definition of teardown was here
searls commented 1 year ago

Whoops, that's no good. I recall adding default implementations for setup/teardown for some reason but it definitely shouldn't impact users this way.