Skip to content

Instantly share code, notes, and snippets.

@lukeledet
Created October 10, 2015 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukeledet/6cf41ae3368eec53dff2 to your computer and use it in GitHub Desktop.
Save lukeledet/6cf41ae3368eec53dff2 to your computer and use it in GitHub Desktop.
Forgiver class and tests
class Forgiver < BasicObject
attr_reader :arg
def initialize arg
@arg = arg
end
def method_missing m, *args, &block
arg.respond_to?(m) ? ::Forgiver.new(arg.send(m, *args, &block)) : self
end
end
require 'minitest/autorun'
require './forgiver'
class ForgiverTest < Minitest::Test
def setup
@object = Forgiver.new("string")
end
def test_simple_return
assert @object.upcase === "STRING"
end
def test_single_invalid_method
# This should return the original argument
assert @object.sup === "string"
end
def test_invalid_method_after_valid_method
assert @object.upcase.noop === "STRING"
end
def test_mix_of_valid_and_invalid_methods
assert @object.noop.noop.upcase.noop.downcase === "string"
end
def test_many_invalid_methods
assert @object.sup.dog.hi === "string"
end
def test_many_valid_methods
assert @object.upcase.chop.length.to_s === "5"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment