Sha256: 8b1282a09416148a0db9487915f739e4e50679c26c0b905dcdd25995aafffea4
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
Contents
RSpec::Matchers.define :have_method do |method_name| match do |object| @method_name = method_name @arity ||= '0'.to_i if %r{^(\.|\#)(.*)} =~ method_name.to_s prefix = $1 normalized_method_name = $2 @normalized_method_name = normalized_method_name @klass = object.is_a?(Class) ? object : object.class if prefix == '.' @klass.method(@normalized_method_name).arity == @arity elsif prefix == '#' @klass.instance_method(@normalized_method_name).arity == @arity end else @method_name = "##{method_name}" @klass = object.class @normalized_method_name = method_name @object = object @object.method(@normalized_method_name).arity == @arity end end description do "have_method #{@method_name} [arity:#{@arity}]" end failure_message_for_should do |text| "expected #{@klass} to have_method #{@method_name} [arity:#{@arity}]" end failure_message_for_should_not do |text| "expected #{@klass} not to delegate #{@method_name} [arity:#{@arity}]" end chain(:with_arity) { |arity| @arity = arity } end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ndlib-on-rspec-0.0.4 | lib/ndlib-on-rspec/have_method_matcher.rb |
ndlib-on-rspec-0.0.3 | lib/ndlib-on-rspec/have_method_matcher.rb |