Sha256: 5fe95309aca6e10eddb4cdc6f6798ba3f6c5e9cc637a6fb42d386a92221f7055

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

require File.dirname(__FILE__) + '/../../../spec_helper'

require 'rack/test'
require 'useless/doc/rack/subject'

describe Useless::Doc::Rack::Subject do
  include Rack::Test::Methods

  def app
    @app ||= lambda do |env|
      base_app = lambda do |env|
        [200, {'Content-Type' => 'text/plain'}, [env['useless.doc.subject']]]
      end

      env['useless.doc.url'] = 'some.api.com'
      Useless::Doc::Rack::Subject.new(base_app).call(env)
    end
  end

  it 'should retrieve the subject from the stub client in a non-production environment' do
    Useless::Doc::Client.stub.should_receive(:get).with('some.api.com').and_return('test subject')
    get 'some.doc.api.com'
    last_response.should be_ok
    last_response.body.should == 'test subject'
  end

  it 'should retrieve the subject from the standard client in a production environment' do
    begin
      ENV['RACK_ENV'] = 'production'
      Useless::Doc::Client.standard.should_receive(:get).with('some.api.com').and_return('production subject')
      get 'some.doc.api.com'
      last_response.should be_ok
      last_response.body.should == 'production subject'
    ensure
      ENV['RACK_ENV'] = 'test'
    end
  end

  it 'should return a 404 if no subject is returned' do
    Useless::Doc::Client.stub.should_receive(:get).with('some.api.com').and_return(nil)
    get 'some.doc.api.com'
    last_response.should be_not_found
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
useless-doc-0.4.0 spec/useless/doc/rack/subject_spec.rb
useless-doc-0.3.1 spec/useless/doc/rack/subject_spec.rb
useless-doc-0.3.0 spec/useless/doc/rack/subject_spec.rb