Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c8481e8efbe2
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a5e42ccc08b1
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Jan 10, 2017

  1. Copy the full SHA
    514fed3 View commit details

Commits on Jan 11, 2017

  1. Merge pull request #3868 from kostya/spec_raise

    Spec: expect_raises return exception
    Martin Verzilli authored Jan 11, 2017
    Copy the full SHA
    a5e42cc View commit details
Showing with 18 additions and 0 deletions.
  1. +16 −0 spec/std/spec_spec.cr
  2. +2 −0 src/spec/expectations.cr
16 changes: 16 additions & 0 deletions spec/std/spec_spec.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
require "spec"

class SpecException < Exception
getter value : Int32

def initialize(@value, msg)
super(msg)
end
end

describe "Spec matchers" do
describe "should be_truthy" do
it "passes for true" do
@@ -77,6 +85,14 @@ describe "Spec matchers" do
end
end

describe "expect_raises" do
it "return exception" do
ex = expect_raises(SpecException) { raise SpecException.new(11, "O_o") }
ex.value.should eq 11
ex.message.should eq "O_o"
end
end

context "should work like describe" do
it "is true" do
true.should be_truthy
2 changes: 2 additions & 0 deletions src/spec/expectations.cr
Original file line number Diff line number Diff line change
@@ -274,6 +274,8 @@ module Spec
fail "expected {{klass.id}} with #{ %msg.inspect }, got #<#{ %ex.class }: #{ %ex_to_s }> with backtrace:\n#{backtrace}", {{file}}, {{line}}
end
end

%ex
rescue %ex
if %failed
raise %ex