-
-
Save nilesmc/7160342 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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