Sha256: 6384d6760b3c29e1d0b321b5dbe35b530547adc7dfc04d32a3f5c342dcb18110
Contents?: true
Size: 1.32 KB
Versions: 1
Compression:
Stored size: 1.32 KB
Contents
class Bogus::VerifiesStubDefinition extend Bogus::Takes takes :method_stringifier def verify!(object, method_name, args) stubbing_non_existent_method!(object, method_name) unless object.respond_to?(method_name) method = object.method(method_name) wrong_number_of_arguments!(method, args) if under_number_of_required_arguments?(method, args.size) wrong_number_of_arguments!(method, args) if over_number_of_allowed_arguments?(method, args.size) end private def wrong_number_of_arguments!(method, args) args_string = method_stringifier.arguments_as_string(method.parameters) raise ArgumentError, "tried to stub #{method.name}(#{args_string}) with #{args.size} arguments" end def stubbing_non_existent_method!(object, method_name) raise NameError, "#{object.inspect} does not respond to #{method_name}" end def under_number_of_required_arguments?(method, args_count) number_of_arguments = method.arity number_of_arguments = -number_of_arguments - 1 if number_of_arguments < 0 args_count < number_of_arguments end def over_number_of_allowed_arguments?(method, args_count) return false if method.parameters.find{|type, name| type == :rest} number_of_arguments = method.parameters.count{|type, name| [:opt, :req].include?(type) } args_count > number_of_arguments end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bogus-0.0.1 | lib/bogus/verifies_stub_definition.rb |