Created
April 5, 2012 20:10
-
-
Save myronmarston/2313727 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
require 'sinatra/base' | |
require 'json' | |
class MyApp < Sinatra::Base | |
before { content_type "application/json;charset=utf-8" } | |
not_found { JSON.dump("error" => "Not Found") } | |
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
source 'https://rubygems.org' | |
gem 'rack-test' | |
gem 'sinatra' |
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
GEM | |
remote: https://rubygems.org/ | |
specs: | |
rack (1.4.1) | |
rack-protection (1.2.0) | |
rack | |
rack-test (0.6.1) | |
rack (>= 1.0) | |
sinatra (1.3.2) | |
rack (~> 1.3, >= 1.3.6) | |
rack-protection (~> 1.2) | |
tilt (~> 1.3, >= 1.3.3) | |
tilt (1.3.3) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
rack-test | |
sinatra |
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
➜ sinatra_example RACK_ENV=test ruby test.rb | |
Run options: | |
# Running tests: | |
. | |
Finished tests in 0.019838s, 50.4083 tests/s, 100.8166 assertions/s. | |
1 tests, 2 assertions, 0 failures, 0 errors, 0 skips | |
➜ sinatra_example ruby test.rb | |
Run options: | |
# Running tests: | |
F | |
Finished tests in 0.022823s, 43.8154 tests/s, 87.6309 assertions/s. | |
1) Failure: | |
test_not_found(MyAppTest) [test.rb:15]: | |
<"application/json;charset=utf-8"> expected but was | |
<"text/html;charset=utf-8">. | |
1 tests, 2 assertions, 1 failures, 0 errors, 0 skips | |
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
require 'test/unit' | |
require 'rack/test' | |
require_relative 'app' | |
class MyAppTest < Test::Unit::TestCase | |
include Rack::Test::Methods | |
def app | |
MyApp.new | |
end | |
def test_not_found | |
get '/not_found' | |
assert_equal 404, last_response.status | |
assert_equal 'application/json;charset=utf-8', last_response.headers['Content-Type'] | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment