Sha256: 8ce03b48fe6f080b5870d2eeef2cfc292153364421c1d5e8359bddc18753ad4f

Contents?: true

Size: 708 Bytes

Versions: 39

Compression:

Stored size: 708 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

39 entries across 39 versions & 1 rubygems

Version Path
search_flip-3.9.0 spec/delegate_matcher.rb
search_flip-4.0.0.beta16 spec/delegate_matcher.rb
search_flip-4.0.0.beta15 spec/delegate_matcher.rb
search_flip-4.0.0.beta14 spec/delegate_matcher.rb
search_flip-3.8.0 spec/delegate_matcher.rb
search_flip-4.0.0.beta13 spec/delegate_matcher.rb
search_flip-3.7.2 spec/delegate_matcher.rb
search_flip-4.0.0.beta12 spec/delegate_matcher.rb
search_flip-3.7.1 spec/delegate_matcher.rb
search_flip-4.0.0.beta11 spec/delegate_matcher.rb
search_flip-3.7.0 spec/delegate_matcher.rb
search_flip-4.0.0.beta10 spec/delegate_matcher.rb
search_flip-3.6.0 spec/delegate_matcher.rb
search_flip-3.5.0 spec/delegate_matcher.rb
search_flip-4.0.0.beta9 spec/delegate_matcher.rb
search_flip-4.0.0.beta8 spec/delegate_matcher.rb
search_flip-3.4.0 spec/delegate_matcher.rb
search_flip-3.3.0 spec/delegate_matcher.rb
search_flip-4.0.0.beta7 spec/delegate_matcher.rb
search_flip-4.0.0.beta6 spec/delegate_matcher.rb