Skip to content

Instantly share code, notes, and snippets.

@Auraelius
Created October 23, 2013 21:15
Show Gist options
  • Save Auraelius/7126869 to your computer and use it in GitHub Desktop.
Save Auraelius/7126869 to your computer and use it in GitHub Desktop.
A sample sinatra application for code challenge 3
# sample/sample_app.rb
require 'sinatra'
require 'pry'
# We us "classic" mode where you don't actually see the class
# inheriting from Sinatra::Base and you don't start the app with
# rackup. This makes the object structure less obvious but lets
# Sinatra do more of the behind-the-scenes
get '/' do
# "Hello, World!"
end
post '/' do
# "Caught a post"
end
# sample/test/sample_test.rb
require './sample_test_helper.rb'
class MyTest < MiniTest::Unit::TestCase
include Rack::Test::Methods
def app
Sinatra::Application
end
def test_hello_world
get '/'
assert last_response.ok?
assert_equal "Hello, World!", last_response.body
end
def test_post
post '/'
assert last_response.ok?
assert_equal "Caught a post", last_response.body
end
end
# sample/test/sample_test_helper.rb
ENV['RACK_ENV'] = 'test'
require 'minitest/autorun'
require 'rack/test'
require '../sample_app.rb'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment