Created
August 10, 2012 19:22
-
-
Save myronmarston/3317068 to your computer and use it in GitHub Desktop.
Testing out using ActiveSupport's inflector w/o monkey patching String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rvm use 1.9.3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # A sample Gemfile | |
| source "https://rubygems.org" | |
| gem 'activesupport' | |
| gem 'rspec' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| GEM | |
| remote: https://rubygems.org/ | |
| specs: | |
| activesupport (3.2.8) | |
| i18n (~> 0.6) | |
| multi_json (~> 1.0) | |
| diff-lcs (1.1.3) | |
| i18n (0.6.0) | |
| multi_json (1.3.6) | |
| rspec (2.11.0) | |
| rspec-core (~> 2.11.0) | |
| rspec-expectations (~> 2.11.0) | |
| rspec-mocks (~> 2.11.0) | |
| rspec-core (2.11.1) | |
| rspec-expectations (2.11.1) | |
| diff-lcs (~> 1.1.3) | |
| rspec-mocks (2.11.1) | |
| PLATFORMS | |
| ruby | |
| DEPENDENCIES | |
| activesupport | |
| rspec |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'active_support/inflector/methods' | |
| describe "Using ActiveSupport's Inflector w/o monkey patching String" do | |
| it 'supports singularization' do | |
| expect(ActiveSupport::Inflector.singularize "dogs").to eq("dog") | |
| expect(ActiveSupport::Inflector.singularize "dog").to eq("dog") | |
| expect(ActiveSupport::Inflector.singularize "sheep").to eq("sheep") | |
| end | |
| it 'supports pluralization' do | |
| expect(ActiveSupport::Inflector.pluralize "dogs").to eq("dogs") | |
| expect(ActiveSupport::Inflector.pluralize "dog").to eq("dogs") | |
| expect(ActiveSupport::Inflector.pluralize "sheep").to eq("sheep") | |
| end | |
| it 'does not monkey patch String' do | |
| expect { "dogs".singularize }.to raise_error(NoMethodError) | |
| expect { "dog".pluralize }.to raise_error(NoMethodError) | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment