How to invoke a task twice in Thor
Asked Answered
M

1

2

I need to invoke a task twice in Thor. In Rake, this could be accomplished by "re-enabling" it, but I can't find an equivalent in either of http://www.rubydoc.info/github/wycats/thor/master/Thor/Invocation or https://github.com/erikhuda/thor/wiki/Invocations

Some background, because of old code, sometimes I need to reset a database between tests (I know this is not ideal, but this is old code), so my scenario is like

desc "all-tests", "all the tests"
def all_tests
  invoke :"clean-db"
  invoke :"first-tests"
  invoke :"clean-db"
  invoke :"second-tests"
end
Mcshane answered 22/9, 2017 at 17:19 Comment(1)
See also: #4331767Contamination
C
0

I had a very similar situation. What worked for me was calling the methods directly rather than using invoke. For example:

class Tests < Thor
  desc('all', 'run all tests')
  def all
    setup()
    invoke :some_test_suite
    teardown()
    setup()
    invoke :some_other_test_suite
    teardown()
    # etc.
  end 

  desc('setup', 'set up the test database')
  def setup
    # some setup tasks here
  end

  desc('teardown', 'tear down the test database')
  def teardown
    # some teardown tasks here
  end
end
Contamination answered 10/4, 2018 at 17:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.