Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

inflection specs are nearly finished moved require all out so its not…

… default need to specify
  • Loading branch information...
commit 0a390f6f29e1fa3bdee48312f24990a8ba75e853 1 parent 36ddbc4
Richard Hooker authored
1  Gemfile
View
@@ -1,5 +1,6 @@
source 'https://rubygems.org'
gem 'bubble-wrap', github: 'rubymotion/BubbleWrap'
+gem "motion-redgreen", :github => "farcaller/motion-redgreen"
gemspec
3  Rakefile
View
@@ -6,8 +6,11 @@ Bundler.setup
Bundler.require
require 'bubble-wrap/test'
+require "motion_support/all"
+
# Bug RubyMotion 1.15
Motion::Project::App.setup do |app|
+ app.redgreen_style = :full
spec_files = app.spec_files + Dir.glob(File.join(app.specs_dir, '**', '*.rb'))
app.instance_variable_set("@spec_files", spec_files.uniq!)
end
4 lib/motion_support.rb
View
@@ -2,6 +2,4 @@
raise "This file must be required within a RubyMotion project Rakefile."
end
-require "motion_support/version"
-
-require File.expand_path('../motion_support/all', __FILE__)
+require "motion_support/version" unless defined?(MotionSupport::VERSION)
1  motion_support.gemspec
View
@@ -16,4 +16,5 @@ Gem::Specification.new do |gem|
gem.version = MotionSupport::VERSION
gem.add_dependency 'bubble-wrap'
+ gem.add_development_dependency 'motion-redgreen'
end
4 spec/helpers/dup.rb
View
@@ -4,10 +4,10 @@
## This helper is implemented by setting @__instance__ because in some tests
## there are module functions that access MotionSupport::Inflector.inflections,
## so we need to replace the singleton itself.
-def with_dup
+def with_dup(&block)
original = MotionSupport::Inflector.inflections
MotionSupport::Inflector::Inflections.instance_variable_set(:@__instance__, original.dup)
-ensure
+ block.call
MotionSupport::Inflector::Inflections.instance_variable_set(:@__instance__, original)
end
265 spec/inflector/inflector_spec.rb
View
@@ -18,17 +18,19 @@
end
it "uncountables should not be gready" do
- uncountable_word = "ors"
- countable_word = "sponsor"
+ with_dup do
+ uncountable_word = "ors"
+ countable_word = "sponsor"
- MotionSupport::Inflector.inflections.uncountable << uncountable_word
+ MotionSupport::Inflector.inflections.uncountable << uncountable_word
- MotionSupport::Inflector.singularize(uncountable_word).should.equal(uncountable_word)
- MotionSupport::Inflector.pluralize(uncountable_word).should.equal(uncountable_word)
- MotionSupport::Inflector.singularize(uncountable_word).should.equal(MotionSupport::Inflector.pluralize(uncountable_word))
- MotionSupport::Inflector.singularize(countable_word).should.equal "sponsor"
- MotionSupport::Inflector.pluralize(countable_word).should.equal("sponsors")
- MotionSupport::Inflector.singularize(MotionSupport::Inflector.pluralize(countable_word)).should.equal("sponsor")
+ MotionSupport::Inflector.singularize(uncountable_word).should.equal(uncountable_word)
+ MotionSupport::Inflector.pluralize(uncountable_word).should.equal(uncountable_word)
+ MotionSupport::Inflector.singularize(uncountable_word).should.equal(MotionSupport::Inflector.pluralize(uncountable_word))
+ MotionSupport::Inflector.singularize(countable_word).should.equal "sponsor"
+ MotionSupport::Inflector.pluralize(countable_word).should.equal("sponsors")
+ MotionSupport::Inflector.singularize(MotionSupport::Inflector.pluralize(countable_word)).should.equal("sponsor")
+ end
end
InflectorTestCases::SingularToPlural.each do |singular, plural|
@@ -183,17 +185,21 @@
end
end
- #describe "underscore acronym sequence" do
- #MotionSupport::Inflector.inflections do |inflect|
- #inflect.acronym("API")
- #inflect.acronym("HTML5")
- #inflect.acronym("HTML")
- #end
+ describe "underscore acronym sequence" do
+ before do
+ with_dup do
+ MotionSupport::Inflector.inflections do |inflect|
+ inflect.acronym("API")
+ inflect.acronym("HTML5")
+ inflect.acronym("HTML")
+ end
+ end
+ end
- #it "should underscore 'HTML5HTMLAPI' to equal 'html5_html_api'" do
- #MotionSupport::Inflector.underscore("HTML5HTMLAPI").should.equal("html5_html_api")
- #end
- #end
+ it "should underscore 'HTML5HTMLAPI' to equal 'html5_html_api'" do
+ MotionSupport::Inflector.underscore("HTML5HTMLAPI").should.equal("html5_html_api")
+ end
+ end
describe "underscore" do
InflectorTestCases::CamelToUnderscore.each do |camel, underscore|
@@ -307,6 +313,227 @@
end
end
+ describe "classify with leading schema name" do
+ it "should classify 'schema.foo_bar' to equal 'FooBar'" do
+ MotionSupport::Inflector.classify('schema.foo_bar').should.equal("FooBar")
+ end
+ end
+
+ describe "hamanize" do
+ InflectorTestCases::UnderscoreToHuman.each do |underscore, human|
+ it "should humanize #{underscore} to equal #{human}" do
+ MotionSupport::Inflector.humanize(underscore).should.equal(human)
+ end
+ end
+ end
+
+ describe "humanize by rule" do
+ before do
+ with_dup do
+ MotionSupport::Inflector.inflections do |inflect|
+ inflect.human(/_cnt$/i, '\1_count')
+ inflect.human(/^prefx_/i, '\1')
+ end
+ end
+ end
+
+ it "should humanize 'jargon_cnt' to equal 'Jargon count'" do
+ MotionSupport::Inflector.humanize("jargon_cnt").should.equal("Jargon count")
+ end
+
+ it "should humanize 'prefx_request' to equal 'Request'" do
+ MotionSupport::Inflector.humanize("prefx_request").should.equal("Request")
+ end
+ end
+
+ describe "humanize by string" do
+ before do
+ with_dup do
+ MotionSupport::Inflector.inflections do |inflect|
+ inflect.human("col_rpted_bugs", "Reported bugs")
+ end
+ end
+ end
+
+ it "should humanize 'col_rpted_bugs' to equal 'Reported bugs'" do
+ MotionSupport::Inflector.humanize("col_rpted_bugs").should.equal("Reported bugs")
+ end
+ it "should humaize 'COL_rpted_bugs' to equal 'Col rpted bugs'" do
+ MotionSupport::Inflector.humanize("COL_rpted_bugs").should.equal('Col rpted bugs')
+ end
+ end
+
+ describe "constantize" do
+ #def test_constantize
+ #run_constantize_tests_on do |string|
+ #ActiveSupport::Inflector.constantize(string)
+ #end
+ #end
+
+ #def test_safe_constantize
+ #run_safe_constantize_tests_on do |string|
+ #ActiveSupport::Inflector.safe_constantize(string)
+ #end
+ #end
+ end
+
+ describe "ordinal" do
+ InflectorTestCases::OrdinalNumbers.each do |number, ordinalized|
+ it "should ordinal #{number} to equal #{ordinalized}" do
+ (number + MotionSupport::Inflector.ordinal(number)).should.equal(ordinalized)
+ end
+ end
+ end
+
+ describe "ordinalize" do
+ InflectorTestCases::OrdinalNumbers.each do |number, ordinalized|
+ it "should ordinalized #{number} to equal #{ordinalized}" do
+ MotionSupport::Inflector.ordinalize(number).should.equal(ordinalized)
+ end
+ end
+ end
+
+ describe "dasherize" do
+ InflectorTestCases::UnderscoresToDashes.each do |underscored, dasherized|
+ it "should dasherize '#{underscored}' to equal '#{dasherized}'" do
+ MotionSupport::Inflector.dasherize(underscored).should.equal(dasherized)
+ end
+ end
+ end
+
+ describe "reverse of dasherize" do
+ InflectorTestCases::UnderscoresToDashes.each do |underscored, dasherized|
+ it "should underscore dasherized '#{underscored}' to equal '#{underscored}'" do
+ MotionSupport::Inflector.underscore(MotionSupport::Inflector.dasherize(underscored)).should.equal(underscored)
+ end
+ end
+ end
+
+ describe "camelize with lower" do
+ InflectorTestCases::UnderscoreToLowerCamel.each do |underscored, lower_camel|
+ it "should lower camelized '#{underscored}' to equal '#{lower_camel}'" do
+ MotionSupport::Inflector.camelize(underscored, false).should.equal(lower_camel)
+ end
+ end
+ end
+
+ describe "symbol_to_lower_camel" do
+ InflectorTestCases::SymbolToLowerCamel.each do |symbol, lower_camel|
+ it "should camelize symbol '#{symbol}' to equal '#{lower_camel}'" do
+ MotionSupport::Inflector.camelize(symbol, false).should.equal(lower_camel)
+ end
+ end
+ end
+
+ #def test_symbol_to_lower_camel
+ #SymbolToLowerCamel.each do |symbol, lower_camel|
+ #assert_equal(lower_camel, ActiveSupport::Inflector.camelize(symbol, false))
+ #end
+ #end
+
+ #%w{plurals singulars uncountables humans}.each do |inflection_type|
+ #class_eval <<-RUBY, __FILE__, __LINE__ + 1
+ #def test_clear_#{inflection_type}
+ #with_dup do
+ #ActiveSupport::Inflector.inflections.clear :#{inflection_type}
+ #assert ActiveSupport::Inflector.inflections.#{inflection_type}.empty?, \"#{inflection_type} inflections should be empty after clear :#{inflection_type}\"
+ #end
+ #end
+ #RUBY
+ #end
+
+ #def test_clear_all
+ #with_dup do
+ #ActiveSupport::Inflector.inflections do |inflect|
+ ## ensure any data is present
+ #inflect.plural(/(quiz)$/i, '\1zes')
+ #inflect.singular(/(database)s$/i, '\1')
+ #inflect.uncountable('series')
+ #inflect.human("col_rpted_bugs", "Reported bugs")
+
+ #inflect.clear :all
+
+ #assert inflect.plurals.empty?
+ #assert inflect.singulars.empty?
+ #assert inflect.uncountables.empty?
+ #assert inflect.humans.empty?
+ #end
+ #end
+ #end
+
+ #def test_clear_with_default
+ #with_dup do
+ #ActiveSupport::Inflector.inflections do |inflect|
+ ## ensure any data is present
+ #inflect.plural(/(quiz)$/i, '\1zes')
+ #inflect.singular(/(database)s$/i, '\1')
+ #inflect.uncountable('series')
+ #inflect.human("col_rpted_bugs", "Reported bugs")
+
+ #inflect.clear
+
+ #assert inflect.plurals.empty?
+ #assert inflect.singulars.empty?
+ #assert inflect.uncountables.empty?
+ #assert inflect.humans.empty?
+ #end
+ #end
+ #end
+
+ #Irregularities.each do |irregularity|
+ #singular, plural = *irregularity
+ #ActiveSupport::Inflector.inflections do |inflect|
+ #define_method("test_irregularity_between_#{singular}_and_#{plural}") do
+ #inflect.irregular(singular, plural)
+ #assert_equal singular, ActiveSupport::Inflector.singularize(plural)
+ #assert_equal plural, ActiveSupport::Inflector.pluralize(singular)
+ #end
+ #end
+ #end
+
+ #Irregularities.each do |irregularity|
+ #singular, plural = *irregularity
+ #ActiveSupport::Inflector.inflections do |inflect|
+ #define_method("test_pluralize_of_irregularity_#{plural}_should_be_the_same") do
+ #inflect.irregular(singular, plural)
+ #assert_equal plural, ActiveSupport::Inflector.pluralize(plural)
+ #end
+ #end
+ #end
+
+ #Irregularities.each do |irregularity|
+ #singular, plural = *irregularity
+ #ActiveSupport::Inflector.inflections do |inflect|
+ #define_method("test_singularize_of_irregularity_#{singular}_should_be_the_same") do
+ #inflect.irregular(singular, plural)
+ #assert_equal singular, ActiveSupport::Inflector.singularize(singular)
+ #end
+ #end
+ #end
+
+ #[ :all, [] ].each do |scope|
+ #ActiveSupport::Inflector.inflections do |inflect|
+ #define_method("test_clear_inflections_with_#{scope.kind_of?(Array) ? "no_arguments" : scope}") do
+ ## save all the inflections
+ #singulars, plurals, uncountables = inflect.singulars, inflect.plurals, inflect.uncountables
+
+ ## clear all the inflections
+ #inflect.clear(*scope)
+
+ #assert_equal [], inflect.singulars
+ #assert_equal [], inflect.plurals
+ #assert_equal [], inflect.uncountables
+
+ ## restore all the inflections
+ #singulars.reverse.each { |singular| inflect.singular(*singular) }
+ #plurals.reverse.each { |plural| inflect.plural(*plural) }
+ #inflect.uncountable(uncountables)
+
+ #assert_equal singulars, inflect.singulars
+ #assert_eq
+ #end
+
+
# @todo finish rest of specs arhhhh!
end
Please sign in to comment.
Something went wrong with that request. Please try again.