How to use camelize method of Support Package

Best Spinach_ruby code snippet using Support.camelize

inflector_test.rb

Source:inflector_test.rb Github

copy

Full Screen

...106 assert_equal(titleized, ActiveSupport::Inflector.titleize(before, keep_id_suffix: true),107 "mixture to TitleCase with keep_id_suffix failed for #{before}")108 end109 end110 def test_camelize111 CamelToUnderscore.each do |camel, underscore|112 assert_equal(camel, ActiveSupport::Inflector.camelize(underscore))113 end114 end115 def test_camelize_with_true_upcases_the_first_letter116 assert_equal("Capital", ActiveSupport::Inflector.camelize("Capital", true))117 assert_equal("Capital", ActiveSupport::Inflector.camelize("capital", true))118 end119 def test_camelize_with_upper_upcases_the_first_letter120 assert_equal("Capital", ActiveSupport::Inflector.camelize("Capital", :upper))121 assert_equal("Capital", ActiveSupport::Inflector.camelize("capital", :upper))122 end123 def test_camelize_with_false_downcases_the_first_letter124 assert_equal("capital", ActiveSupport::Inflector.camelize("Capital", false))125 assert_equal("capital", ActiveSupport::Inflector.camelize("capital", false))126 end127 def test_camelize_with_nil_downcases_the_first_letter128 assert_equal("capital", ActiveSupport::Inflector.camelize("Capital", nil))129 assert_equal("capital", ActiveSupport::Inflector.camelize("capital", nil))130 end131 def test_camelize_with_lower_downcases_the_first_letter132 assert_equal("capital", ActiveSupport::Inflector.camelize("Capital", :lower))133 assert_equal("capital", ActiveSupport::Inflector.camelize("capital", :lower))134 end135 def test_camelize_with_any_other_arg_upcases_the_first_letter136 assert_equal("Capital", ActiveSupport::Inflector.camelize("capital", :true))137 assert_equal("Capital", ActiveSupport::Inflector.camelize("Capital", :true))138 assert_equal("Capital", ActiveSupport::Inflector.camelize("capital", :false))139 assert_equal("Capital", ActiveSupport::Inflector.camelize("capital", :foo))140 assert_equal("Capital", ActiveSupport::Inflector.camelize("capital", 42))141 assert_equal("Capital", ActiveSupport::Inflector.camelize("capital"))142 end143 def test_camelize_with_underscores144 assert_equal("CamelCase", ActiveSupport::Inflector.camelize("Camel_Case"))145 end146 def test_acronyms147 ActiveSupport::Inflector.inflections do |inflect|148 inflect.acronym("API")149 inflect.acronym("HTML")150 inflect.acronym("HTTP")151 inflect.acronym("RESTful")152 inflect.acronym("W3C")153 inflect.acronym("PhD")154 inflect.acronym("RoR")155 inflect.acronym("SSL")156 end157 # camelize underscore humanize titleize158 [159 ["API", "api", "API", "API"],160 ["APIController", "api_controller", "API controller", "API Controller"],161 ["Nokogiri::HTML", "nokogiri/html", "Nokogiri/HTML", "Nokogiri/HTML"],162 ["HTTPAPI", "http_api", "HTTP API", "HTTP API"],163 ["HTTP::Get", "http/get", "HTTP/get", "HTTP/Get"],164 ["SSLError", "ssl_error", "SSL error", "SSL Error"],165 ["RESTful", "restful", "RESTful", "RESTful"],166 ["RESTfulController", "restful_controller", "RESTful controller", "RESTful Controller"],167 ["Nested::RESTful", "nested/restful", "Nested/RESTful", "Nested/RESTful"],168 ["IHeartW3C", "i_heart_w3c", "I heart W3C", "I Heart W3C"],169 ["PhDRequired", "phd_required", "PhD required", "PhD Required"],170 ["IRoRU", "i_ror_u", "I RoR u", "I RoR U"],171 ["RESTfulHTTPAPI", "restful_http_api", "RESTful HTTP API", "RESTful HTTP API"],172 ["HTTP::RESTful", "http/restful", "HTTP/RESTful", "HTTP/RESTful"],173 ["HTTP::RESTfulAPI", "http/restful_api", "HTTP/RESTful API", "HTTP/RESTful API"],174 ["APIRESTful", "api_restful", "API RESTful", "API RESTful"],175 # misdirection176 ["Capistrano", "capistrano", "Capistrano", "Capistrano"],177 ["CapiController", "capi_controller", "Capi controller", "Capi Controller"],178 ["HttpsApis", "https_apis", "Https apis", "Https Apis"],179 ["Html5", "html5", "Html5", "Html5"],180 ["Restfully", "restfully", "Restfully", "Restfully"],181 ["RoRails", "ro_rails", "Ro rails", "Ro Rails"]182 ].each do |camel, under, human, title|183 assert_equal(camel, ActiveSupport::Inflector.camelize(under))184 assert_equal(camel, ActiveSupport::Inflector.camelize(camel))185 assert_equal(under, ActiveSupport::Inflector.underscore(under))186 assert_equal(under, ActiveSupport::Inflector.underscore(camel))187 assert_equal(title, ActiveSupport::Inflector.titleize(under))188 assert_equal(title, ActiveSupport::Inflector.titleize(camel))189 assert_equal(human, ActiveSupport::Inflector.humanize(under))190 end191 end192 def test_acronym_override193 ActiveSupport::Inflector.inflections do |inflect|194 inflect.acronym("API")195 inflect.acronym("LegacyApi")196 end197 assert_equal("LegacyApi", ActiveSupport::Inflector.camelize("legacyapi"))198 assert_equal("LegacyAPI", ActiveSupport::Inflector.camelize("legacy_api"))199 assert_equal("SomeLegacyApi", ActiveSupport::Inflector.camelize("some_legacyapi"))200 assert_equal("Nonlegacyapi", ActiveSupport::Inflector.camelize("nonlegacyapi"))201 end202 def test_acronyms_camelize_lower203 ActiveSupport::Inflector.inflections do |inflect|204 inflect.acronym("API")205 inflect.acronym("HTML")206 end207 assert_equal("htmlAPI", ActiveSupport::Inflector.camelize("html_api", false))208 assert_equal("htmlAPI", ActiveSupport::Inflector.camelize("htmlAPI", false))209 assert_equal("htmlAPI", ActiveSupport::Inflector.camelize("HTMLAPI", false))210 end211 def test_underscore_acronym_sequence212 ActiveSupport::Inflector.inflections do |inflect|213 inflect.acronym("API")214 inflect.acronym("JSON")215 inflect.acronym("HTML")216 end217 assert_equal("json_html_api", ActiveSupport::Inflector.underscore("JSONHTMLAPI"))218 end219 def test_underscore220 CamelToUnderscore.each do |camel, underscore|221 assert_equal(underscore, ActiveSupport::Inflector.underscore(camel))222 end223 CamelToUnderscoreWithoutReverse.each do |camel, underscore|224 assert_equal(underscore, ActiveSupport::Inflector.underscore(camel))225 end226 end227 def test_camelize_with_module228 CamelWithModuleToUnderscoreWithSlash.each do |camel, underscore|229 assert_equal(camel, ActiveSupport::Inflector.camelize(underscore))230 end231 end232 def test_underscore_with_slashes233 CamelWithModuleToUnderscoreWithSlash.each do |camel, underscore|234 assert_equal(underscore, ActiveSupport::Inflector.underscore(camel))235 end236 end237 def test_demodulize238 assert_equal "Account", ActiveSupport::Inflector.demodulize("MyApplication::Billing::Account")239 assert_equal "Account", ActiveSupport::Inflector.demodulize("Account")240 assert_equal "Account", ActiveSupport::Inflector.demodulize("::Account")241 assert_equal "", ActiveSupport::Inflector.demodulize("")242 end243 def test_deconstantize244 assert_equal "MyApplication::Billing", ActiveSupport::Inflector.deconstantize("MyApplication::Billing::Account")245 assert_equal "::MyApplication::Billing", ActiveSupport::Inflector.deconstantize("::MyApplication::Billing::Account")246 assert_equal "MyApplication", ActiveSupport::Inflector.deconstantize("MyApplication::Billing")247 assert_equal "::MyApplication", ActiveSupport::Inflector.deconstantize("::MyApplication::Billing")248 assert_equal "", ActiveSupport::Inflector.deconstantize("Account")249 assert_equal "", ActiveSupport::Inflector.deconstantize("::Account")250 assert_equal "", ActiveSupport::Inflector.deconstantize("")251 end252 def test_foreign_key253 ClassNameToForeignKeyWithUnderscore.each do |klass, foreign_key|254 assert_equal(foreign_key, ActiveSupport::Inflector.foreign_key(klass))255 end256 ClassNameToForeignKeyWithoutUnderscore.each do |klass, foreign_key|257 assert_equal(foreign_key, ActiveSupport::Inflector.foreign_key(klass, false))258 end259 end260 def test_tableize261 ClassNameToTableName.each do |class_name, table_name|262 assert_equal(table_name, ActiveSupport::Inflector.tableize(class_name))263 end264 end265 def test_parameterize266 StringToParameterized.each do |some_string, parameterized_string|267 assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string))268 end269 end270 def test_parameterize_and_normalize271 StringToParameterizedAndNormalized.each do |some_string, parameterized_string|272 assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string))273 end274 end275 def test_parameterize_with_custom_separator276 StringToParameterizeWithUnderscore.each do |some_string, parameterized_string|277 assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string, separator: "_"))278 end279 end280 def test_parameterize_with_multi_character_separator281 StringToParameterized.each do |some_string, parameterized_string|282 assert_equal(parameterized_string.gsub("-", "__sep__"), ActiveSupport::Inflector.parameterize(some_string, separator: "__sep__"))283 end284 end285 def test_parameterize_with_locale286 word = "Fünf autos"287 I18n.backend.store_translations(:de, i18n: { transliterate: { rule: { "ü" => "ue" } } })288 assert_equal("fuenf-autos", ActiveSupport::Inflector.parameterize(word, locale: :de))289 end290 def test_classify291 ClassNameToTableName.each do |class_name, table_name|292 assert_equal(class_name, ActiveSupport::Inflector.classify(table_name))293 assert_equal(class_name, ActiveSupport::Inflector.classify("table_prefix." + table_name))294 end295 end296 def test_classify_with_symbol297 assert_nothing_raised do298 assert_equal "FooBar", ActiveSupport::Inflector.classify(:foo_bars)299 end300 end301 def test_classify_with_leading_schema_name302 assert_equal "FooBar", ActiveSupport::Inflector.classify("schema.foo_bar")303 end304 def test_humanize305 UnderscoreToHuman.each do |underscore, human|306 assert_equal(human, ActiveSupport::Inflector.humanize(underscore))307 end308 end309 def test_humanize_without_capitalize310 UnderscoreToHumanWithoutCapitalize.each do |underscore, human|311 assert_equal(human, ActiveSupport::Inflector.humanize(underscore, capitalize: false))312 end313 end314 def test_humanize_with_keep_id_suffix315 UnderscoreToHumanWithKeepIdSuffix.each do |underscore, human|316 assert_equal(human, ActiveSupport::Inflector.humanize(underscore, keep_id_suffix: true))317 end318 end319 def test_humanize_by_rule320 ActiveSupport::Inflector.inflections do |inflect|321 inflect.human(/_cnt$/i, '\1_count')322 inflect.human(/^prefx_/i, '\1')323 end324 assert_equal("Jargon count", ActiveSupport::Inflector.humanize("jargon_cnt"))325 assert_equal("Request", ActiveSupport::Inflector.humanize("prefx_request"))326 end327 def test_humanize_by_string328 ActiveSupport::Inflector.inflections do |inflect|329 inflect.human("col_rpted_bugs", "Reported bugs")330 end331 assert_equal("Reported bugs", ActiveSupport::Inflector.humanize("col_rpted_bugs"))332 assert_equal("Col rpted bugs", ActiveSupport::Inflector.humanize("COL_rpted_bugs"))333 end334 def test_humanize_with_acronyms335 ActiveSupport::Inflector.inflections do |inflect|336 inflect.acronym "LAX"337 inflect.acronym "SFO"338 end339 assert_equal("LAX roundtrip to SFO", ActiveSupport::Inflector.humanize("LAX ROUNDTRIP TO SFO"))340 assert_equal("LAX roundtrip to SFO", ActiveSupport::Inflector.humanize("LAX ROUNDTRIP TO SFO", capitalize: false))341 assert_equal("LAX roundtrip to SFO", ActiveSupport::Inflector.humanize("lax roundtrip to sfo"))342 assert_equal("LAX roundtrip to SFO", ActiveSupport::Inflector.humanize("lax roundtrip to sfo", capitalize: false))343 assert_equal("LAX roundtrip to SFO", ActiveSupport::Inflector.humanize("Lax Roundtrip To Sfo"))344 assert_equal("LAX roundtrip to SFO", ActiveSupport::Inflector.humanize("Lax Roundtrip To Sfo", capitalize: false))345 end346 def test_constantize347 run_constantize_tests_on do |string|348 ActiveSupport::Inflector.constantize(string)349 end350 end351 def test_safe_constantize352 run_safe_constantize_tests_on do |string|353 ActiveSupport::Inflector.safe_constantize(string)354 end355 end356 def test_ordinal357 OrdinalNumbers.each do |number, ordinalized|358 assert_equal(ordinalized, number + ActiveSupport::Inflector.ordinal(number))359 end360 end361 def test_ordinalize362 OrdinalNumbers.each do |number, ordinalized|363 assert_equal(ordinalized, ActiveSupport::Inflector.ordinalize(number))364 end365 end366 def test_dasherize367 UnderscoresToDashes.each do |underscored, dasherized|368 assert_equal(dasherized, ActiveSupport::Inflector.dasherize(underscored))369 end370 end371 def test_underscore_as_reverse_of_dasherize372 UnderscoresToDashes.each_key do |underscored|373 assert_equal(underscored, ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.dasherize(underscored)))374 end375 end376 def test_underscore_to_lower_camel377 UnderscoreToLowerCamel.each do |underscored, lower_camel|378 assert_equal(lower_camel, ActiveSupport::Inflector.camelize(underscored, false))379 end380 end381 def test_symbol_to_lower_camel382 SymbolToLowerCamel.each do |symbol, lower_camel|383 assert_equal(lower_camel, ActiveSupport::Inflector.camelize(symbol, false))384 end385 end386 %w{plurals singulars uncountables humans}.each do |inflection_type|387 class_eval <<-RUBY, __FILE__, __LINE__ + 1388 def test_clear_#{inflection_type}389 ActiveSupport::Inflector.inflections.clear :#{inflection_type}390 assert ActiveSupport::Inflector.inflections.#{inflection_type}.empty?, \"#{inflection_type} inflections should be empty after clear :#{inflection_type}\"391 end392 RUBY393 end394 def test_inflector_locality395 ActiveSupport::Inflector.inflections(:es) do |inflect|396 inflect.plural(/$/, "s")397 inflect.plural(/z$/i, "ces")...

