waterlink / spec2.cr

Enhanced `spec` testing library for [Crystal](http://crystal-lang.org/).
MIT License
103 stars 22 forks source link

Not able catch exception by raise_error. #19

Closed vjdhama closed 8 years ago

vjdhama commented 8 years ago

This is more of a question. I have this method i want to test.

module Test
  class InvalidPathException < Exception; end

  class Application
    def load
      raise Test::InvalidPathException.new
    end
  end
end

Now I wrote this spec.

Spec2.describe Test::Application do
  Spec2.describe "#load" do
    it "should raise error if path is not valid" do
      path = "wrong/path.yml"
      application = Test::Application.new("test", path)
      expect(application.load).to raise_error Test::InvalidPathException
    end
  end
end

I think this test should pass. But it doesn't. Am i doing something silly?

waterlink commented 8 years ago
expect {
  # .. code ..
}.to raise_error(...)
vjdhama commented 8 years ago

Aha. Don't know how i missed that.