Sha256: fa68ca33a33e75ed2ffb0917e306b22b6bec276a53432f203a6e0599a67b6a6b

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

require 'bundler/setup'

require 'simplecov'
require 'coveralls'

SimpleCov.formatters = [
  Coveralls::SimpleCov::Formatter,
  SimpleCov::Formatter::HTMLFormatter,
]

SimpleCov.start do
  add_filter "/spec/"
end

require 'rspec'
require 'rack/test'
require 'rack/schema'
require "json"
require 'pry'

module SpecHelpers
  def echo(headers, body, status = 200)
    env = {
      'echo.body' => MultiJson.dump(body),
      'echo.headers' => headers,
      'echo.status' => status
    }
    get '/', {}, env
  end

  def headers
    @headers ||= {
      'Content-Type' => 'application/json'
    }
  end

  def schema_uri(name)
    "file://#{schema_file(name)}"
  end

  def schema_file(name)
    File.expand_path("../schemas/#{name}.json", __FILE__)
  end

  def described_by(uri, anchor = nil, collection = nil)
    header = "<#{uri}>; rel=\"describedby\""
    header.concat "; anchor=\"#{anchor}\"" if anchor
    header.concat "; collection=\"collection\"" if collection
    header
  end

  module EchoApp
    def self.call(env)
      body = [env['echo.body']] # body should respond to :each
      [env['echo.status'], env['echo.headers'], body]
    end
  end
end

RSpec.configure do |config|
  config.include Rack::Test::Methods
  config.include SpecHelpers
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-schema-0.7.0 spec/spec_helper.rb