Full Screen

Full Screen

inflections.rb

Source:inflections.rb Github

copy

Full Screen

...45 def constantize46 ActiveSupport::Inflector.constantize(self)47 end48 ##49 # The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.50 #51 # +underscore+ will also change '::' to '/' to convert namespaces to paths.52 #53 # "ActiveRecord".underscore # => "active_record"54 # "ActiveRecord::Errors".underscore # => active_record/errors55 #56 def underscore57 ActiveSupport::Inflector.underscore(self)58 end59 ##60 # By default, +camelize+ converts strings to UpperCamelCase. If the argument to camelize61 # is set to <tt>:lower</tt> then camelize produces lowerCamelCase.62 #63 # +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces.64 #65 # "active_record".camelize # => "ActiveRecord"66 # "active_record".camelize(:lower) # => "activeRecord"67 # "active_record/errors".camelize # => "ActiveRecord::Errors"68 # "active_record/errors".camelize(:lower) # => "activeRecord::Errors"69 #70 def camelize(first_letter = :upper)71 case first_letter72 when :upper then ActiveSupport::Inflector.camelize(self, true)73 when :lower then ActiveSupport::Inflector.camelize(self, false)74 end75 end76 alias_method :camelcase, :camelize77 ##78 # Create a class name from a plural table name like Rails does for table names to models.79 # Note that this returns a string and not a class. (To convert to an actual class80 # follow +classify+ with +constantize+.)81 #82 # "egg_and_hams".classify # => "EggAndHam"83 # "posts".classify # => "Post"84 #85 # Singular names are not handled correctly.86 #87 # "business".classify # => "Busines"88 #89 def classify90 ActiveSupport::Inflector.classify(self)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Spinach_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful