Sha256: a7cfc6f502b1d4af7bd10c44c80134b90c03982f3d96f7cabcc097ead81323f7

Contents?: true

Size: 1.22 KB

Versions: 16

Compression:

Stored size: 1.22 KB

Contents

require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))

describe "error_handler plugin" do 
  it "executes only if error raised" do
    app(:bare) do
      plugin :error_handler

      error do |e|
        e.message
      end

      route do |r|
        r.on "a" do
          "found"
        end

        raise ArgumentError, "bad idea"
      end
    end

    body("/a").should == 'found'
    status("/a").should == 200
    body.should == 'bad idea'
    status.should == 500
  end

  it "can override status inside error block" do
    app(:bare) do
      plugin :error_handler do |e|
        response.status = 501
        e.message
      end

      route do |r|
        raise ArgumentError, "bad idea"
      end
    end

    status.should == 501
  end

  it "can set error via the plugin block" do
    app(:bare) do
      plugin :error_handler do |e|
        e.message
      end

      route do |r|
        raise ArgumentError, "bad idea"
      end
    end

    body.should == 'bad idea'
  end

  it "has default error handler also raise" do
    app(:bare) do
      plugin :error_handler

      route do |r|
        raise ArgumentError, "bad idea"
      end
    end

    proc{req}.should raise_error(ArgumentError)
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
roda-1.2.0 spec/plugin/error_handler_spec.rb
roda-1.1.0 spec/plugin/error_handler_spec.rb
roda-cj-1.0.5 spec/plugin/error_handler_spec.rb
roda-cj-1.0.4 spec/plugin/error_handler_spec.rb
roda-cj-1.0.3 spec/plugin/error_handler_spec.rb
roda-cj-1.0.2 spec/plugin/error_handler_spec.rb
roda-cj-1.0.1 spec/plugin/error_handler_spec.rb
roda-cj-1.0.0 spec/plugin/error_handler_spec.rb
roda-1.0.0 spec/plugin/error_handler_spec.rb
roda-cj-0.9.6 spec/plugin/error_handler_spec.rb
roda-cj-0.9.5 spec/plugin/error_handler_spec.rb
roda-cj-0.9.4 spec/plugin/error_handler_spec.rb
roda-cj-0.9.3 spec/plugin/error_handler_spec.rb
roda-cj-0.9.2 spec/plugin/error_handler_spec.rb
roda-cj-0.9.1 spec/plugin/error_handler_spec.rb
roda-0.9.0 spec/plugin/error_handler_spec.rb