Sha256: 4d541ca7536977a01a91f77e0bc86f959e115038ba5092bb694f990de5d599d5

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

require 'teststrap'

class MyException < Exception; end

context "raises assertion:" do
  setup { Riot::Situation.new }

  should("raise an Exception") { raise Exception }.raises(Exception)

  should "fail if nothing was raised" do
    assertion = Riot::Assertion.new("foo", topic) { "barf" }
    assertion.raises(Exception)
    assertion.result.message
  end.matches(/should have raised Exception, but raised nothing/)

  should "fail if Exception classes do not match" do
    Riot::Assertion.new("foo", topic) { raise MyException }.raises(Exception)
  end.kind_of(Riot::Failure)

  should "pass if provided message equals expectation" do
    Riot::Assertion.new("foo", topic) { raise Exception, "I'm a nerd" }.raises(Exception, "I'm a nerd")
  end

  should "fail if provided message does not equal expectation" do
    Riot::Assertion.new("foo", topic) { raise(Exception, "I'm a nerd") }.raises(Exception, "But I'm not")
  end.kind_of(Riot::Failure)

  should "pass if provided message matches expectation" do
    Riot::Assertion.new("foo", topic) { raise(Exception, "I'm a nerd") }.raises(Exception, /nerd/)
  end

  should "fail if provided message does not match expectation" do
    Riot::Assertion.new("foo", topic) { raise(Exception, "I'm a nerd") }.raises(Exception, /foo/)
  end.kind_of(Riot::Failure)

  should "pass if provided message as array equals expectation" do
    Riot::Assertion.new("foo", topic) { raise(Exception, ["foo", "bar"]) }.raises(Exception, "foobar")
  end

  should "pass if provided message as array matches expectation" do
    Riot::Assertion.new("foo", topic) { raise(Exception, ["foo", "bar"]) }.raises(Exception, /oba/)
  end
end # raises assertion

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
riot-0.9.12 test/assertion_macros/assertion_macro_raises_test.rb