File: negative_assertion_test.rb

package info (click to toggle)
ruby-riot 0.12.7-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 512 kB
  • sloc: ruby: 2,557; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 1,310 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'teststrap'

context "A negative assertion test" do

  helper(:negative_assertion) do |definition|
    Riot::Assertion.new("foo", true) { definition }
  end

  asserts("response when evaluated with false result") do
    negative_assertion(false).run(Riot::Situation.new)
  end.equals([:pass, ""])
  
  asserts("response when evaluated with nil result") do
    negative_assertion(false).run(Riot::Situation.new)
  end.equals([:pass, ""])
  
  asserts("response when evaluated with true result") do
    negative_assertion(true).run(Riot::Situation.new)
  end.equals([:fail, "Expected non-true but got true instead", nil, nil])

  asserts("response when evaluated with \"bar\" result") do
    negative_assertion("bar").run(Riot::Situation.new)
  end.equals([:fail, "Expected non-true but got \"bar\" instead", nil, nil])

  asserts("response when evaluated with 0 result") do
    negative_assertion(0).run(Riot::Situation.new)
  end.equals([:fail, "Expected non-true but got 0 instead", nil, nil])

  helper(:big_exception) { @exception ||= Exception.new("blah") }

  asserts("response when evaluation errors") do
    exception = big_exception # :\
    Riot::Assertion.new("foo", true) { raise exception }.run(Riot::Situation.new)
  end.equals { [:error, big_exception] }

end # A negative assertion test