Sha256: 612eb4f43e3a3c28c392ee046762673d80db0ba28fe14f8bb417b647fbcfa14b

Contents?: true

Size: 710 Bytes

Versions: 14

Compression:

Stored size: 710 Bytes

Contents

RSpec::Matchers.define :delegate do |method|
  match do |delegator|
    @method = method
    @delegator = delegator

    return false unless @delegator.respond_to?(@to)
    return false unless @delegator.respond_to?(@method)

    target = double

    allow(@delegator).to receive(@to).and_return(target)
    allow(target).to receive(@method).and_return(:called)

    @delegator.send(@method) == :called
  end

  description do
    "delegate :#{@method} to :#{@to}"
  end

  failure_message do
    "expected #{@delegator} to delegate :#{@method} to :#{@to}"
  end

  failure_message_when_negated do
    "expected #{@delegator} not to delegate :#{@method} to :#{@to}"
  end

  chain(:to) { |to| @to = to }
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
search_flip-2.3.2 spec/delegate_matcher.rb
search_flip-2.3.1 spec/delegate_matcher.rb
search_flip-2.3.0 spec/delegate_matcher.rb
search_flip-2.2.0 spec/delegate_matcher.rb
search_flip-2.1.0 spec/delegate_matcher.rb
search_flip-2.1.0.beta2 spec/delegate_matcher.rb
search_flip-2.1.0.beta1 spec/delegate_matcher.rb
search_flip-2.0.0 spec/delegate_matcher.rb
search_flip-2.0.0.beta8 spec/delegate_matcher.rb
search_flip-2.0.0.beta7 spec/delegate_matcher.rb
search_flip-2.0.0.beta6 spec/delegate_matcher.rb
search_flip-2.0.0.beta5 spec/delegate_matcher.rb
search_flip-2.0.0.beta4 spec/delegate_matcher.rb
search_flip-2.0.0.beta3 spec/delegate_matcher.rb