module RSpec::Fire::FireDoublable
Public Instance Methods
should_not_receive(method_name)
click to toggle source
Calls superclass method
# File lib/rspec/fire/legacy.rb, line 166 def should_not_receive(method_name) ensure_implemented(method_name) super end
should_receive(method_name)
click to toggle source
Calls superclass method
# File lib/rspec/fire/legacy.rb, line 161 def should_receive(method_name) ensure_implemented(method_name) ShouldProxy.new(self, @__method_finder, super) end
stub(method_name)
click to toggle source
Calls superclass method
# File lib/rspec/fire/legacy.rb, line 171 def stub(method_name) ensure_implemented(method_name) unless method_name.is_a?(Hash) super end
stub!(method_name)
click to toggle source
# File lib/rspec/fire/legacy.rb, line 176 def stub!(method_name) stub(method_name) end
with_doubled_class() { |value| ... }
click to toggle source
# File lib/rspec/fire/legacy.rb, line 180 def with_doubled_class ::RSpec::Fire.find_original_value_for(@__doubled_class_name) do |value| yield value if value return end if recursive_const_defined?(@__doubled_class_name) yield recursive_const_get(@__doubled_class_name) end end
Protected Instance Methods
ensure_implemented(*method_names)
click to toggle source
# File lib/rspec/fire/legacy.rb, line 207 def ensure_implemented(*method_names) with_doubled_class do |doubled_class| methods = unimplemented_methods( doubled_class, method_names, @__checked_methods ) if methods.any? implemented_methods = Object.public_methods - implemented_methods(doubled_class, @__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
implemented_methods(doubled_class, checked_methods)
click to toggle source
This cache gives a decent speed up when a class is doubled a lot.
# File lib/rspec/fire/legacy.rb, line 194 def implemented_methods(doubled_class, checked_methods) @@_implemented_methods_cache ||= {} # to_sym for non-1.9 compat @@_implemented_methods_cache[[doubled_class, checked_methods]] ||= doubled_class.__send__(checked_methods).map(&:to_sym) end
unimplemented_methods(doubled_class, expected_methods, checked_methods)
click to toggle source
# File lib/rspec/fire/legacy.rb, line 202 def unimplemented_methods(doubled_class, expected_methods, checked_methods) expected_methods.map(&:to_sym) - implemented_methods(doubled_class, checked_methods) end
verify_constant_name()
click to toggle source
# File lib/rspec/fire/legacy.rb, line 232 def verify_constant_name return if recursive_const_defined?(@__doubled_class_name) raise UndefinedConstantError, "#{@__doubled_class_name} is not a defined constant." end