Class: Refute

Inherits:
Gloo::Core::Verb
  • Object
show all
Defined in:
lib/refute.rb

Overview

Refute that [it] is true. (Assert that [it] is false.)

Constant Summary collapse

KEYWORD =
'refute'.freeze
KEYWORD_SHORT =
'expect_not'.freeze
DEFAULT_MESSAGE =
'Refutation failed'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.doc_dataObject

Get the verb's documentation data.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/refute.rb', line 65

def self.doc_data
  {
    :name => KEYWORD,
    :shortcut => KEYWORD_SHORT,
    :description => 'Refute an expectation about the state or ' \
      'results. The verb looks at the value of it. If it is false, ' \
      'then the assertion passes, otherwise it fails.',
    :syntax => [ 'refute {optional expectation message}' ],
    :parameters => [
      "optional expectation message — A textual statement about " \
        "what was NOT expected. Optional. If none provided the " \
        "default \"#{DEFAULT_MESSAGE}\" will be shown."
    ],
    :result => 'Validates a negative assumption and reports failures (or success).',
    :examples => <<~EXAMPLES.strip
      refute [test] :
        description [string] : Refute an operation
        on_test [script] :
          eval false
          refute 'false should be false'
    EXAMPLES
  }
end

.keywordObject

Get the Verb's keyword.



14
15
16
# File 'lib/refute.rb', line 14

def self.keyword
  return KEYWORD
end

.keyword_shortcutObject

Get the Verb's keyword shortcut.



21
22
23
# File 'lib/refute.rb', line 21

def self.keyword_shortcut
  return KEYWORD_SHORT
end

Instance Method Details

#get_messageObject

Get the refutation message.



49
50
51
52
53
54
55
56
# File 'lib/refute.rb', line 49

def get_message
  if @tokens.token_count > 1
    expr = Gloo::Expr::Expression.new( @engine, @tokens.params )
    result = expr.evaluate
    return result
  end
  return DEFAULT_MESSAGE
end

#runObject

Run the verb.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/refute.rb', line 28

def run
  begin
    @engine.context_object.refute_count += 1
    if @engine.heap.it.is_false?
      # Refutation passes
      @engine.context_object.passed = true
      return true
    else
      # Refutation fails
      @engine.context_object.passed = false
      @engine.context_object.add_message(get_message)
      return false
    end
  rescue => ex
    @engine.log_exception ex
  end
end