Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Created August 10, 2012 19:22
Show Gist options
  • Select an option

  • Save myronmarston/3317068 to your computer and use it in GitHub Desktop.

Select an option

Save myronmarston/3317068 to your computer and use it in GitHub Desktop.
Testing out using ActiveSupport's inflector w/o monkey patching String
rvm use 1.9.3
# A sample Gemfile
source "https://rubygems.org"
gem 'activesupport'
gem 'rspec'
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
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