Skip to content

Commit

Permalink
Allow headers to be set inside an example.
Browse files Browse the repository at this point in the history
Closes #86
  • Loading branch information
oestrich committed Oct 14, 2013
1 parent eac8414 commit 5545bbc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/rspec_api_documentation/dsl/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)|
Expand Down
13 changes: 13 additions & 0 deletions spec/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

2 comments on commit 5545bbc

@jejacks0n
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Yeah!

@jsmestad
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Please sign in to comment.