Skip to content

Instantly share code, notes, and snippets.

@chendo
Created November 21, 2012 07:10
Show Gist options
  • Save chendo/4123532 to your computer and use it in GitHub Desktop.
Save chendo/4123532 to your computer and use it in GitHub Desktop.
WillPaginate::Collection and RSpec's =~ operator fix
# Seeing really confusing RSpec output like this?
# Failure/Error: obj.will_paginated_array.map(&:id).should =~ [foo.id, bar.id]
# expected: [1, 2]
# got: [1, 2] (using =~)
# (WillPaginate::Collection#map returns WillPaginate::Collection instance)
# This is due to how OperatorMatcher simply does a lookup of the class of the actual
# result rather and checking a hash rather than using #is_a?(klass)
#
# This snippet below will make it work again.
RSpec::Matchers::OperatorMatcher.register(WillPaginate::Collection, '=~', RSpec::Matchers::BuiltIn::MatchArray)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment