Sha256: 7aa49a2df8f2f19de19fb1e2f560a04a5ad75d838965e31b7ee14706e03b72fe
Contents?: true
Size: 1.61 KB
Versions: 11
Compression:
Stored size: 1.61 KB
Contents
# frozen_string_literal: true class Sinclair module Matchers # @api private # @author darthjee # @abstract # # Base class for add_method_to matcher class AddMethodTo < RSpec::Matchers::BuiltIn::BaseMatcher # @param method [SYmbol,String] method name def initialize(method) @method = method end # Checks if expectation is true or not # # @return [Boolean] expectation check def matches?(event_proc) return false unless event_proc.is_a?(Proc) raise_block_syntax_error if block_given? perform_change(event_proc) added? end # definition needed for block matchers def supports_block_expectations? true end # Checkes if another instnce is equal self # # @return [Boolean] def equal?(other) return unless other.class == self.class other.method == method && other.klass == klass end alias == equal? protected # @method method # @private # # The method, to be checked, name # # @return [Symbol] attr_reader :method private # @private # # Checks if a method was added (didn't exist before) # # @return Boolean def added? !@initial_state && @final_state end # @private # # Call block to check if it aded a method or not # # @return [Boolan] def perform_change(event_proc) @initial_state = method_defined? event_proc.call @final_state = method_defined? end end end end
Version data entries
11 entries across 11 versions & 1 rubygems