Sha256: 75c7b7cd542d9ce7c051568b92bede262777e49e3bb9a86378dccca9de85e4f7

Contents?: true

Size: 1.07 KB

Versions: 72

Compression:

Stored size: 1.07 KB

Contents

RSpec::Matchers.define :delegate do |delegated_method|
  chain :to do |target_method|
    @target_method = target_method
  end

  chain :as do |method_on_target|
    @method_on_target = method_on_target
  end

  chain :with_arguments do |args|
    @args = args
  end

  match do |instance|
    extend Mocha::API

    @instance = instance
    @args ||= []
    return_value = 'stubbed return value'
    method_on_target = @method_on_target || delegated_method
    stubbed_target = stub('stubbed_target', method_on_target => return_value)
    @instance.stubs(@target_method => stubbed_target)
    begin
      @instance.send(delegated_method, *@args) == return_value
    rescue NoMethodError
      false
    end
  end

  failure_message do
    if Class === @instance
      message = "expected #{@instance.name} "
      prefix = '.'
    else
      message = "expected #{@instance.class.name} "
      prefix = '#'
    end
    message << "to delegate #{prefix}#{delegated_method} to #{prefix}#{@target_method}"
    if @method_on_target
      message << ".#{@method_on_target}"
    end
    message
  end
end

Version data entries

72 entries across 68 versions & 5 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.7.4 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.7.3 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/factory_girl-2.6.4/spec/support/matchers/delegate.rb
classiccms-0.7.2 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.7.1 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.7.0 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.6.9 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.6.8 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.6.7 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.6.6 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.6.5 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.6.4 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.6.3 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.6.2 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.6.1 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.6.0 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.5.17 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.5.16 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb
classiccms-0.5.15 vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb