class Object
Public Instance Methods
arity_failure_message(method, expected_arity)
click to toggle source
# File lib/attribute_matcher/attribute_matcher.rb, line 60 def arity_failure_message(method, expected_arity) format('%s() takes %d argument%s instead of %d', method.name, method.arity, method.arity == 1 ? '' : 's', expected_arity) if method && method.arity != expected_arity end
attribute_type()
click to toggle source
# File lib/attribute_matcher/attribute_matcher.rb, line 22 def attribute_type return attribute_value.class if attribute_value actual.send(:attribute_set)[expected].primitive if actual.respond_to?(:attribute_set, true) end
attribute_value()
click to toggle source
# File lib/attribute_matcher/attribute_matcher.rb, line 18 def attribute_value actual.send(expected) end
ensure_valid_visibility(visibility)
click to toggle source
# File lib/attribute_matcher/attribute_matcher.rb, line 79 def ensure_valid_visibility(visibility) fail format('%s is an invalid visibility; should be one of %s', visibility, VALID_VISIBILITIES.join(', ')) unless VALID_VISIBILITIES.include?(visibility) end
exists?()
click to toggle source
# File lib/attribute_matcher/attribute_matcher.rb, line 27 def exists? reader || writer end
method(name)
click to toggle source
# File lib/attribute_matcher/attribute_matcher.rb, line 47 def method(name) actual.method(name) rescue NameError nil end
reader()
click to toggle source
# File lib/attribute_matcher/attribute_matcher.rb, line 39 def reader method(expected) end
reader_ok?()
click to toggle source
# File lib/attribute_matcher/attribute_matcher.rb, line 31 def reader_ok? reader && reader.arity.eql?(0) end
visibility(method)
click to toggle source
# File lib/attribute_matcher/attribute_matcher.rb, line 64 def visibility(method) klass = method.receiver.class case when klass.private_method_defined?(method.name) :private when klass.protected_method_defined?(method.name) :protected else :public end end
writer()
click to toggle source
# File lib/attribute_matcher/attribute_matcher.rb, line 43 def writer method("#{expected}=") end
writer_ok?()
click to toggle source
# File lib/attribute_matcher/attribute_matcher.rb, line 35 def writer_ok? writer && writer.arity.eql?(1) end