Class: Given::NaturalAssertion

Inherits:
Object
  • Object
show all
Defined in:
lib/given/natural_assertion.rb

Constant Summary collapse

VOID_SEXP =
[:void_stmt]

Instance Method Summary collapse

Constructor Details

#initialize(clause_type, block, example, line_extractor) ⇒ NaturalAssertion

Returns a new instance of NaturalAssertion.



26
27
28
29
30
31
# File 'lib/given/natural_assertion.rb', line 26

def initialize(clause_type, block, example, line_extractor)
  @clause_type = clause_type
  @evaluator = Evaluator.new(example, block)
  @line_extractor = line_extractor
  set_file_and_line(block)
end

Instance Method Details

#has_content?Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/given/natural_assertion.rb', line 35

def has_content?
  return true unless NATURAL_ASSERTIONS_SUPPORTED
  assertion_sexp != VOID_SEXP
end

#messageObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/given/natural_assertion.rb', line 40

def message
  @output = "#{@clause_type} expression failed at #{source_line}\n"
  if NATURAL_ASSERTIONS_SUPPORTED
    @output << "Failing expression: #{source.strip}\n" if @clause_type != "Then"
    explain_failure
    display_pairs(expression_value_pairs)
    @output << "\n"
  else
    @output << "Failing expression (possibly truncated): #{source.strip}\n"
  end
  @output
end