1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Make the specs run under new miniunit stuff in Ruby 1.9

* Rename Sinatra::Test#test_request to make_request. miniunit
  runs test_XXX methods included from modules.
* Make describe/it work with miniunit -- all kinds of weirdness
  here
This commit is contained in:
Ryan Tomayko 2009-01-30 17:23:34 -08:00
parent c8f1c7cb4d
commit 18dff713cd
2 changed files with 13 additions and 10 deletions

View file

@ -7,7 +7,7 @@ module Sinatra
attr_reader :app, :request, :response
def test_request(verb, path, *args)
def make_request(verb, path, *args)
@app = Sinatra::Application if @app.nil? && defined?(Sinatra::Application)
fail "@app not set - cannot make request" if @app.nil?
@request = Rack::MockRequest.new(@app)
@ -38,14 +38,14 @@ module Sinatra
@response = @request.request(verb, path, opts)
end
def get(path, *args, &b) ; test_request('GET', path, *args, &b) ; end
def head(path, *args, &b) ; test_request('HEAD', path, *args, &b) ; end
def post(path, *args, &b) ; test_request('POST', path, *args, &b) ; end
def put(path, *args, &b) ; test_request('PUT', path, *args, &b) ; end
def delete(path, *args, &b) ; test_request('DELETE', path, *args, &b) ; end
def get(path, *args, &b) ; make_request('GET', path, *args, &b) ; end
def head(path, *args, &b) ; make_request('HEAD', path, *args, &b) ; end
def post(path, *args, &b) ; make_request('POST', path, *args, &b) ; end
def put(path, *args, &b) ; make_request('PUT', path, *args, &b) ; end
def delete(path, *args, &b) ; make_request('DELETE', path, *args, &b) ; end
def follow!
test_request 'GET', @response.location
make_request 'GET', @response.location
end
def body ; @response.body ; end
@ -103,7 +103,7 @@ module Sinatra
eval <<-RUBY, binding, __FILE__, __LINE__
def #{verb}_it(*args, &block)
sinatra_warn "The #{verb}_it method is deprecated; use #{verb} instead."
test_request('#{verb.upcase}', *args, &block)
make_request('#{verb.upcase}', *args, &block)
end
RUBY
end

View file

@ -32,9 +32,12 @@ end
#
def describe(*args, &block)
return super unless (name = args.first) && block
klass = Class.new(Test::Unit::TestCase) do
name = "#{name.gsub(/\W/, '')}Test"
Object.send :const_set, name, Class.new(Test::Unit::TestCase)
klass = Object.const_get(name)
klass.class_eval do
def self.it(name, &block)
define_method("test_#{name.gsub(/\W/,'_')}", &block)
define_method("test_#{name.gsub(/\W/,'_').downcase}", &block)
end
def self.xspecify(*args) end
def self.before(&block) define_method(:setup, &block) end