01 Jul 2010, 00:30
Generic-user-small

Pierre Jacomet (2 posts)

Hi, I was tinkering with this, and the code included in the zip file works only with Sinatra 0.9. For Sinatra 1.0, the following is the code that will run. I annotated the changes:

require 'rubygems'
#
# Instead of require sinatra/test/unit, you need the next two:
#
require 'test/unit'
require 'rack/test'

require File.join(File.dirname(__FILE__), '..', 'shortener')

class TestShortener < Test::Unit::TestCase
  #
  # You also need to include the Rack test methods mixin
  # and define the app method.
  #
  include Rack::Test::Methods
  def app
    Sinatra::Application
  end

  configure do
    set :views => File.join(File.dirname(__FILE__), '..',
'views')
  end

  def test_home_renders_content
    get '/'
    
    #
    # Here and in all occurrences of @response, I had to substitute
    # for last_response
    #
    assert_equal 200, last_response.status
    assert last_response.body.length > 0
  end
  
  def test_shorten_redirects_to_info
    post '/shorten', {:url => 'example.com'}
    assert_equal 302, last_response.status
    assert_match %r{/info/.*}, last_response['Location']
  end
  
end
  You must be logged in to comment