Skip to content

Instantly share code, notes, and snippets.

@justinko
Created May 21, 2011 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinko/984935 to your computer and use it in GitHub Desktop.
Save justinko/984935 to your computer and use it in GitHub Desktop.
module RSpec
module Mocks
module AnyInstance
class Chains < Array
def add(chain)
push(chain)
chain
end
def method_names
map {|chain| chain.method_name }
end
def unplayed
reject {|chain| chain.played? }
end
def expectations
chain { select {|chain| chain.is_a?(Expectation) } }
end
def find_with_siblings(chain)
chain { select {|c| c.method_name == chain.method_name } }
end
def find_by_id(id)
find {|chain| chain.object_id == id }
end
def has_playable_messages(args)
reject {|chain| chain.any_unplayable_messages?(args) }
end
private
def chain
self.class.new yield
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment