Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dump sinatra rack test exceptions to console?

While I develop, I would like to see sinatra app exceptions when running tests, cosider example:

require 'sinatra/base'

class ExceptionWeb < Sinatra::Base
  enable :raise_errors
  enable :dump_errors
  configure do 
    enable :dump_errors
  end
  get "/" do
    raise "hell"
    "ok"
  end
  def self.bad_method
    raise "bad method"    
  end
end


require 'rack/test'

describe 'The Web interface' do
  include Rack::Test::Methods

  def app
    ExceptionWeb
  end
  it "should error out" do
    get "/"
    #puts last_response.errors
    #ExceptionWeb.bad_method
    #last_response.should be_ok
  end
end

Following rspec code shows no exceptions at all, if I uncomment last_response, then I see something is wrong, but I don't see what was wrong.

But calling mad_method shows me exception.

And adding puts last_response.errors to every test doesn't look proper.

I tried sinatra config options raise_errors and dump_errors but that doesn't help me much.

Any ideas?

like image 552
Rubycut Avatar asked Mar 27 '12 13:03

Rubycut


1 Answers

Sinatra will behave the way you want it to by default when ENV['RACK_ENV'] is set to 'test'. Because of the way Sinatra works, you have to make sure this environment variable is set correctly before the interpreter loads the file in which your application is defined (i.e. it checks this when it creates the app class, not on each request.)

like image 101
John Wilger Avatar answered Sep 29 '22 16:09

John Wilger