Skip to content
This repository
Browse code

have_matcher - use pluralize only when ActiveSupport inflections are …

…indeed defined

- Closes #30.
  • Loading branch information...
commit 1196f935ab84e814bd4ba633375a69471a290999 1 parent 0e46795
Josep M. Bach authored dchelimsky committed
2  lib/rspec/matchers/have.rb
@@ -75,7 +75,7 @@ def respond_to?(sym)
75 75
       
76 76
       def method_missing(sym, *args, &block)
77 77
         @collection_name = sym
78  
-        if inflector = (defined?(ActiveSupport::Inflector) ? ActiveSupport::Inflector : (defined?(Inflector) ? Inflector : nil))
  78
+        if inflector = (defined?(ActiveSupport::Inflector) && ActiveSupport::Inflector.respond_to?(:pluralize) ? ActiveSupport::Inflector : (defined?(Inflector) ? Inflector : nil))
79 79
           @plural_collection_name = inflector.pluralize(sym.to_s)
80 80
         end
81 81
         @args = args
12  spec/rspec/matchers/have_spec.rb
@@ -4,7 +4,7 @@
4 4
 describe "have matcher" do
5 5
 
6 6
   before(:each) do
7  
-    if defined?(::ActiveSupport::Inflector)
  7
+    if defined?(::ActiveSupport::Inflector) && ::ActiveSupport::Inflector.respond_to?(:pluralize)
8 8
       @active_support_was_defined = true
9 9
     else
10 10
       @active_support_was_defined = false
@@ -68,6 +68,16 @@ def create_collection_owner_with(n)
68 68
     owner = create_collection_owner_with(1)
69 69
     owner.should have(1).item
70 70
   end
  71
+
  72
+  context "when ActiveSupport::Inflector is partially loaded without its inflectors" do
  73
+
  74
+    it "does not pluralize the collection name" do
  75
+      (class << ::ActiveSupport::Inflector; self; end).send :undef_method, :pluralize
  76
+      owner = create_collection_owner_with(1)
  77
+      expect { owner.should have(1).item }.to raise_error(NoMethodError)
  78
+    end
  79
+
  80
+  end
71 81
   
72 82
   after(:each) do
73 83
     unless @active_support_was_defined

0 notes on commit 1196f93

Please sign in to comment.
Something went wrong with that request. Please try again.