Created
November 8, 2010 19:11
-
-
Save chischaschos/668111 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
test_app = lambda do |env| | |
[200, | |
{'Content-Type' => 'text/html', | |
'Content-Length' => '3'}, ['Yes']] | |
end | |
describe test_app, 'RackApp' do | |
it { should respond_to(:call) } | |
context '#call' do | |
let(:response) { subject.call({}) } | |
let(:http_status) { response[0].to_i } | |
let(:http_header) { response[1] } | |
let(:http_body) { response[2] } | |
it do | |
response.should be_an(Array) | |
response.should have_exactly(3).items | |
end | |
context 'response HTTP status' do | |
it do | |
http_status.should be_an(Integer) | |
http_status.should > 100 | |
end | |
end | |
context 'response HTTP headers' do | |
it do | |
http_header.should respond_to(:each) | |
http_header_string = '' | |
http_header.each do |key, value| | |
http_header_string << key | |
key.should be_a(String) | |
key.should_not eq('Status') | |
key.should_not =~ /:\n/ | |
key.should_not =~ /[-_]$/ | |
key.should =~ /^[a-zA-Z]{1}[\w]+/ | |
value.should be_a(String) | |
value.should =~ /[\n]*/ | |
value.should_not =~ /[\000-\037]/ | |
end | |
no_content_statuses = [204, 304, *(100...200)] | |
http_header_string.should include 'Content-Type' unless no_content_statuses.include? http_status | |
http_header_string.should include 'Content-Length' unless no_content_statuses.include? http_status | |
end | |
end | |
context 'response HTTP body' do | |
it "won't break in ruby 1.9" do | |
http_body.should_not be_a(String) | |
end | |
it do | |
http_body.should respond_to(:each) | |
http_body.each do |element| | |
element.should be_a(String) | |
element.to_path.should be_a(String) if element.respond_to? :path | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment