Sha256: fb7d8ce4e8c7d3bf02412205c28b2b8736a4d31e551705503dc1a565499f15f3

Contents?: true

Size: 1.76 KB

Versions: 19

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

class Sinclair
  module Matchers
    # @api private
    # @author darthjee
    #
    # Checks if a class method was changed
    # by the call of a block
    #
    #  This is used with a RSpec DSL method
    #  change_class_method(method_name).on(class_object)
    class ChangeClassMethodOn < ChangeMethodOn
      # @param target [Class]
      #   Class where the class method should be added to
      #
      # @param method_name [Symbol,String] method name
      def initialize(target, method_name)
        @klass = target
        super(method_name)
      end

      # Return expectaton description
      #
      # @return [String]
      def description
        "change class method '#{method_name}' on #{klass}"
      end

      # Returns message on expectation failure
      #
      # @return [String]
      def failure_message_for_should
        "expected class method '#{method_name}' to be changed on #{klass} but " \
          "#{initial_state ? "it didn't" : "it didn't exist"}"
      end

      # Returns message on expectation failure for negative expectation
      #
      # @return [String]
      def failure_message_for_should_not
        "expected class method '#{method_name}' not to be changed on #{klass} but it was"
      end

      private

      # Checks if class has instance method defined
      #
      # @return [Boolean]
      def state
        klass.methods(false).include?(method_name.to_sym) \
          && klass.method(method_name)
      end

      # Raises when block was not given
      #
      # @raise SyntaxError
      def raise_block_syntax_error
        raise SyntaxError, 'Block not received by the `change_class_method_on` matcher. ' \
          'Perhaps you want to use `{ ... }` instead of do/end?'
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
sinclair-2.1.1 lib/sinclair/matchers/change_class_method_on.rb
sinclair-2.1.0 lib/sinclair/matchers/change_class_method_on.rb
sinclair-2.0.1 lib/sinclair/matchers/change_class_method_on.rb
sinclair-2.0.0 lib/sinclair/matchers/change_class_method_on.rb
sinclair-1.16.3 lib/sinclair/matchers/change_class_method_on.rb
sinclair-1.16.2 lib/sinclair/matchers/change_class_method_on.rb
sinclair-1.16.1 lib/sinclair/matchers/change_class_method_on.rb
sinclair-1.16.0 lib/sinclair/matchers/change_class_method_on.rb
sinclair-1.15.0 lib/sinclair/matchers/change_class_method_on.rb
sinclair-1.14.2 lib/sinclair/matchers/change_class_method_on.rb
sinclair-1.14.1 lib/sinclair/matchers/change_class_method_on.rb
sinclair-1.14.0 lib/sinclair/matchers/change_class_method_on.rb
sinclair-1.13.0 lib/sinclair/matchers/change_class_method_on.rb
sinclair-1.12.1 lib/sinclair/matchers/change_class_method_on.rb
sinclair-1.12.0 lib/sinclair/matchers/change_class_method_on.rb
sinclair-1.11.0 lib/sinclair/matchers/change_class_method_on.rb
sinclair-1.10.0 lib/sinclair/matchers/change_class_method_on.rb
sinclair-1.9.0 lib/sinclair/matchers/change_class_method_on.rb
sinclair-1.8.0 lib/sinclair/matchers/change_class_method_on.rb