Sha256: 694b4311bede7a44bdcb9720da19d89ea27dbdb0c899c4f4c4869477f6b40dd8

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

require "spec_helper"

ENV["RACK_ENV"] = "test"

begin
  require "sinatra/base"
  require "rack/test"

  describe "Sinatra" do
    include Rack::Test::Methods


    class TestApp < Sinatra::Base
      get "/status.json" do
        content_type :json
        body Rapporteur.run.as_json.to_json
      end
    end


    def app
      TestApp
    end

    before do
      Rapporteur.add_check(Rapporteur::Checks::TimeCheck)
    end


    subject { get("/status.json") ; last_response }

    it 'responds with HTTP 200' do
      expect(subject.status).to(eq(200))
    end

    it 'responds with a JSON content header' do
      expect(subject.content_type).to(eq(Mime::JSON))
    end

    it 'responds with valid JSON' do
      expect { JSON.parse(subject.body) }.not_to(raise_error)
    end

    it 'contains the time in ISO8601' do
      allow(Time).to receive(:now).and_return(Time.gm(2013,8,23))
      expect(subject).to include_status_message('time', /^2013-08-23T00:00:00(?:.000)?Z$/)
    end

    context 'the response payload' do
      subject { get("/status.json") ; JSON.parse(last_response.body) }

      it 'does not contain errors' do
        expect(subject).not_to(have_key('errors'))
      end

    end
  end
rescue LoadError
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rapporteur-3.3.0 spec/requests/sinatra_spec.rb
rapporteur-3.2.0 spec/requests/sinatra_spec.rb