Permalink
Browse files

Split base_spec into shell_spec and invocation_spec.

  • Loading branch information...
1 parent 7647246 commit cdef0cfd1de3c81e03a35c07f577f2db7423511e @josevalim josevalim committed Jun 23, 2009
Showing with 111 additions and 103 deletions.
  1. +0 −103 spec/base_spec.rb
  2. +88 −0 spec/invocation_spec.rb
  3. +23 −0 spec/shell_spec.rb
View
@@ -30,109 +30,6 @@ def hello
base = MyCounter.new [1, 2], :third => 3
base.options.third.must == 3
end
-
- it "sets shell value" do
- shell = Thor::Shell::Basic.new
- base = MyCounter.new [1, 2], { }, :shell => shell
- base.shell.must == shell
- end
-
- it "sets the base value on the shell if an accessor is available" do
- shell = Thor::Shell::Basic.new
- shell.instance_eval "def base=(base); @base = base; end; def base; @base; end"
- base = MyCounter.new [1, 2], { }, :shell => shell
- shell.base.must == base
- end
- end
-
- describe "#invoke" do
- it "invokes a task inside another task" do
- capture(:stdout){ A.new.invoke(:two) }.must == "2\n3\n"
- end
-
- it "invokes a task just once" do
- capture(:stdout){ A.new.invoke(:one) }.must == "1\n2\n3\n"
- end
-
- it "invokes a task just once even if they belongs to different classes" do
- capture(:stdout){ D.new.invoke(:one) }.must == "1\n2\n3\n4\n5\n"
- end
-
- it "invokes a task with arguments" do
- A.new.invoke(:five, [5]).must be_true
- A.new.invoke(:five, [7]).must be_false
- end
-
- it "invokes the default task if none is given to a Thor class" do
- content = capture(:stdout){ A.new.invoke("b") }
- content.must =~ /Tasks/
- content.must =~ /LAST_NAME/
- end
-
- it "accepts a class as argument without a task to invoke" do
- content = capture(:stdout){ A.new.invoke(B) }
- content.must =~ /Tasks/
- content.must =~ /LAST_NAME/
- end
-
- it "accepts a class as argument with a task to invoke" do
- base = A.new([], :last_name => "Valim")
- base.invoke(B, :one, ["José"]).must == "Valim, José"
- end
-
- it "accepts a Thor instance as argument" do
- invoked = B.new([], :last_name => "Valim")
- base = A.new
- base.invoke(invoked, :one, ["José"]).must == "Valim, José"
- base.invoke(invoked, :one, ["José"]).must be_nil
- end
-
- it "reparses options in the new class" do
- A.start(["invoker", "--last-name", "Valim"]).must == "Valim, José"
- end
-
- it "shares initialize options with invoked class" do
- A.new([], :foo => :bar).invoke("b:two").must == { "foo" => :bar }
- end
-
- it "dump configuration values to be used in the invoked class" do
- base = A.new
- base.invoke("b:three").shell.must == base.shell
- end
-
- it "invokes a Thor::Group and all of its tasks" do
- capture(:stdout){ A.new.invoke(:c) }.must == "1\n2\n3\n"
- end
-
- it "does not invoke a Thor::Group twice" do
- base = A.new
- silence(:stdout){ base.invoke(:c) }
- capture(:stdout){ base.invoke(:c) }.must be_empty
- end
-
- it "does not invoke any of Thor::Group tasks twice" do
- base = A.new
- silence(:stdout){ base.invoke(:c) }
- capture(:stdout){ base.invoke("c:one") }.must be_empty
- end
-
- it "raises Thor::UndefinedTaskError if the task can't be found" do
- lambda do
- A.new.invoke("foo:bar")
- end.must raise_error(Thor::UndefinedTaskError)
- end
-
- it "raises an error if a non Thor class is given" do
- lambda do
- A.new.invoke(Object)
- end.must raise_error(RuntimeError, "Expected Thor class, got Object")
- end
- end
-
- describe "#shell" do
- it "returns the shell in use" do
- MyCounter.new.shell.class.must == Thor::Shell::Basic
- end
end
describe "#no_tasks" do
View
@@ -0,0 +1,88 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+require 'thor/options'
+
+describe Thor::Invocation do
+ describe "#invoke" do
+ it "invokes a task inside another task" do
+ capture(:stdout){ A.new.invoke(:two) }.must == "2\n3\n"
+ end
+
+ it "invokes a task just once" do
+ capture(:stdout){ A.new.invoke(:one) }.must == "1\n2\n3\n"
+ end
+
+ it "invokes a task just once even if they belongs to different classes" do
+ capture(:stdout){ D.new.invoke(:one) }.must == "1\n2\n3\n4\n5\n"
+ end
+
+ it "invokes a task with arguments" do
+ A.new.invoke(:five, [5]).must be_true
+ A.new.invoke(:five, [7]).must be_false
+ end
+
+ it "invokes the default task if none is given to a Thor class" do
+ content = capture(:stdout){ A.new.invoke("b") }
+ content.must =~ /Tasks/
+ content.must =~ /LAST_NAME/
+ end
+
+ it "accepts a class as argument without a task to invoke" do
+ content = capture(:stdout){ A.new.invoke(B) }
+ content.must =~ /Tasks/
+ content.must =~ /LAST_NAME/
+ end
+
+ it "accepts a class as argument with a task to invoke" do
+ base = A.new([], :last_name => "Valim")
+ base.invoke(B, :one, ["José"]).must == "Valim, José"
+ end
+
+ it "accepts a Thor instance as argument" do
+ invoked = B.new([], :last_name => "Valim")
+ base = A.new
+ base.invoke(invoked, :one, ["José"]).must == "Valim, José"
+ base.invoke(invoked, :one, ["José"]).must be_nil
+ end
+
+ it "reparses options in the new class" do
+ A.start(["invoker", "--last-name", "Valim"]).must == "Valim, José"
+ end
+
+ it "shares initialize options with invoked class" do
+ A.new([], :foo => :bar).invoke("b:two").must == { "foo" => :bar }
+ end
+
+ it "dump configuration values to be used in the invoked class" do
+ base = A.new
+ base.invoke("b:three").shell.must == base.shell
+ end
+
+ it "invokes a Thor::Group and all of its tasks" do
+ capture(:stdout){ A.new.invoke(:c) }.must == "1\n2\n3\n"
+ end
+
+ it "does not invoke a Thor::Group twice" do
+ base = A.new
+ silence(:stdout){ base.invoke(:c) }
+ capture(:stdout){ base.invoke(:c) }.must be_empty
+ end
+
+ it "does not invoke any of Thor::Group tasks twice" do
+ base = A.new
+ silence(:stdout){ base.invoke(:c) }
+ capture(:stdout){ base.invoke("c:one") }.must be_empty
+ end
+
+ it "raises Thor::UndefinedTaskError if the task can't be found" do
+ lambda do
+ A.new.invoke("foo:bar")
+ end.must raise_error(Thor::UndefinedTaskError)
+ end
+
+ it "raises an error if a non Thor class is given" do
+ lambda do
+ A.new.invoke(Object)
+ end.must raise_error(RuntimeError, "Expected Thor class, got Object")
+ end
+ end
+end
View
@@ -0,0 +1,23 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe Thor::Shell do
+ describe "#initialize" do
+ it "sets shell value" do
+ shell = Thor::Shell::Basic.new
+ base = MyCounter.new [1, 2], { }, :shell => shell
+ base.shell.must == shell
+ end
+
+ it "sets the base value on the shell if an accessor is available" do
+ shell = Thor::Shell::Basic.new
+ base = MyCounter.new [1, 2], { }, :shell => shell
+ shell.base.must == base
+ end
+ end
+
+ describe "#shell" do
+ it "returns the shell in use" do
+ MyCounter.new.shell.must be_kind_of(Thor::Shell::Basic)
+ end
+ end
+end

0 comments on commit cdef0cf

Please sign in to comment.