本文介绍了如何在Thor中两次调用任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Thor中两次调用一个任务.在Rake中,这可以通过重新启用" 来完成,但是我在 http://www中都找不到等效项. rubydoc.info/github/wycats/thor/master/Thor/Invocation https://github.com/erikhuda/thor/wiki/Invocations

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

某些背景下,由于使用了旧代码,有时我需要在测试之间重置数据库(我知道这并不理想,但这是 old 代码),所以我的情况就像

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

推荐答案

我遇到了非常相似的情况.对我有用的是直接调用方法,而不是使用invoke.例如:

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

这篇关于如何在Thor中两次调用任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-29 13:09