Permalink
Browse files

Example spec showing custom request headers & response header matching.

  • Loading branch information...
1 parent daf5197 commit 9e616241f39d53cf25caf8294f452929aa9826a5 Martin Bilski committed Sep 5, 2011
Showing with 25 additions and 0 deletions.
  1. +25 −0 spec/examples/headers_spec.rb
@@ -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.