Skip to content

Commit

Permalink
have_matcher - use pluralize only when ActiveSupport inflections are …
Browse files Browse the repository at this point in the history
…indeed defined

- Closes #30.
  • Loading branch information
Josep M. Bach authored and dchelimsky committed Nov 6, 2010
1 parent 0e46795 commit 1196f93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rspec/matchers/have.rb
Expand Up @@ -75,7 +75,7 @@ def respond_to?(sym)


def method_missing(sym, *args, &block) def method_missing(sym, *args, &block)
@collection_name = sym @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) @plural_collection_name = inflector.pluralize(sym.to_s)
end end
@args = args @args = args
Expand Down
12 changes: 11 additions & 1 deletion spec/rspec/matchers/have_spec.rb
Expand Up @@ -4,7 +4,7 @@
describe "have matcher" do describe "have matcher" do


before(:each) do before(:each) do
if defined?(::ActiveSupport::Inflector) if defined?(::ActiveSupport::Inflector) && ::ActiveSupport::Inflector.respond_to?(:pluralize)
@active_support_was_defined = true @active_support_was_defined = true
else else
@active_support_was_defined = false @active_support_was_defined = false
Expand Down Expand Up @@ -68,6 +68,16 @@ def create_collection_owner_with(n)
owner = create_collection_owner_with(1) owner = create_collection_owner_with(1)
owner.should have(1).item owner.should have(1).item
end 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 after(:each) do
unless @active_support_was_defined unless @active_support_was_defined
Expand Down

0 comments on commit 1196f93

Please sign in to comment.