Sha256: 96b1fe553c937069cb59006e68db060b277f3ac7eda52660cd24347f96888f56
Contents?: true
Size: 1015 Bytes
Versions: 1
Compression:
Stored size: 1015 Bytes
Contents
require "rspec/expectations" RSpec::Matchers.define :require_subclass_to_implement do |method_name| chain :with_error_message do |err_message| @err_message = err_message end match do |klass| item = if klass.is_a?(Class) klass.new else klass end if item.respond_to?(method_name) begin item.__send__ method_name false rescue NotImplementedError => err @err_message ||= ::SubclassMustImplement.default_error_message(method_name) err.message == @err_message end else false end end # match do failure_message do "should require subclasses to implement method `#{method_name}`, " \ "otherwise raise a NotImplementedError with message '#{@err_message}'" end failure_message_when_negated do "should not require method `#{method_name}` to be implemented by subclasses" end description do "method `#{method_name}` must be implemented by subclasses" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
subclass_must_implement-0.0.2 | lib/subclass_must_implement/rspec_matchers/require_subclass_to_implement_matcher.rb |