diff --git a/lib/rspec_api_documentation/dsl/endpoint.rb b/lib/rspec_api_documentation/dsl/endpoint.rb index 00edbe30..1daeb7c1 100644 --- a/lib/rspec_api_documentation/dsl/endpoint.rb +++ b/lib/rspec_api_documentation/dsl/endpoint.rb @@ -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 diff --git a/spec/dsl_spec.rb b/spec/dsl_spec.rb index ca811826..c7a1420c 100644 --- a/spec/dsl_spec.rb +++ b/spec/dsl_spec.rb @@ -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