Browse files

baconlicious

  • Loading branch information...
1 parent 58a3f56 commit d1dfb1cd7d33f5e3905b4d10a83a52226adeaf59 @cldwalker committed Jun 11, 2010
View
106 test/alias_test.rb
@@ -1,63 +1,61 @@
require File.join(File.dirname(__FILE__), 'test_helper.rb')
-class AliasTest < Test::Unit::TestCase
- context "Alias" do
- test "loads config file config/alias.yml if found" do
- File.expects(:exists?).with('config/alias.yml').returns(true)
- Alias.config_file.should == 'config/alias.yml'
- end
+describe "Alias" do
+ test "loads config file config/alias.yml if found" do
+ File.expects(:exists?).with('config/alias.yml').returns(true)
+ Alias.config_file.should == 'config/alias.yml'
+ end
- context "create" do
- before(:each) { Alias.instance_eval "@manager = @config = @config_file = nil"}
-
- test "with aliases option creates aliases" do
- options = {:aliases=>{:constant=> {'Array'=>'Arr'}, :instance_method=>{'String'=>{'to_s'=>'s'}} } , :file=>false}
- Alias.create options
- Alias.manager.aliases_of(:instance_method).empty?.should be(false)
- Alias.manager.aliases_of(:constant).empty?.should be(false)
- Alias.config.should == options
- end
-
- test "with file option creates aliases" do
- Alias.create :file=>File.join(File.dirname(__FILE__),'aliases.yml')
- Alias.manager.aliases_of(:instance_method).empty?.should be(false)
- Alias.manager.aliases_of(:class_method).empty?.should be(false)
- Alias.manager.aliases_of(:constant).empty?.should be(false)
- Alias.manager.aliases_of(:class_to_instance_method).empty?.should be(false)
- end
+ describe "create" do
+ before { Alias.instance_eval "@manager = @config = @config_file = nil"}
+
+ test "with aliases option creates aliases" do
+ options = {:aliases=>{:constant=> {'Array'=>'Arr'}, :instance_method=>{'String'=>{'to_s'=>'s'}} } , :file=>false}
+ Alias.create options
+ Alias.manager.aliases_of(:instance_method).empty?.should == false
+ Alias.manager.aliases_of(:constant).empty?.should == false
+ Alias.config.should == options
+ end
+
+ test "with file option creates aliases" do
+ Alias.create :file=>File.join(File.dirname(__FILE__),'aliases.yml')
+ Alias.manager.aliases_of(:instance_method).empty?.should == false
+ Alias.manager.aliases_of(:class_method).empty?.should == false
+ Alias.manager.aliases_of(:constant).empty?.should == false
+ Alias.manager.aliases_of(:class_to_instance_method).empty?.should == false
+ end
- test "with false file option doesn't load config file" do
- Alias.create :file=>'blah'
- File.expects(:exists?).never
- Alias.create :file=>false
- end
+ test "with false file option doesn't load config file" do
+ Alias.create :file=>'blah'
+ File.expects(:exists?).never
+ Alias.create :file=>false
+ end
- test "with invalid file option creates nothing" do
- Alias.create :file=>'blah'
- Alias.config.should == {:aliases=>{}}
- end
-
- test "with verbose option sets manager's verbose" do
- Alias.manager.verbose.should == false
- Alias.create :verbose=>true, :aliases=>{}, :file=>false
- Alias.manager.verbose.should == true
- end
+ test "with invalid file option creates nothing" do
+ Alias.create :file=>'blah'
+ Alias.config.should == {:aliases=>{}}
+ end
+
+ test "with verbose option sets manager's verbose" do
+ Alias.manager.verbose.should == false
+ Alias.create :verbose=>true, :aliases=>{}, :file=>false
+ Alias.manager.verbose.should == true
+ end
- test "with force option sets manager's verbose" do
- Alias.manager.force.should == false
- Alias.create :force=>true, :aliases=>{}
- Alias.manager.force.should == true
- end
+ test "with force option sets manager's verbose" do
+ Alias.manager.force.should == false
+ Alias.create :force=>true, :aliases=>{}
+ Alias.manager.force.should == true
+ end
- test "called twice recursively merges config" do
- hash1 = {:constant=>{"Blah"=>"B"}}
- Alias.manager.expects(:create_aliases).with(:constant, hash1[:constant])
- Alias.create :aliases=>hash1, :file=>false
- hash2 = {:constant=>{"Blah2"=>"B2"}}
- Alias.manager.expects(:create_aliases).with(:constant, hash2[:constant])
- Alias.create :aliases=>hash2, :file=>false
- Alias.config.should == {:aliases=>{:constant=>{"Blah"=>"B", "Blah2"=>"B2"}} }
- end
+ test "called twice recursively merges config" do
+ hash1 = {:constant=>{"Blah"=>"B"}}
+ Alias.manager.expects(:create_aliases).with(:constant, hash1[:constant])
+ Alias.create :aliases=>hash1, :file=>false
+ hash2 = {:constant=>{"Blah2"=>"B2"}}
+ Alias.manager.expects(:create_aliases).with(:constant, hash2[:constant])
+ Alias.create :aliases=>hash2, :file=>false
+ Alias.config.should == {:aliases=>{:constant=>{"Blah"=>"B", "Blah2"=>"B2"}} }
end
end
-end
+end
View
58 test/any_to_instance_method_creator_test.rb
@@ -1,39 +1,37 @@
require File.join(File.dirname(__FILE__), 'test_helper.rb')
-class Alias::Creators::AnyToInstanceMethodCreatorTest < Test::Unit::TestCase
- context "AnyToInstanceMethodCreator" do
- before(:each) { @manager = Alias::Manager.new }
+describe "AnyToInstanceMethodCreator" do
+ before { @manager = Alias::Manager.new }
- def expect_aliases(hash)
- arr = Alias::Creators::AnyToInstanceMethodCreator.maps_config(hash)
- Alias::Creators::AnyToInstanceMethodCreator.expects(:generates_aliases).with(arr).returns('')
- end
+ def expect_aliases(hash)
+ arr = Alias::Creators::AnyToInstanceMethodCreator.maps_config(hash)
+ Alias::Creators::AnyToInstanceMethodCreator.expects(:generates_aliases).with(arr).returns('')
+ end
- def create_aliases(hash)
- @manager.create_aliases(:any_to_instance_method, hash)
- end
+ def create_aliases(hash)
+ @manager.create_aliases(:any_to_instance_method, hash)
+ end
- test "deletes invalid classes" do
- expect_aliases 'String'=>{'String.to_s'=>'s'}
- create_aliases 'String'=>{'String.to_s'=>'s'}, 'AnotherString'=>{'String.to_s'=>'s'}
- end
+ test "deletes invalid classes" do
+ expect_aliases 'String'=>{'String.to_s'=>'s'}
+ create_aliases 'String'=>{'String.to_s'=>'s'}, 'AnotherString'=>{'String.to_s'=>'s'}
+ end
- test "deletes existing method aliases" do
- expect_aliases 'String'=>{'Date.commercial'=>'s'}
- create_aliases 'String'=>{'Date.civil'=>'strip', 'Date.commercial'=>'s'}
- end
+ test "deletes existing method aliases" do
+ expect_aliases 'String'=>{'Date.commercial'=>'s'}
+ create_aliases 'String'=>{'Date.civil'=>'strip', 'Date.commercial'=>'s'}
+ end
- test "creates aliases" do
- Kernel.eval %[
- class ::SomeClass
- def self.cap; 'itup'; end
- end
- module ::SomeModule; end
- ]
- create_aliases 'SomeModule'=>{'SomeClass.cap.to_sym'=>'c', 'SomeClass.cap.gsub'=>'gsub'}
- obj = Object.new.extend SomeModule
- SomeClass.cap.to_sym.should == obj.c
- SomeClass.cap.gsub('cap','smack') == obj.gsub('cap','smack')
- end
+ test "creates aliases" do
+ Kernel.eval %[
+ class ::SomeClass
+ def self.cap; 'itup'; end
+ end
+ module ::SomeModule; end
+ ]
+ create_aliases 'SomeModule'=>{'SomeClass.cap.to_sym'=>'c', 'SomeClass.cap.gsub'=>'gsub'}
+ obj = Object.new.extend SomeModule
+ SomeClass.cap.to_sym.should == obj.c
+ SomeClass.cap.gsub('cap','smack').should == obj.gsub('cap','smack')
end
end
View
65 test/class_method_creator_test.rb
@@ -1,42 +1,39 @@
require File.join(File.dirname(__FILE__), 'test_helper.rb')
-class Alias::Creators::ClassMethodCreatorTest < Test::Unit::TestCase
-
- context "ClassMethodCreator" do
- before(:each) { @manager = Alias::Manager.new }
- def expect_aliases(hash)
- arr = Alias::Creators::ClassMethodCreator.maps_config(hash)
- Alias::Creators::ClassMethodCreator.expects(:generates_aliases).with(arr).returns('')
- end
+describe "ClassMethodCreator" do
+ before { @manager = Alias::Manager.new }
+ def expect_aliases(hash)
+ arr = Alias::Creators::ClassMethodCreator.maps_config(hash)
+ Alias::Creators::ClassMethodCreator.expects(:generates_aliases).with(arr).returns('')
+ end
- def create_aliases(hash)
- @manager.create_aliases(:class_method, hash)
- end
-
- test "deletes invalid class method keys" do
- expect_aliases "Array"=>{}, "String"=>{'yaml_new'=>'yn'}
- create_aliases 'String'=>{'yaml_new'=>'yn'},'Array'=>{'blah'=>'bl'}
- end
+ def create_aliases(hash)
+ @manager.create_aliases(:class_method, hash)
+ end
- test "deletes invalid classes" do
- expect_aliases "String"=>{'yaml_new'=>'yn'}
- create_aliases 'String'=>{'yaml_new'=>'yn'},'Blah'=>{'new'=>'n'}
- end
+ test "deletes invalid class method keys" do
+ expect_aliases "Array"=>{}, "String"=>{'yaml_new'=>'yn'}
+ create_aliases 'String'=>{'yaml_new'=>'yn'},'Array'=>{'blah'=>'bl'}
+ end
- test "deletes existing class method aliases" do
- expect_aliases 'Date'=>{'valid_time?'=>'vt'}
- create_aliases 'Date'=>{'civil_to_jd'=>'civil', 'valid_time?'=>'vt'}
- end
+ test "deletes invalid classes" do
+ expect_aliases "String"=>{'yaml_new'=>'yn'}
+ create_aliases 'String'=>{'yaml_new'=>'yn'},'Blah'=>{'new'=>'n'}
+ end
+
+ test "deletes existing class method aliases" do
+ expect_aliases 'Date'=>{'valid_time?'=>'vt'}
+ create_aliases 'Date'=>{'civil_to_jd'=>'civil', 'valid_time?'=>'vt'}
+ end
- test "creates class method aliases" do
- Kernel.eval %[
- class ::SampleClass
- def self.cap; 'itup'; end
- end
- ]
- hash1 = {'SampleClass'=>{:cap=>:capohow}, 'Array'=>{:blah=>:bl}}
- @manager.create_aliases(:class_method, hash1)
- SampleClass.capohow.should == SampleClass.cap
- end
+ test "creates class method aliases" do
+ Kernel.eval %[
+ class ::SampleClass
+ def self.cap; 'itup'; end
+ end
+ ]
+ hash1 = {'SampleClass'=>{:cap=>:capohow}, 'Array'=>{:blah=>:bl}}
+ @manager.create_aliases(:class_method, hash1)
+ SampleClass.capohow.should == SampleClass.cap
end
end
View
86 test/class_to_instance_method_creator_test.rb
@@ -1,48 +1,46 @@
require File.join(File.dirname(__FILE__), 'test_helper.rb')
-class Alias::Creators::ClassToInstanceMethodCreatorTest < Test::Unit::TestCase
- context "ClassToInstanceMethodCreator" do
- before(:each) { @manager = Alias::Manager.new }
-
- def expect_aliases(hash)
- arr = Alias::Creators::ClassToInstanceMethodCreator.maps_config(hash)
- Alias::Creators::ClassToInstanceMethodCreator.expects(:generates_aliases).with(arr).returns('')
- end
-
- def create_aliases(hash)
- @manager.create_aliases(:class_to_instance_method, hash)
- end
-
- test "deletes invalid to classes" do
- expect_aliases 'String'=>{'String.to_s'=>'s'}
- create_aliases 'String'=>{'AnotherString.name'=>'n', 'String.to_s'=>'s'}
- end
-
- test "deletes invalid classes" do
- expect_aliases 'String'=>{'String.to_s'=>'s'}
- create_aliases 'String'=>{'String.to_s'=>'s'}, 'AnotherString'=>{'String.to_s'=>'s'}
- end
-
- test "deletes existing method aliases" do
- expect_aliases 'String'=>{'Date.commercial'=>'s'}
- create_aliases 'String'=>{'Date.civil'=>'strip', 'Date.commercial'=>'s'}
- end
-
- test "deletes invalid to methods" do
- expect_aliases 'String'=>{'Date.civil'=>'c'}
- create_aliases 'String'=>{'Date.civil'=>'c', 'Date.uncivil'=>'uc'}
- end
-
- test "creates aliases" do
- Kernel.eval %[
- class ::SampleClass
- def self.cap; 'itup'; end
- end
- module ::SampleModule; end
- ]
- create_aliases 'SampleModule'=>{'SampleClass.cap'=>'c', 'Sampleclass.dap'=>'d'}
- obj = Object.new.extend SampleModule
- SampleClass.cap.should == obj.c
- end
+describe "ClassToInstanceMethodCreator" do
+ before { @manager = Alias::Manager.new }
+
+ def expect_aliases(hash)
+ arr = Alias::Creators::ClassToInstanceMethodCreator.maps_config(hash)
+ Alias::Creators::ClassToInstanceMethodCreator.expects(:generates_aliases).with(arr).returns('')
+ end
+
+ def create_aliases(hash)
+ @manager.create_aliases(:class_to_instance_method, hash)
+ end
+
+ test "deletes invalid to classes" do
+ expect_aliases 'String'=>{'String.to_s'=>'s'}
+ create_aliases 'String'=>{'AnotherString.name'=>'n', 'String.to_s'=>'s'}
+ end
+
+ test "deletes invalid classes" do
+ expect_aliases 'String'=>{'String.to_s'=>'s'}
+ create_aliases 'String'=>{'String.to_s'=>'s'}, 'AnotherString'=>{'String.to_s'=>'s'}
+ end
+
+ test "deletes existing method aliases" do
+ expect_aliases 'String'=>{'Date.commercial'=>'s'}
+ create_aliases 'String'=>{'Date.civil'=>'strip', 'Date.commercial'=>'s'}
+ end
+
+ test "deletes invalid to methods" do
+ expect_aliases 'String'=>{'Date.civil'=>'c'}
+ create_aliases 'String'=>{'Date.civil'=>'c', 'Date.uncivil'=>'uc'}
+ end
+
+ test "creates aliases" do
+ Kernel.eval %[
+ class ::SampleClass
+ def self.cap; 'itup'; end
+ end
+ module ::SampleModule; end
+ ]
+ create_aliases 'SampleModule'=>{'SampleClass.cap'=>'c', 'Sampleclass.dap'=>'d'}
+ obj = Object.new.extend SampleModule
+ SampleClass.cap.should == obj.c
end
end
View
39 test/console_test.rb
@@ -1,60 +1,63 @@
require File.join(File.dirname(__FILE__), 'test_helper.rb')
-class Alias::ConsoleTest < Test::Unit::TestCase
- before(:all) { @console = Object.new.extend(Alias::Console) }
+describe "Console" do
+ before { @console = nil }
+ def console
+ console ||= Object.new.extend(Alias::Console)
+ end
test "create_aliases doesn't save failed alias creation" do
- capture_stderr { @console.create_aliases :blah, {} }
+ capture_stderr { console.create_aliases :blah, {} }
Alias.manager.instance_eval("@created_aliases").should == {}
end
test "create_aliases takes partial creator names" do
Alias.manager.expects(:create_aliases).with(:instance_method, {}, anything)
- @console.create_aliases(:in, {})
+ console.create_aliases(:in, {})
end
test "search_aliases lists aliases if given nothing" do
Alias.manager.expects(:all_aliases)
- @console.search_aliases
+ console.search_aliases
end
- context "save_aliases" do
- before(:all) { eval "module ::Bluh; def blah; end; end" }
- before(:each) { Alias.manager.instance_eval("@created_aliases = nil") }
+ describe "save_aliases" do
+ before_all { eval "module ::Bluh; def blah; end; end" }
+ before { Alias.manager.instance_eval("@created_aliases = nil") }
test "saves created aliases" do
hash = {"Bluh"=>{"blah"=>"bl"}}
- @console.create_aliases :instance_method, hash
+ console.create_aliases :instance_method, hash
File.expects(:exists?).returns(false)
Alias.expects(:save_to_file).with("#{ENV['HOME']}/.alias.yml", {:aliases=>{:instance_method=>hash}}.to_yaml)
- capture_stdout { @console.save_aliases }.should =~ /Save/
+ capture_stdout { console.save_aliases }.should =~ /Save/
end
test "saves to given file" do
hash = {"Bluh"=>{"blah"=>"b"}}
- @console.create_aliases :instance_method, hash
+ console.create_aliases :instance_method, hash
Alias.expects(:save_to_file).with("explicit", {:aliases=>{:instance_method=>hash}}.to_yaml)
- capture_stdout { @console.save_aliases('explicit') }.should =~ /explicit/
+ capture_stdout { console.save_aliases('explicit') }.should =~ /explicit/
end
test "prints message if nothing to save" do
- capture_stdout { @console.save_aliases }.should =~ /Didn't save/
+ capture_stdout { console.save_aliases }.should =~ /Didn't save/
end
test "saves aliases to config/alias.yml if config/ exists" do
File.expects(:directory?).returns(true)
- @console.create_aliases :instance_method, {"Bluh"=>{"blah"=>"b2"}}
+ console.create_aliases :instance_method, {"Bluh"=>{"blah"=>"b2"}}
Alias.expects(:save_to_file).with("config/alias.yml", anything)
- capture_stdout { @console.save_aliases }
+ capture_stdout { console.save_aliases }
end
test "merges existing aliases with created aliases" do
hash = {"Bluh"=>{"blah"=>"b3"}}
- @console.create_aliases :instance_method, hash
+ console.create_aliases :instance_method, hash
Alias.expects(:read_config_file).returns({:aliases=>{:instance_method=>{"Bluh"=>{"bling"=>"bl"}}}})
Alias.expects(:save_to_file).with("#{ENV['HOME']}/.alias.yml",
{:aliases=>{:instance_method=>{"Bluh"=>{'bling'=>'bl', 'blah'=>'b3'}}}}.to_yaml)
- capture_stdout { @console.save_aliases }
+ capture_stdout { console.save_aliases }
end
end
-end
+end
View
56 test/constant_creator_test.rb
@@ -1,38 +1,36 @@
require File.join(File.dirname(__FILE__), 'test_helper.rb')
-class Alias::Creators::ConstantCreatorTest < Test::Unit::TestCase
- context "AliasConstantCreator" do
- before(:each) { @manager = Alias::Manager.new }
+describe "AliasConstantCreator" do
+ before { @manager = Alias::Manager.new }
- def create_aliases(hash, options={})
- @manager.create_aliases(:constant, hash, options)
- end
+ def create_aliases(hash, options={})
+ @manager.create_aliases(:constant, hash, options)
+ end
- def expect_aliases(hash)
- arr = Alias::Creators::ConstantCreator.maps_config(hash)
- Alias::Creators::ConstantCreator.expects(:generates_aliases).with(arr).returns('')
- end
-
- test "deletes existing aliases" do
- expect_aliases "Array"=>'Ar'
- create_aliases "Alias::Creators::ConstantCreator"=>"Alias::Creator", "Array"=>"Ar"
- end
+ def expect_aliases(hash)
+ arr = Alias::Creators::ConstantCreator.maps_config(hash)
+ Alias::Creators::ConstantCreator.expects(:generates_aliases).with(arr).returns('')
+ end
+
+ test "deletes existing aliases" do
+ expect_aliases "Array"=>'Ar'
+ create_aliases "Alias::Creators::ConstantCreator"=>"Alias::Creator", "Array"=>"Ar"
+ end
- test "deletes existing aliases unless force option" do
- h1 = {"Alias::Creators::ConstantCreator"=>"Alias::Creator", "Array"=>"Ar"}
- expect_aliases h1
- create_aliases h1, :force=>true
- end
+ test "deletes existing aliases unless force option" do
+ h1 = {"Alias::Creators::ConstantCreator"=>"Alias::Creator", "Array"=>"Ar"}
+ expect_aliases h1
+ create_aliases h1, :force=>true
+ end
- test "deletes invalid classes" do
- eval "module ::Bling; end"
- expect_aliases 'Array'=>'Ar'
- create_aliases "Blah"=>"Bling", "Array"=>"Ar"
- end
+ test "deletes invalid classes" do
+ eval "module ::Bling; end"
+ expect_aliases 'Array'=>'Ar'
+ create_aliases "Blah"=>"Bling", "Array"=>"Ar"
+ end
- test "creates aliases" do
- create_aliases 'Time'=>'T'
- ::Time.should == ::T
- end
+ test "creates aliases" do
+ create_aliases 'Time'=>'T'
+ ::Time.should == ::T
end
end
View
40 test/creator_test.rb
@@ -1,29 +1,27 @@
require File.join(File.dirname(__FILE__), 'test_helper.rb')
module Alias
- class CreatorTest < Test::Unit::TestCase
- context "invalid creator" do
- before(:all) { eval "class Alias::TestCreator < Alias::Creator; end"}
- test "raises AbstractMethodError if map not defined" do
- assert_raises(Creator::AbstractMethodError) {
- TestCreator.maps_config({})
- }
- end
+describe "invalid creator" do
+ before_all { eval "class Alias::TestCreator < Alias::Creator; end"}
+ test "raises AbstractMethodError if map not defined" do
+ should.raise(Creator::AbstractMethodError) {
+ TestCreator.maps_config({})
+ }
+ end
- test "raises AbstractMethodError if generate not defined" do
- assert_raises(Creator::AbstractMethodError) {
- TestCreator.generates_aliases([])
- }
- end
+ test "raises AbstractMethodError if generate not defined" do
+ should.raise(Creator::AbstractMethodError) {
+ TestCreator.generates_aliases([])
+ }
+ end
- test "raises ArgumentError when no validator is given" do
- assert_raises(ArgumentError) { TestCreator.valid :name }
- end
+ test "raises ArgumentError when no validator is given" do
+ should.raise(ArgumentError) { TestCreator.valid :name }
+ end
- test "prints error and deletes validator when invalid one is given" do
- capture_stderr { TestCreator.valid(:name, :if=>:blah) }.should =~ /not set/
- TestCreator.validators[:name].should == nil
- end
- end
+ test "prints error and deletes validator when invalid one is given" do
+ capture_stderr { TestCreator.valid(:name, :if=>:blah) }.should =~ /not set/
+ TestCreator.validators[:name].should == nil
end
end
+end
View
64 test/instance_method_creator_test.rb
@@ -1,41 +1,39 @@
require File.join(File.dirname(__FILE__), 'test_helper.rb')
-class Alias::Creators::InstanceMethodCreatorTest < Test::Unit::TestCase
- context "InstanceMethodCreator" do
- before(:each) { @manager = Alias::Manager.new }
- def expect_aliases(hash)
- arr = Alias::Creators::InstanceMethodCreator.maps_config(hash)
- Alias::Creators::InstanceMethodCreator.expects(:generates_aliases).with(arr).returns('')
- end
+describe "InstanceMethodCreator" do
+ before { @manager = Alias::Manager.new }
+ def expect_aliases(hash)
+ arr = Alias::Creators::InstanceMethodCreator.maps_config(hash)
+ Alias::Creators::InstanceMethodCreator.expects(:generates_aliases).with(arr).returns('')
+ end
- def create_aliases(hash)
- @manager.create_aliases(:instance_method, hash)
- end
-
- test "deletes existing instance method aliases" do
- expect_aliases "String"=>{"strip"=>"st"}
- create_aliases 'String'=>{'strip'=>'st', 'chomp'=>'chop'}
- end
+ def create_aliases(hash)
+ @manager.create_aliases(:instance_method, hash)
+ end
+
+ test "deletes existing instance method aliases" do
+ expect_aliases "String"=>{"strip"=>"st"}
+ create_aliases 'String'=>{'strip'=>'st', 'chomp'=>'chop'}
+ end
- test "deletes invalid classes" do
- expect_aliases "String"=>{'strip','st'}
- create_aliases "String"=>{'strip','st'}, 'Blah'=>{'map'=>'m'}
- end
+ test "deletes invalid classes" do
+ expect_aliases "String"=>{'strip','st'}
+ create_aliases "String"=>{'strip','st'}, 'Blah'=>{'map'=>'m'}
+ end
- test "deletes invalid instance method keys" do
- expect_aliases "Array"=>{}, "String"=>{"strip"=>"st"}
- create_aliases 'String'=>{'strip'=>'st'},'Array'=>{'blah', 'bl'}
- end
+ test "deletes invalid instance method keys" do
+ expect_aliases "Array"=>{}, "String"=>{"strip"=>"st"}
+ create_aliases 'String'=>{'strip'=>'st'},'Array'=>{'blah', 'bl'}
+ end
- test "creates aliases" do
- Kernel.eval %[
- class ::SampleClass
- def whoop; 'WHOOP'; end
- end
- ]
- obj = SampleClass.new
- create_aliases 'SampleClass'=>{:whoop=>:can_of_wass, :blah=>:bl}
- SampleClass.new.whoop.should == SampleClass.new.can_of_wass
- end
+ test "creates aliases" do
+ Kernel.eval %[
+ class ::SampleClass
+ def whoop; 'WHOOP'; end
+ end
+ ]
+ obj = SampleClass.new
+ create_aliases 'SampleClass'=>{:whoop=>:can_of_wass, :blah=>:bl}
+ SampleClass.new.whoop.should == SampleClass.new.can_of_wass
end
end
View
203 test/manager_test.rb
@@ -1,105 +1,106 @@
require File.join(File.dirname(__FILE__), 'test_helper.rb')
-class Alias::ManagerTest < Test::Unit::TestCase
- before(:each) { @manager = Alias::Manager.new}
-
- context "create_aliases" do
- before(:all) { eval %[class Alias::Creators::ValidTestCreator < Alias::Creator; map { [] }; generate { ' '}; end]}
- def create_aliases(options={})
- @manager.create_aliases :valid_test, {}, options
- end
-
- test "creates aliases" do
- Kernel.expects(:eval).with(' ')
- create_aliases
- end
-
- test "doesn't create aliases with pretend option" do
- Kernel.expects(:eval).never
- capture_stdout { create_aliases :pretend=>true }.should == "\n \n"
- end
-
- test "with manager's verbose sets creator's verbose" do
- @manager.verbose = true
- create_aliases
- @manager.creators[:valid_test].verbose.should == true
- end
-
- test "with manager's verbose array sets creator's verbose" do
- @manager.verbose = [:valid_test]
- create_aliases
- @manager.creators[:valid_test].verbose.should == true
- end
-
- test "with manager's verbose array doesn't set creator's verbose" do
- @manager.verbose = [:another]
- create_aliases
- @manager.creators[:valid_test].verbose.should == false
- end
-
- test "with manager's force sets creator's force" do
- @manager.force = true
- create_aliases
- @manager.creators[:valid_test].force.should == true
- end
-
- test "with manager's force array sets creator's force" do
- @manager.force = [:valid_test]
- create_aliases
- @manager.creators[:valid_test].force.should == true
- end
-
- test "with manager's force array doesn't set creators force" do
- @manager.force = [:another]
- create_aliases
- @manager.creators[:valid_test].force.should == false
- end
-
- test "force option sets force in creator object" do
- create_aliases :force=>true
- @manager.creators[:valid_test].force.should == true
- end
-
- test "verbose option sets verbose in creator object" do
- create_aliases :verbose=>true
- @manager.creators[:valid_test].verbose.should == true
- end
-
- test "prints error if nonexistent creator given" do
- capture_stderr {@manager.create_aliases :blah, {} }.should =~ /not found/
- end
-
- test "prints error if necessary creator methods not defined" do
- eval "class Alias::Creators::BlingCreator < Alias::Creator; end"
- capture_stderr { @manager.create_aliases :bling, {} }.should =~ /BlingCreator/
- end
-
- test "prints error if aliases fail to create" do
- eval "class Alias::Creators::Bling2Creator < Alias::Creator; map {[]}; generate { 'blah' }; end"
- capture_stderr { @manager.create_aliases :bling2, {} }.should =~ /failed to create aliases/
- end
- end
-
- context "search" do
- before(:each) {
- @manager.instance_variable_set "@creators", {:constant=>Alias::Creators::ConstantCreator.new}
- @manager.stubs(:all_aliases).returns([{:name=>'Array', :alias=>'A'}, {:name=>'Abbrev', :alias=>'B'}])
- }
-
- test "key and symbol value" do
- @manager.search(:name=>:Array).should == [{:name=>'Array', :alias=>'A'}]
- end
-
- test "with key and string value" do
- @manager.search(:name=>'A').should == [{:name=>'Array', :alias=>'A'}, {:name=>'Abbrev', :alias=>'B'}]
- end
-
- test "with a string" do
- @manager.search('Array').should == [{:name=>'Array', :alias=>'A'}]
- end
-
- test "with multiple search terms" do
- @manager.search(:name=>'A', :alias=>'A').should == [{:name=>'Array', :alias=>'A'}]
- end
+describe "Manager" do
+ before { @manager = nil }
+ def manager; @manager ||= Alias::Manager.new; end
+
+ describe "create_aliases" do
+ before_all { eval %[class Alias::Creators::ValidTestCreator < Alias::Creator; map { [] }; generate { ' '}; end]}
+ def create_aliases(options={})
+ manager.create_aliases :valid_test, {}, options
end
+
+ test "creates aliases" do
+ Kernel.expects(:eval).with(' ')
+ create_aliases
+ end
+
+ test "doesn't create aliases with pretend option" do
+ Kernel.expects(:eval).never
+ capture_stdout { create_aliases :pretend=>true }.should == "\n \n"
+ end
+
+ test "with manager's verbose sets creator's verbose" do
+ manager.verbose = true
+ create_aliases
+ manager.creators[:valid_test].verbose.should == true
+ end
+
+ test "with manager's verbose array sets creator's verbose" do
+ manager.verbose = [:valid_test]
+ create_aliases
+ manager.creators[:valid_test].verbose.should == true
+ end
+
+ test "with manager's verbose array doesn't set creator's verbose" do
+ manager.verbose = [:another]
+ create_aliases
+ manager.creators[:valid_test].verbose.should == false
+ end
+
+ test "with manager's force sets creator's force" do
+ manager.force = true
+ create_aliases
+ manager.creators[:valid_test].force.should == true
+ end
+
+ test "with manager's force array sets creator's force" do
+ manager.force = [:valid_test]
+ create_aliases
+ manager.creators[:valid_test].force.should == true
+ end
+
+ test "with manager's force array doesn't set creators force" do
+ manager.force = [:another]
+ create_aliases
+ manager.creators[:valid_test].force.should == false
+ end
+
+ test "force option sets force in creator object" do
+ create_aliases :force=>true
+ manager.creators[:valid_test].force.should == true
+ end
+
+ test "verbose option sets verbose in creator object" do
+ create_aliases :verbose=>true
+ manager.creators[:valid_test].verbose.should == true
+ end
+
+ test "prints error if nonexistent creator given" do
+ capture_stderr {manager.create_aliases :blah, {} }.should =~ /not found/
+ end
+
+ test "prints error if necessary creator methods not defined" do
+ eval "class Alias::Creators::BlingCreator < Alias::Creator; end"
+ capture_stderr { manager.create_aliases :bling, {} }.should =~ /BlingCreator/
+ end
+
+ test "prints error if aliases fail to create" do
+ eval "class Alias::Creators::Bling2Creator < Alias::Creator; map {[]}; generate { 'blah' }; end"
+ capture_stderr { manager.create_aliases :bling2, {} }.should =~ /failed to create aliases/
+ end
+ end
+
+ describe "search" do
+ before {
+ manager.instance_variable_set "@creators", {:constant=>Alias::Creators::ConstantCreator.new}
+ manager.stubs(:all_aliases).returns([{:name=>'Array', :alias=>'A'}, {:name=>'Abbrev', :alias=>'B'}])
+ }
+
+ test "key and symbol value" do
+ manager.search(:name=>:Array).should == [{:name=>'Array', :alias=>'A'}]
+ end
+
+ test "with key and string value" do
+ manager.search(:name=>'A').should == [{:name=>'Array', :alias=>'A'}, {:name=>'Abbrev', :alias=>'B'}]
+ end
+
+ test "with a string" do
+ manager.search('Array').should == [{:name=>'Array', :alias=>'A'}]
+ end
+
+ test "with multiple search terms" do
+ manager.search(:name=>'A', :alias=>'A').should == [{:name=>'Array', :alias=>'A'}]
+ end
+ end
end
View
11 test/test_helper.rb
@@ -1,11 +1,12 @@
require 'rubygems'
-require 'test/unit'
-require 'context' #gem install jeremymcanally-context -s http://gems.github.com
-require 'mocha' #gem install mocha
-require 'matchy' #gem install jeremymcanally-matchy -s http://gems.github.com
+require 'bacon'
+require 'mocha'
+require 'mocha-on-bacon'
require 'alias'
-class Test::Unit::TestCase
+class Bacon::Context
+ alias_method :test, :it
+ def before_all; yield; end
def capture_stdout(&block)
original_stdout = $stdout
$stdout = fake = StringIO.new
View
74 test/util_test.rb
@@ -1,42 +1,42 @@
require File.join(File.dirname(__FILE__), 'test_helper.rb')
module Alias
- class UtilTest < Test::Unit::TestCase
- test "any_const_get fetches simple class" do
- Util.any_const_get("Array").should == Array
- end
-
- test "any_const_get fetches nested class" do
- eval "module ::Somemodule; class Someclass; end; end"
- Util.any_const_get("Somemodule::Someclass").should == Somemodule::Someclass
- end
-
- test "any_const_get returns nil for nonexistent class" do
- Util.any_const_get("NonexistentClass").should == nil
- end
-
- test "slice only returns valid keys given" do
- Util.slice({:a=>1,:b=>2}, :a, :c).should == {:a=>1}
- end
-
- test "slice_off! returns given keys but takes them off existing hash" do
- h = {:a=>1, :b=>2}
- Util.slice_off!(h, :a, :c).should == {:a=>1}
- h.should == {:b=>2}
- end
-
- test "camelize should uppercase non-underscored string" do
- Util.camelize('man').should == 'Man'
- end
-
- test "camelize should camelize underscored string" do
- Util.camelize('some_test').should == 'SomeTest'
- end
-
- test "make_shortest_aliases" do
- eval "::Y = 'some value'"
- expected_hash = {"Yo"=>"Y", "Man"=>"M", "Cool"=>"C", 'Yay'=>'Ya'}
- Util.make_shortest_aliases(['Yo','Yay','Cool','Man']).should == expected_hash
- end
+describe "Util" do
+ test "any_const_get fetches simple class" do
+ Util.any_const_get("Array").should == Array
end
+
+ test "any_const_get fetches nested class" do
+ eval "module ::Somemodule; class Someclass; end; end"
+ Util.any_const_get("Somemodule::Someclass").should == Somemodule::Someclass
+ end
+
+ test "any_const_get returns nil for nonexistent class" do
+ Util.any_const_get("NonexistentClass").should == nil
+ end
+
+ test "slice only returns valid keys given" do
+ Util.slice({:a=>1,:b=>2}, :a, :c).should == {:a=>1}
+ end
+
+ test "slice_off! returns given keys but takes them off existing hash" do
+ h = {:a=>1, :b=>2}
+ Util.slice_off!(h, :a, :c).should == {:a=>1}
+ h.should == {:b=>2}
+ end
+
+ test "camelize should uppercase non-underscored string" do
+ Util.camelize('man').should == 'Man'
+ end
+
+ test "camelize should camelize underscored string" do
+ Util.camelize('some_test').should == 'SomeTest'
+ end
+
+ test "make_shortest_aliases" do
+ eval "::Y = 'some value'"
+ expected_hash = {"Yo"=>"Y", "Man"=>"M", "Cool"=>"C", 'Yay'=>'Ya'}
+ Util.make_shortest_aliases(['Yo','Yay','Cool','Man']).should == expected_hash
+ end
+end
end
View
110 test/validator_test.rb
@@ -1,72 +1,70 @@
require File.join(File.dirname(__FILE__), 'test_helper.rb')
-class Alias::ValidatorTest < Test::Unit::TestCase
- context "Validator" do
- before(:all) { eval "class ::TestCreator < Alias::Creator; end"}
- before(:each) { Alias::Validator.instance_eval "@validators = {}"}
+describe "Validator" do
+ before_all { eval "class ::TestCreator < Alias::Creator; end"}
+ before { Alias::Validator.instance_eval "@validators = {}"}
- def validate(options={})
- creator = TestCreator.new
- options.each {|k,v| creator.send("#{k}=",v)}
- @validator.validate(creator, {}, :blah)
- end
+ def validate(options={})
+ creator = TestCreator.new
+ options.each {|k,v| creator.send("#{k}=",v)}
+ @validator.validate(creator, {}, :blah)
+ end
- def validator_message
- @validator.create_message(:blah)
- end
+ def validator_message
+ @validator.create_message(:blah)
+ end
- def create_validator(options)
- @validator = TestCreator.valid :num, options
- end
+ def create_validator(options)
+ @validator = TestCreator.valid :num, options
+ end
- def create_parent_validator(key)
- Alias::Validator.register_validators [{:key=>key, :if=>lambda {|e| 'yo'}, :message=>lambda {|e| 'cool'}}]
- @parent_validator = Alias::Validator.validators[key]
- end
+ def create_parent_validator(key)
+ Alias::Validator.register_validators [{:key=>key, :if=>lambda {|e| 'yo'}, :message=>lambda {|e| 'cool'}}]
+ @parent_validator = Alias::Validator.validators[key]
+ end
- test "copies a validator when using a previous one" do
- create_parent_validator :num
- create_validator :if=>:num
- @parent_validator.validate(TestCreator.new, {}, :blah).should == validate
- end
+ test "copies a validator when using a previous one" do
+ create_parent_validator :num
+ create_validator :if=>:num
+ @parent_validator.validate(TestCreator.new, {}, :blah).should == validate
+ end
- test "inherits a validator's message when using a previous one" do
- create_parent_validator :num
- create_validator :if=>:num
- validator_message.should == 'cool'
- end
+ test "inherits a validator's message when using a previous one" do
+ create_parent_validator :num
+ create_validator :if=>:num
+ validator_message.should == 'cool'
+ end
- test "overrides an inherited message with explicit message" do
- create_parent_validator :num
- create_validator :if=>:num, :message=>lambda {|e| 'cooler'}
- validator_message.should == 'cooler'
- end
+ test "overrides an inherited message with explicit message" do
+ create_parent_validator :num
+ create_validator :if=>:num, :message=>lambda {|e| 'cooler'}
+ validator_message.should == 'cooler'
+ end
- test "sets a default message if an invalid one is given" do
- create_validator :if=>lambda {|e| 'yo'}, :message=>:blah
- validator_message.should =~ /Validation failed/
- end
+ test "sets a default message if an invalid one is given" do
+ create_validator :if=>lambda {|e| 'yo'}, :message=>:blah
+ validator_message.should =~ /Validation failed/
+ end
- test "with :with option sets proc arg" do
- create_validator :if=>lambda {|e| 'yo'}, :with=>[:a, :b]
- @validator.validation_proc.expects(:call).with(['a','c'])
- @validator.validate(TestCreator.new, {:a=>'a', :b=>'c', :c=>'d'}, :c)
- end
+ test "with :with option sets proc arg" do
+ create_validator :if=>lambda {|e| 'yo'}, :with=>[:a, :b]
+ @validator.validation_proc.expects(:call).with(['a','c'])
+ @validator.validate(TestCreator.new, {:a=>'a', :b=>'c', :c=>'d'}, :c)
+ end
- test "with :unless option negates result and changes message" do
- create_validator :unless=>lambda {|e| true }, :message=>lambda {|e| "yo doesn't exist"}
- validate.should == false
- validator_message.should == 'yo already exists'
- end
+ test "with :unless option negates result and changes message" do
+ create_validator :unless=>lambda {|e| true }, :message=>lambda {|e| "yo doesn't exist"}
+ validate.should == false
+ validator_message.should == 'yo already exists'
+ end
- test "with :optional option can be forced" do
- create_validator :if=>lambda { false }, :optional=>true
- validate(:force=>true).should == true
- end
+ test "with :optional option can be forced" do
+ create_validator :if=>lambda { false }, :optional=>true
+ validate(:force=>true).should == true
+ end
- test "without :optional option cannot be forced" do
- create_validator :if=>lambda { false }
- validate(:force=>true).should == false
- end
+ test "without :optional option cannot be forced" do
+ create_validator :if=>lambda { false }
+ validate(:force=>true).should == false
end
end

0 comments on commit d1dfb1c

Please sign in to comment.