Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

clean up manager and its test helpers

  • Loading branch information...
commit fbe5c6e960b4041d36fd52cd9e792751f46acfe1 1 parent 6dbf8b3
@cldwalker authored
Showing with 32 additions and 25 deletions.
  1. +3 −4 test/command_test.rb
  2. +23 −15 test/manager_test.rb
  3. +6 −6 test/test_helper.rb
View
7 test/command_test.rb
@@ -2,11 +2,10 @@
describe "Command" do
describe ".find" do
- before_all {
+ before do
reset_boson
- @top_level_command = Command.new(:name=>'blah', :lib=>'bling')
- Boson.commands << @top_level_command
- }
+ @top_level_command = create_command(:name=>'blah', :lib=>'bling')
+ end
it 'finds correct command when a subcommand of the same name exists' do
Command.find('blah').should == @top_level_command
View
38 test/manager_test.rb
@@ -17,6 +17,13 @@ def load_library(hash={})
library_loaded? 'blah'
end
+ it "loads basic library with verbose" do
+ capture_stdout {
+ load_library verbose: true
+ }.chomp.should == 'Loaded library blah'
+ library_loaded? 'blah'
+ end
+
it "loads library with commands" do
load_library :commands=>['frylock','meatwad']
library_loaded? 'blah'
@@ -62,32 +69,33 @@ def load_library(hash={})
end
it "merges with existing created library" do
- create_library('blah')
+ create_library(name: 'blah')
load_library
library_loaded? 'blah'
Boson.libraries.size.should == 1
end
end
- describe "option commands without args" do
- before_all {
+ describe ".redefine_commands" do
+ before do
reset_boson
- @library = Library.new(:name=>'blah', :commands=>['foo', 'bar'])
- Boson.libraries << @library
- @foo = Command.new(:name=>'foo', :lib=>'blah', :options=>{:fool=>:string}, :args=>'*')
- Boson.commands << @foo
- Boson.commands << Command.new(:name=>'bar', :lib=>'blah', :options=>{:bah=>:string})
- }
-
- it "are deleted" do
+ @library = create_library(:name=>'blah', :commands=>['foo', 'bar'])
+ @foo = create_command(name: 'foo', lib: 'blah', options: {fool: :string},
+ args: '*')
+ create_command(name: 'bar', lib: 'blah', options: {bah: :string})
+ end
+
+ it "only redefines commands with args" do
Scientist.expects(:redefine_command).with(anything, @foo)
Manager.redefine_commands(@library, @library.commands)
end
- it "are deleted and printed when verbose" do
+ it "with verbose only redefines commands with args and prints rejected" do
Scientist.expects(:redefine_command).with(anything, @foo)
- @library.instance_eval("@options = {:verbose=>true}")
- capture_stdout { Manager.redefine_commands(@library, @library.commands) } =~ /options.*blah/
+ Manager.instance_eval("@options = {:verbose=>true}")
+ capture_stdout {
+ Manager.redefine_commands(@library, @library.commands)
+ }.should =~ /cannot have options.*bar/
end
end
@@ -95,7 +103,7 @@ def load_library(hash={})
before { reset_libraries }
it "returns false when library isn't loaded" do
- create_library('blah')
+ create_library(name: 'blah')
Manager.loaded?('blah').should == false
end
end
View
12 test/test_helper.rb
@@ -96,12 +96,12 @@ def create_runner(*methods, &block)
end
end
- def create_library(libraries, attributes={})
- libraries = [libraries] unless libraries.is_a?(Array)
- libraries.map {|e|
- lib = Library.new({:name=>e}.update(attributes))
- Manager.add_library(lib); lib
- }
+ def create_library(hash)
+ Library.new(hash).tap {|lib| Manager.add_library lib }
+ end
+
+ def create_command(hash)
+ Command.new(hash).tap {|cmd| Boson.commands << cmd }
end
## Capture
Please sign in to comment.
Something went wrong with that request. Please try again.