Skip to content
Browse files

Inline custom implement matcher.

This drops rspec-fire overhead roughly from 100% to around 20%
  • Loading branch information...
1 parent 8356064 commit e14f2630e18860a17dff048e332a5cecd0e2fd41 @xaviershay committed Jul 4, 2012
Showing with 24 additions and 23 deletions.
  1. +24 −23 lib/rspec/fire.rb
View
47 lib/rspec/fire.rb
@@ -147,32 +147,33 @@ def with_doubled_class
protected
- def ensure_implemented(*method_names)
- with_doubled_class do |klass|
- klass.should implement(method_names, @__checked_methods)
- end
- end
-
- define :implement do |expected_methods, checked_methods|
- unimplemented_methods = lambda {|doubled_class|
- implemented_methods = doubled_class.send(checked_methods)
- # to_sym for non-1.9 compat
- expected_methods - implemented_methods.map(&:to_sym)
- }
+ def unimplemented_methods(doubled_class, expected_methods, checked_methods)
+ implemented_methods = doubled_class.send(checked_methods)
- match do |doubled_class|
- unimplemented_methods[ doubled_class ].empty?
- end
+ # to_sym for non-1.9 compat
+ expected_methods - implemented_methods.map(&:to_sym)
+ end
- failure_message_for_should do |doubled_class|
- implemented_methods =
- Object.public_methods - doubled_class.send(checked_methods)
- "%s does not implement:\n%s" % [
+ def ensure_implemented(*method_names)
+ with_doubled_class do |doubled_class|
+ methods = unimplemented_methods(
doubled_class,
- unimplemented_methods[ doubled_class ].sort.map {|x|
- " #{x}"
- }.join("\n")
- ]
+ method_names,
+ @__checked_methods
+ )
+
+ if methods.any?
+ implemented_methods =
+ Object.public_methods - doubled_class.send(@__checked_methods)
+
+ msg = "%s does not implement:\n%s" % [
+ doubled_class,
+ methods.sort.map {|x|
+ " #{x}"
+ }.join("\n")
+ ]
+ raise RSpec::Expectations::ExpectationNotMetError, msg
+ end
end
end
end

0 comments on commit e14f263

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