File: exists_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 (38 lines) | stat: -rw-r--r-- 1,091 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
37
38
require 'teststrap'

context "An exists assertion macro" do
  helper(:assert_exists) do |o|
    Riot::Assertion.new("test") { o }.exists.run(Riot::Situation.new)
  end

  asserts(":pass when result has a value") do
    assert_exists("foo")
  end.equals([:pass, "does exist"])

  asserts(":pass because empty string is considered a value") do
    assert_exists("")
  end.equals([:pass, "does exist"])

  asserts(":fail with message when value is nil") do
    assert_exists(nil)[0..1]
  end.equals([:fail, "expected a non-nil value"])
end # An exists assertion macro

context "A negative exists assertion macro" do
  helper(:assert_exists) do |o|
    Riot::Assertion.new("test", true) { o }.exists.run(Riot::Situation.new)
  end
  
  asserts(":fail when string") do
    assert_exists("foo")[0..1]
  end.equals([:fail, "expected a nil value"])

  asserts ":fail when string empty" do 
    assert_exists("")[0..1]
  end.equals([:fail, "expected a nil value"])

  asserts(":pass when nil") do 
    assert_exists(nil)
  end.equals([:pass, "does exist"])
  
end # A negative exists assertion macro