12 Nov 2010, 19:42
Natal_pragsmall

Rodrigo Serradura (1 post)

Sinatra 1.x doesn’t use [require “sinatra/test/unit “]

But Rack::Test (http://www.sinatrarb.com/testing.html)

Because of this I want share the script wich I made.

PROJECT_PATH = File.join(File.dirname(__FILE__), '../')

require "rubygems"
require "test/unit"
require "rack/test"

require PROJECT_PATH + 'shortener'

class TestShortener < Test::Unit::TestCase

  include Rack::Test::Methods

  def app
    Sinatra::Application
  end

  configure do
    set :views => PROJECT_PATH + 'views'
  end

  def test_home_renders_content
    get '/'

    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

My english is not so good… So forgive me! :)

  You must be logged in to comment