Skip to content

Commit

Permalink
Make the specs run under new miniunit stuff in Ruby 1.9
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rtomayko committed Feb 3, 2009
1 parent c8f1c7c commit 18dff71
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
16 changes: 8 additions & 8 deletions lib/sinatra/test.rb
Expand Up @@ -7,7 +7,7 @@ module Test

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)
Expand Down Expand Up @@ -38,14 +38,14 @@ def test_request(verb, path, *args)
@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
Expand Down Expand Up @@ -103,7 +103,7 @@ def param_string(value, prefix = nil)
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
Expand Down
7 changes: 5 additions & 2 deletions test/helper.rb
Expand Up @@ -32,9 +32,12 @@ class Sinatra::Base
#
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
Expand Down

0 comments on commit 18dff71

Please sign in to comment.