Add class method specs extracted from extlib

* Mark failed ones as pending as I dunno correct result now.
This commit is contained in:
Markus Schirp 2012-10-15 19:53:29 +02:00
parent e72bda2044
commit e738ecee8e
8 changed files with 129 additions and 0 deletions

1
.rspec Normal file
View File

@ -0,0 +1 @@
--color

View File

@ -0,0 +1,21 @@
require 'spec_helper'
describe Inflector do
describe '.camelize' do
it 'camelizes data_mapper as DataMapper' do
Inflector.camelize('data_mapper').should == 'DataMapper'
end
it 'camelizes merb as Merb' do
Inflector.camelize('merb').should == 'Merb'
end
it 'camelizes data_mapper/resource as DataMapper::Resource' do
Inflector.camelize('data_mapper/resource').should == 'DataMapper::Resource'
end
it 'camelizes data_mapper/associations/one_to_many as DataMapper::Associations::OneToMany' do
Inflector.camelize('data_mapper/associations/one_to_many').should == 'DataMapper::Associations::OneToMany'
end
end
end

View File

@ -0,0 +1,17 @@
require 'spec_helper'
describe Inflector do
describe '.classify' do
it 'classifies data_mapper as DataMapper' do
Inflector.classify('data_mapper').should == 'DataMapper'
end
pending 'classifies enlarged_testes as EnlargedTestis' do
Inflector.classify('enlarged_testes').should == 'EnlargedTestis'
end
pending 'singularizes string first: classifies data_mappers as egg_and_hams as EggAndHam' do
Inflector.classify('egg_and_hams').should == 'EggAndHam'
end
end
end

View File

@ -0,0 +1,13 @@
require 'spec_helper'
describe Inflector do
describe '.demodulize' do
it 'demodulizes module name: DataMapper::Inflector => Inflector' do
Inflector.demodulize('DataMapper::Inflector').should == 'Inflector'
end
it 'demodulizes module name: A::B::C::D::E => E' do
Inflector.demodulize('A::B::C::D::E').should == 'E'
end
end
end

View File

@ -0,0 +1,13 @@
require 'spec_helper'
describe Inflector do
describe '.foreign_key' do
it 'adds _id to downcased string: Message => message_id' do
Inflector.foreign_key('Message').should == 'message_id'
end
it 'demodulizes string first: Admin::Post => post_id' do
Inflector.foreign_key('Admin::Post').should == 'post_id'
end
end
end

View File

@ -0,0 +1,14 @@
require 'spec_helper'
describe Inflector do
describe '.humanize' do
it 'replaces _ with space: humanizes employee_salary as Employee salary' do
Inflector.humanize('employee_salary').should == 'Employee salary'
end
it 'strips _id endings: humanizes author_id as Author' do
Inflector.humanize('author_id').should == 'Author'
end
end
end

View File

@ -0,0 +1,29 @@
require 'spec_helper'
describe Inflector do
pending '.tableize' do
it 'pluralizes last word in snake_case strings: fancy_category => fancy_categories' do
Inflector.tableize('fancy_category').should == 'fancy_categories'
end
it 'underscores CamelCase strings before pluralization: enlarged_testis => enlarged_testes' do
Inflector.tableize('enlarged_testis').should == 'enlarged_testes'
end
it 'underscores CamelCase strings before pluralization: FancyCategory => fancy_categories' do
Inflector.tableize('FancyCategory').should == 'fancy_categories'
end
it 'underscores CamelCase strings before pluralization: EnlargedTestis => enlarged_testes' do
Inflector.tableize('EnlargedTestis').should == 'enlarged_testes'
end
it 'replaces :: with underscores: Fancy::Category => fancy_categories' do
Inflector.tableize('Fancy::Category').should == 'fancy_categories'
end
it 'underscores CamelCase strings before pluralization: Enlarged::Testis => enlarged_testes' do
Inflector.tableize('Enlarged::Testis').should == 'enlarged_testes'
end
end
end

View File

@ -0,0 +1,21 @@
require 'spec_helper'
describe Inflector do
describe '.underscore' do
it 'underscores DataMapper as data_mapper' do
Inflector.underscore('DataMapper').should == 'data_mapper'
end
it 'underscores Merb as merb' do
Inflector.underscore('Merb').should == 'merb'
end
it 'underscores DataMapper::Resource as data_mapper/resource' do
Inflector.underscore('DataMapper::Resource').should == 'data_mapper/resource'
end
it 'underscores Merb::BootLoader::Rackup as merb/boot_loader/rackup' do
Inflector.underscore('Merb::BootLoader::Rackup').should == 'merb/boot_loader/rackup'
end
end
end