Rubycut
Rubycut

Reputation: 1646

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?

Upvotes: 5

Views: 3073

Answers (3)

John Wilger
John Wilger

Reputation: 181

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.)

Upvotes: 14

Rubycut
Rubycut

Reputation: 1646

This is combination of options that must be used and then it works.

set :raise_errors, true
set :dump_errors, false
set :show_exceptions, false

Upvotes: 8

Shtirlic
Shtirlic

Reputation: 692

Maybe something with rspec config.backtrace_clean_patterns? There is link about it http://spin.atomicobject.com/2010/12/28/rspec-backtrace-filtering/

Upvotes: 0

Related Questions