Sha256: 8676f47e50853a067705f9378d40edde491c6e6d1c6eb4f6863537134b7a44f3

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

require 'spec_helper'

#
# Specs for implemetned API endpoints. Only check response: OK or 404.
#

shared_examples_for :fail_on_random_url do |base|  
  RANDOM.each do |url|
    ep = "#{base}/#{url}"
    it "fails on #{ep} string" do
      get ep
      last_response.status.should be 404
    end
  end
end

shared_examples_for :respond_to_valid_url do |base, urls|
  urls.each do |url|
    ep = "#{base}/#{url}"
    it "responds to #{ep}" do
      get ep
      last_response.should be_ok
    end
  end
end

shared_examples_for :fail_on_bad_url do |url|
  before {  get url }
  it "fails on #{url}" do 
    last_response.status.should be 404
  end
end

describe Nagira do 
  
  set :environment, :test       # This should run only in test mode as it uses hardcoded host names
  include Rack::Test::Methods
  def app 
    @app ||= Nagira
  end
  
  context "API endpoints" do
    
    host = IMPLEMENTED[:hosts].first 

    context :top do 
      it_should_behave_like :respond_to_valid_url,  '', IMPLEMENTED[:top]
      it_should_behave_like :fail_on_random_url,    ''
    end
      

    context "/_status" do
      it_should_behave_like :respond_to_valid_url,  "/_status", IMPLEMENTED[:hosts]
      it_should_behave_like :respond_to_valid_url,  "/_status", IMPLEMENTED[:output] + ["_hosts"]
      it_should_behave_like :fail_on_random_url, '/_status'
    end

    context "/_status/:host" do
      it_should_behave_like :respond_to_valid_url,  "/_status/#{host}", IMPLEMENTED[:status]
      it_should_behave_like :fail_on_random_url,    "/_status/#{host}"

      context :unknown_host do
        it_should_behave_like :fail_on_bad_url,       '/_status/unknown_host'
        it_should_behave_like :fail_on_random_url,    "/_status/unknown_host"
      end

    end

  end                           # API endpoints

    
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nagira-0.2.12 spec/get/endpoints_spec.rb