File: empty.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 (26 lines) | stat: -rw-r--r-- 824 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
module Riot
  # In the postive case, asserts the result of the test is empty.
  #
  #   asserts("a string") { "" }.empty
  #   asserts("an array") { [] }.empty
  #   asserts("a hash") { Hash.new }.empty
  #
  # In the negative case, asserts the result of the test is not empty.
  #
  #   denies("a string") { "foo" }.empty
  #   denies("an array") { [1] }.empty
  #   denies("a hash") { {:foo => "bar" } }.empty
  class EmptyMacro < AssertionMacro
    register :empty

    # (see Riot::AssertionMacro#evaluate)
    def evaluate(actual)
      actual.empty? ? pass(new_message.is_empty) : fail(expected_message(actual).to_be_empty)
    end

    # (see Riot::AssertionMacro#devaluate)
    def devaluate(actual)
      actual.empty? ? fail(expected_message(actual).to_not_be_empty) : pass(new_message.is_empty)
    end
  end
end