Created
May 28, 2017 11:33
-
-
Save jamesmoriarty/9d7b7345df29b33b276eb326be17a0fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "minitest/autorun" | |
class Proxy | |
module DSL | |
module ClassMethods | |
def option(name) | |
define_method(name) do |value| | |
tap do | |
options[name] = value | |
end | |
end | |
end | |
end | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
def options | |
@__options ||= {} | |
end | |
end | |
include DSL | |
option :per_page | |
option :page | |
end | |
describe Proxy::DSL do | |
before do | |
@proxy = Proxy.new | |
end | |
it "#page" do | |
@proxy.page(2).options.must_equal(page: 2) | |
@proxy.page(2).per_page(25).options.must_equal(page: 2, per_page: 25) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment