Sha256: f2d526ae8f14d3958688ac514f8e69f5436ba6a2a9a888001466cfcc543d5f6f

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 KB

Contents

  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
        JSON.parse(
          File.read("<%= "spec/support/examples/#{@resource.to_s.gsub("/", "")}_#{method.method}_request_body.json" %>"),
          symbolize_names: true
        )
      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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rambo_ruby-0.5.0 lib/rambo/rspec/templates/example_group_template.erb