Sha256: 1a5effc4e8043f96119e28320d9aea37cacabadda7201801e8baa8f50f75afc4

Contents?: true

Size: 1.93 KB

Versions: 17

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

class Sinclair
  module Matchers
    # @api private
    # @author darthjee
    #
    # AddInstanceMethod is able to build an instance of
    # {Sinclair::Matchers::ChangeInstanceMethodOn}
    class ChangeInstanceMethod < AddMethod
      # @example Checking if an instance method has changed
      #  RSpec.configure do |config|
      #    config.include Sinclair::Matchers
      #  end
      #
      #  class MyModel
      #  end
      #
      #  RSpec.describe 'my test' do
      #    let(:builder) { Sinclair.new(klass) }
      #    let(:klass)   { Class.new(MyModel) }
      #
      #    before do
      #      builder.add_method(:the_method) { 10 }
      #      builder.build
      #      builder.add_method(:the_method) { 20 }
      #    end
      #
      #    it do
      #      expect{ builder.build }.to change_method(:the_method).on(klass)
      #    end
      #  end
      #
      # @example Checking if an instance method has changed on an instance
      #  RSpec.configure do |config|
      #    config.include Sinclair::Matchers
      #  end
      #
      #  class MyModel
      #  end
      #
      #  RSpec.describe 'my test' do
      #    let(:builder)  { Sinclair.new(klass) }
      #    let(:instance) { klass.new }
      #    let(:klass)    { Class.new(MyModel) }
      #
      #    before do
      #      builder.add_method(:the_method) { 10 }
      #      builder.build
      #      builder.add_method(:the_method) { 20 }
      #    end
      #
      #    it do
      #      expect{ builder.build }.to change_method(:the_method).on(instance)
      #    end
      #  end
      with_final_matcher :on, ChangeInstanceMethodOn

      private

      # @private
      #
      # Error description on wrong usage
      #
      # @return String
      def matcher_error
        'You should specify which instance the method is being changed on' \
          "change_method(:#{method_name}).on(instance)"
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

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