describe "<%= @resource.to_s %>" do let(:route) { "<%= @resource.to_s %>" } <%- @resource.http_methods.each do |method| %> describe "<%= method.method.upcase %>" do <% if method.headers %>let(:headers) do <% headers = method.headers.pretty.split("\n")[1..-2] %> { <%= headers.join(",\n ") %> } end<% end %><% if method.request_body %> let(:request_body) do File.read("<%= "spec/support/examples/#{@resource.to_s.gsub("/", "")}_#{method.method}_request_body.json" %>") end<% end %><% if has_schema = method.responses.first.bodies.first.schema %> let(:response_schema) do File.read("<%= "spec/support/examples/#{@resource.to_s.gsub("/", "")}_#{method.method}_response_schema.json" %>") end<% else %> let(:response_body) do<% body = method.responses.first.bodies.first.example.split("\n") %> File.read("<%= "spec/support/examples/#{@resource.to_s.gsub("/", "")}_#{method.method}_response_body.json" %>") end<% end %> let(:output_file) do "<%= "spec/contract/output/#{@resource.to_s.gsub("/", "")}_#{method.method}_response.json" %>" end it "<%= method.description && method.description.downcase || "#{method.method}s the resource" %>" do <%= method.method %> route<% if method.request_body %>, request_body<% end %><% if method.headers %>, headers<% end %> File.open(output_file, "w+") {|file| file.puts JSON.pretty_generate(JSON.parse(last_response.body)) } expect(last_response.body).to <%= has_schema ? "match_schema response_schema" : "eql response_body" %> end it "returns status <%= method.responses.first.status_code %>" do <%= method.method %> route<% if method.request_body %>, request_body<% end %><% if method.headers %>, headers<% end %> expect(last_response.status).to eql <%= method.responses.first.status_code %> end end<%- end %> end