#!/usr/bin/env ruby require 'specserv/rspec_adapter' require 'specserv/custom_exceptions' require 'sinatra' # possibly overkill, maybe just use thin or something? set :run, true # not sure about this, apparently Sinatra needs it to automatically launch a server before do @tester = Specserv::RSpecAdapter.new def set_spec_path (spec_path) @spec_path = "#{spec_path}.rb" end def spec_file_exists? File.exists?(@spec_path) end def run_tests @results = @tester.run @spec_path end def malformed_results? @results.nil? || @results.strip == "" end def respond_with_results @results end def respond_with_404 status 404 "Could not find a spec file called #{@spec_path} in #{Dir.pwd}" end def respond_with_500 status 500 "There was an error generating results for #{@spec_path}" end end ## Index Page ## get '/' do 'SpecServ Test Result Server' end ## Result Pages ## get "/*" do |path| set_spec_path( path ) begin raise Specserv::NoSpecFileError unless spec_file_exists? run_tests raise Specserv::MalformedResultsError if malformed_results? respond_with_results rescue Specserv::NoSpecFileError respond_with_404 rescue Specserv::MalformedResultsError respond_with_500 end end