test/delegator_test.rb in sinatra-1.2.9 vs test/delegator_test.rb in sinatra-1.3.0.a
- old
+ new
@@ -1,7 +1,5 @@
-require File.expand_path('../helper', __FILE__)
-
class DelegatorTest < Test::Unit::TestCase
class Mirror
attr_reader :last_call
def method_missing(*a, &b)
@last_call = [*a.map(&:to_s)]
@@ -46,11 +44,11 @@
delegate(&block)
end
def delegate(&block)
assert Sinatra::Delegator.target != Sinatra::Application
- Object.new.extend(Sinatra::Delegator).instance_eval(&block) if block
+ Object.new.extend(Sinatra::Delegator).instance_eval(&block)
Sinatra::Delegator.target
end
def target
Sinatra::Delegator.target
@@ -58,11 +56,11 @@
it 'defaults to Sinatra::Application as target' do
assert_equal Sinatra::Delegator.target, Sinatra::Application
end
- %w[get put post delete options].each do |verb|
+ %w[get put post delete options patch].each do |verb|
it "delegates #{verb} correctly" do
delegation_app do
send verb, '/hello' do
'Hello World'
end
@@ -88,49 +86,11 @@
assert response.ok?
assert_equal 'World!', response['X-Hello']
assert_equal '', response.body
end
- it "registers extensions with the delegation target" do
- app, mixin = mirror, Module.new
- Sinatra.register mixin
- assert_equal app.last_call, ["register", mixin.to_s ]
- end
-
- it "registers helpers with the delegation target" do
- app, mixin = mirror, Module.new
- Sinatra.helpers mixin
- assert_equal app.last_call, ["helpers", mixin.to_s ]
- end
-
- it "should work with method_missing proxies for options" do
- mixin = Module.new do
- def respond_to?(method, *)
- method.to_sym == :options or super
- end
-
- def method_missing(method, *args, &block)
- return super unless method.to_sym == :options
- {:some => :option}
- end
- end
-
- value = nil
- mirror do
- extend mixin
- value = options
- end
-
- assert_equal({:some => :option}, value)
- end
-
- it "delegates crazy method names" do
- Sinatra::Delegator.delegate "foo:bar:"
- method = mirror { send "foo:bar:" }.last_call.first
- assert_equal "foo:bar:", method
- end
-
delegates 'get'
+ delegates 'patch'
delegates 'put'
delegates 'post'
delegates 'delete'
delegates 'head'
delegates 'options'