How to invoke a task twice in Thor

不想你离开。 提交于 2019-12-12 22:13:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!