From 5545bbc59a35d001f363b5582c42cf42c2a7db56 Mon Sep 17 00:00:00 2001 From: Eric Oestrich Date: Mon, 14 Oct 2013 17:05:50 -0400 Subject: [PATCH] Allow headers to be set inside an example. Closes #86 --- lib/rspec_api_documentation/dsl/endpoint.rb | 5 +++++ spec/dsl_spec.rb | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/rspec_api_documentation/dsl/endpoint.rb b/lib/rspec_api_documentation/dsl/endpoint.rb index 222392c7..f5fcc0c2 100644 --- a/lib/rspec_api_documentation/dsl/endpoint.rb +++ b/lib/rspec_api_documentation/dsl/endpoint.rb @@ -59,6 +59,11 @@ def params parameters end + def header(name, value) + example.metadata[:headers] ||= {} + example.metadata[:headers][name] = value + end + def headers return unless example.metadata[:headers] example.metadata[:headers].inject({}) do |hash, (header, value)| diff --git a/spec/dsl_spec.rb b/spec/dsl_spec.rb index 207e9d6f..03c9e49d 100644 --- a/spec/dsl_spec.rb +++ b/spec/dsl_spec.rb @@ -400,6 +400,19 @@ end end + put "/orders" do + context "setting header in example level" do + before do + header "Accept", "application/json" + header "Content-Type", "application/json" + end + + it "adds to headers" do + headers.should == { "Accept" => "application/json", "Content-Type" => "application/json" } + end + end + end + put "/orders" do header "Accept", :accept