Skip to content

Commit bcf9378

Browse files
committed
Allow letting of headers
1 parent 8bf5784 commit bcf9378

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

lib/rspec_api_documentation/dsl/endpoint.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,15 @@ def params
6262
end
6363

6464
def headers
65-
example.metadata[:headers]
65+
return unless example.metadata[:headers]
66+
example.metadata[:headers].inject({}) do |hash, header|
67+
if header[1].is_a?(Symbol)
68+
hash[header[0]] = send(header[1]) if respond_to?(header[1])
69+
else
70+
hash[header[0]] = header[1]
71+
end
72+
hash
73+
end
6674
end
6775

6876
def method

spec/dsl_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,36 @@
436436
end
437437
end
438438
end
439+
440+
put "/orders" do
441+
header "Accept", :accept
442+
443+
let(:accept) { "application/json" }
444+
445+
it "should be sent with the request" do
446+
example.metadata[:headers].should == { "Accept" => :accept }
447+
end
448+
449+
it "should fill out into the headers" do
450+
headers.should == { "Accept" => "application/json" }
451+
end
452+
453+
context "nested headers" do
454+
header "Content-Type", "application/json"
455+
456+
it "does not affect the outer context's assertions" do
457+
headers.should == { "Accept" => "application/json", "Content-Type" => "application/json" }
458+
end
459+
end
460+
461+
context "header was not let" do
462+
header "X-My-Header", :my_header
463+
464+
it "should not be in the headers hash" do
465+
headers.should == { "Accept" => "application/json" }
466+
end
467+
end
468+
end
439469
end
440470
end
441471

0 commit comments

Comments
 (0)