Sha256: cfd11a81e0afd5b39f8bc9b67e2cdd9072968a65e3cbf4faeb7f5edc84478d5b

Contents?: true

Size: 839 Bytes

Versions: 1

Compression:

Stored size: 839 Bytes

Contents

#
# Tries to send any method to application.method instead.
#
# Sadly, Ruby doesn't allow this to work work with naked assignments. So
#   foo_button.click # turns into application.foo_button.click
#   bar_text == 'baz' # turns into application.bar_text == 'baz'
# but
#   quux = 'quuux' # just stays quux = 'quuux'
#
module DefaultMethodObjectToApp
  # rubocop:disable Style/MethodMissingSuper
  def method_missing(method, *args, &block)
    super unless respond_to_missing? method
    if args.empty?
      app.send(method)
    else
      app.send(method, *args, &block)
    end
  rescue ArgumentError
    app.send(method)
  end
  # rubocop:enable Style/MethodMissingSuper

  def respond_to_missing?(method, _include_private = false)
    return false if method =~ /^app$/
    app.respond_to?(method)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rutl-0.8.0 lib/rspec/default_method_object_to_app.rb