summaryrefslogtreecommitdiff
path: root/pkgs/development/ruby-modules/testing/assertions.nix
blob: c8e7f9a05e94ede783a46aee2288238a4f521be6 (plain)
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
{ test, lib, ... }:
{
  equal =
    expected: actual:
    if actual == expected then
      (test.passed "= ${toString expected}")
    else
      (test.failed (
        "expected '${toString expected}'(${builtins.typeOf expected})"
        + " !=  "
        + "actual '${toString actual}'(${builtins.typeOf actual})"
      ));

  beASet =
    actual:
    if builtins.isAttrs actual then
      (test.passed "is a set")
    else
      (test.failed "is not a set, was ${builtins.typeOf actual}: ${toString actual}");

  haveKeys =
    expected: actual:
    if builtins.all (ex: builtins.any (ac: ex == ac) (builtins.attrNames actual)) expected then
      (test.passed "has expected keys")
    else
      (test.failed "keys differ: expected: [${lib.concatStringsSep ";" expected}] actual: [${lib.concatStringsSep ";" (builtins.attrNames actual)}]");

  havePrefix =
    expected: actual:
    if lib.hasPrefix expected actual then
      (test.passed "has prefix '${expected}'")
    else
      (test.failed "prefix '${expected}' not found in '${actual}'");
}