Skip to content

Commit

Permalink
test thor actions without testing thor
Browse files Browse the repository at this point in the history
  • Loading branch information
nicknovitski committed Jan 6, 2012
1 parent 07d2742 commit 34d7621
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
35 changes: 27 additions & 8 deletions spec/cli_spec.rb
@@ -1,21 +1,38 @@
require 'spec_helper'
require 'stringio'

module Oldness
describe "oldness" do
before :all do
Dir.chdir("../bin")
describe CLI do
before :each do
@io = StringIO.new
$stdout = @io
end
let(:cli) {CLI.new}

describe "rating" do
it "calls the rating method of the named Medium class with :formatted=>true"
def compare(method, medium, date=nil)
cli.invoke(method, [medium, date].compact)
args = [method, date]
args << {:formatted => true} unless method == :first
@io.string.should == eval(medium.capitalize).send(*args.compact).to_s + "\n"
end


describe "rate" do
it "calls the rating method of the named Medium class with :formatted=>true" do
compare(:rate, "film", "1999")
end
end

describe "range" do
it "calls the range method of the named Medium class with :formatted=>true"
it "calls the range method of the named Medium class with :formatted=>true" do
compare(:ranges,"film")
end
end

describe "first" do
it "prints the string formatting of the Work object stored under the first method of the appropriate Medium class"
it "calls the first method of named Medium class" do
compare(:first, "film")
end
end

describe "media" do
Expand All @@ -25,7 +42,9 @@ module Oldness
next unless c.superclass == Medium
list << c
end
`./oldness media`.should == list.collect(&:to_s).sort.inject("") { |l, c| l + c.downcase.sub("oldness::", "")+"\n" }

cli.invoke(:media)
@io.string.should == list.collect(&:to_s).sort.inject("") { |l, c| l + c.downcase.sub("oldness::", "")+"\n" }
end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/thor_spec.rb
@@ -0,0 +1 @@
require_relative '../tasks.thor'

0 comments on commit 34d7621

Please sign in to comment.