问题
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
回答1:
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
来源:https://stackoverflow.com/questions/46370031/how-to-invoke-a-task-twice-in-thor