Skip to content

Commit

Permalink
Example spec showing custom request headers & response header matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Bilski authored and Martin Bilski committed Sep 5, 2011
1 parent daf5197 commit 9e61624
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions spec/examples/headers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require File.join(File.dirname(__FILE__), "../spec_helper")
require File.join(File.dirname(__FILE__), "sample_actions")

describe CustomHeader, :cramp => true do
def app
CustomHeader
end

it "should render the value of the custom header" do
get("/", :headers => {"Custom-Header" => "SAMPLE VALUE"}).should respond_with :body => /^SAMPLE VALUE$/
get("/", :headers => {"Custom-Header" => "SAMPLE VALUE"}).should respond_with :body => "SAMPLE VALUE"
end

it "should include the custom header in response headers" do
# Exact match using string & regex.
get("/", :headers => {"Custom-Header" => "SAMPLE VALUE"}).should respond_with :headers => {"Custom-Header" => "SAMPLE VALUE"}
get("/", :headers => {"Custom-Header" => "SAMPLE VALUE"}).should respond_with :headers => {"Custom-Header" => /^SAMPLE VALUE$/}

# Header field names are case insensitive - use regex match:
get("/", :headers => {"Custom-Header" => "SAMPLE VALUE"}).should respond_with :headers => {/Custom\-Header/i => "SAMPLE VALUE"}

# Negative match.
get("/", :headers => {"Custom-Header" => "SAMPLE VALUE"}).should_not respond_with :headers => {"Custom-Header" => "ANOTHER VALUE"}
end
end

0 comments on commit 9e61624

Please sign in to comment.