Permalink
Browse files

have_matcher - use pluralize only when ActiveSupport inflections are …

…indeed defined

- Closes #30.
  • Loading branch information...
1 parent 0e46795 commit 1196f935ab84e814bd4ba633375a69471a290999 @txus txus committed with dchelimsky Oct 27, 2010
Showing with 12 additions and 2 deletions.
  1. +1 −1 lib/rspec/matchers/have.rb
  2. +11 −1 spec/rspec/matchers/have_spec.rb
@@ -75,7 +75,7 @@ def respond_to?(sym)
def method_missing(sym, *args, &block)
@collection_name = sym
- if inflector = (defined?(ActiveSupport::Inflector) ? ActiveSupport::Inflector : (defined?(Inflector) ? Inflector : nil))
+ if inflector = (defined?(ActiveSupport::Inflector) && ActiveSupport::Inflector.respond_to?(:pluralize) ? ActiveSupport::Inflector : (defined?(Inflector) ? Inflector : nil))
@plural_collection_name = inflector.pluralize(sym.to_s)
end
@args = args
@@ -4,7 +4,7 @@
describe "have matcher" do
before(:each) do
- if defined?(::ActiveSupport::Inflector)
+ if defined?(::ActiveSupport::Inflector) && ::ActiveSupport::Inflector.respond_to?(:pluralize)
@active_support_was_defined = true
else
@active_support_was_defined = false
@@ -68,6 +68,16 @@ def create_collection_owner_with(n)
owner = create_collection_owner_with(1)
owner.should have(1).item
end
+
+ context "when ActiveSupport::Inflector is partially loaded without its inflectors" do
+
+ it "does not pluralize the collection name" do
+ (class << ::ActiveSupport::Inflector; self; end).send :undef_method, :pluralize
+ owner = create_collection_owner_with(1)
+ expect { owner.should have(1).item }.to raise_error(NoMethodError)
+ end
+
+ end
after(:each) do
unless @active_support_was_defined

0 comments on commit 1196f93

Please sign in to comment.