Skip to content

Commit

Permalink
Allow letting of headers
Browse files Browse the repository at this point in the history
  • Loading branch information
oestrich committed Aug 24, 2012
1 parent 8bf5784 commit bcf9378
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/rspec_api_documentation/dsl/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ def params
end

def headers
example.metadata[:headers]
return unless example.metadata[:headers]
example.metadata[:headers].inject({}) do |hash, header|
if header[1].is_a?(Symbol)
hash[header[0]] = send(header[1]) if respond_to?(header[1])
else
hash[header[0]] = header[1]
end
hash
end
end

def method
Expand Down
30 changes: 30 additions & 0 deletions spec/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,36 @@
end
end
end

put "/orders" do
header "Accept", :accept

let(:accept) { "application/json" }

it "should be sent with the request" do
example.metadata[:headers].should == { "Accept" => :accept }
end

it "should fill out into the headers" do
headers.should == { "Accept" => "application/json" }
end

context "nested headers" do
header "Content-Type", "application/json"

it "does not affect the outer context's assertions" do
headers.should == { "Accept" => "application/json", "Content-Type" => "application/json" }
end
end

context "header was not let" do
header "X-My-Header", :my_header

it "should not be in the headers hash" do
headers.should == { "Accept" => "application/json" }
end
end
end
end
end

Expand Down

0 comments on commit bcf9378

Please sign in to comment.