File: any_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 (51 lines) | stat: -rw-r--r-- 1,605 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
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'teststrap'

context "An any assertion macro" do
  helper(:assert_any) do |o|
    Riot::Assertion.new("test") { o }.any
  end

  assertion_test_passes("when an array has items", "has items") { assert_any([1]) }
  assertion_test_fails("when an array is empty", "expected [] to have items") do
    assert_any([])
  end

  assertion_test_passes("when a hash has items", "has items") { assert_any({:name => 'washington'}) }
  assertion_test_fails("when a hash is empty", "expected {} to have items") do
    assert_any({})
  end
end

context "A negative, any assertion macro" do
  helper(:any) do |o|
    Riot::Assertion.new("test", true) { o }.any
  end

  asserts(":error when value is nil") do
    any(nil).run(Riot::Situation.new)[0] # No method any? on nil
  end.equals(:error)

  asserts(":pass when string is empty") do
    any("").run(Riot::Situation.new)
  end.equals([:pass, "has items"])

  asserts(":pass when array is empty") do
    any([]).run(Riot::Situation.new)
  end.equals([:pass, "has items"])

  asserts(":pass when hash is empty") do
    any({}).run(Riot::Situation.new)
  end.equals([:pass, "has items"])

  asserts(":fail when string is empty") do
    any("foo").run(Riot::Situation.new)[0..1]
  end.equals([:fail, %Q{expected "foo" not to have items}])

  asserts(":fail when array has items") do
    any([1,2]).run(Riot::Situation.new)[0..1]
  end.equals([:fail, %Q{expected [1, 2] not to have items}])

  asserts(":fail when hash has items") do
    any({"bar" => "baz"}).run(Riot::Situation.new)[0..1]
  end.equals([:fail, %Q{expected {"bar"=>"baz"} not to have items}])
end