2

I have the following thor command:

require 'highline'
class Import < Thor

  desc "files", "Import files into the database"
  method_option "path", :required => true, :desc => "Path to folder containing new  files", :aliases => "-p", :type => :string

  def files
    require './config/environment'

    line = HighLine.new
    line.say(line.color("Identified files as Version 15 (English)", :green))
    if line.agree(line.color("Are you sure you want to import?", :yellow))
      line.say(line.color("Finished.  Imported 70,114 items", :green))
    else
      line.say(line.color("Aborting...", :red))
    end
  end

end

Now, obviously, at the moment this is just outputting some language to the screen. However, what I need to do is write a test for the command that tests the output is as I would expect, and that when I start hooking in the heavy lifting that I can stub that stuff out.

I've had a look at Aruba, but this doesn't appear to like interactivity for some reason, and it's not clear why.

Therefore, does anyone have any ideas on how this might be testable (with RSpec)?

4

2 に答える 2

3

Arubaは、コマンドラインアプリをテストするためのかなり完全な一連の手順です。それが機能しない場合は、arubaがすべてのファイル操作をデフォルトでに設定していることが原因である可能性がありますtmp/aruba

しかし、neimOoはアルバでシナリオを書く方法について正しいです

When I run `thor import` interactively
And I type "yes"
于 2012-09-09T13:23:12.723 に答える
0

Arubaでこれを行う方法は次のとおりです

Scenario: Test import
  When I run `thor import` interactively
  And I type "yes"
  Then the stdout should contain "Finished.  Imported 70,114 items"

ここでは、多くの aruba の例を見つけることができます https://github.com/cucumber/aruba/blob/master/features/interactive.feature

そして、ここに実装自体があり ます https://github.com/cucumber/aruba/blob/master/lib/aruba/cucumber.rb

于 2012-07-16T13:55:46.023 に答える