Skip to content

Commit 5545bbc

Browse files
committed
Allow headers to be set inside an example.
Closes #86
1 parent eac8414 commit 5545bbc

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/rspec_api_documentation/dsl/endpoint.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ def params
5959
parameters
6060
end
6161

62+
def header(name, value)
63+
example.metadata[:headers] ||= {}
64+
example.metadata[:headers][name] = value
65+
end
66+
6267
def headers
6368
return unless example.metadata[:headers]
6469
example.metadata[:headers].inject({}) do |hash, (header, value)|

spec/dsl_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,19 @@
400400
end
401401
end
402402

403+
put "/orders" do
404+
context "setting header in example level" do
405+
before do
406+
header "Accept", "application/json"
407+
header "Content-Type", "application/json"
408+
end
409+
410+
it "adds to headers" do
411+
headers.should == { "Accept" => "application/json", "Content-Type" => "application/json" }
412+
end
413+
end
414+
end
415+
403416
put "/orders" do
404417
header "Accept", :accept
405418

0 commit comments

Comments
 (0)