Class: RSpec::Given::NaturalAssertion

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/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.



32
33
34
35
36
37
38
# File 'lib/rspec/given/natural_assertion.rb', line 32

def initialize(clause_type, block, example, line_extractor)
  @clause_type = clause_type
  @block = block
  @example = example
  @line_extractor = line_extractor
  set_file_and_line
end

Instance Method Details

#evaluate(expr_string) ⇒ Object



59
60
61
# File 'lib/rspec/given/natural_assertion.rb', line 59

def evaluate(expr_string)
  eval_in_context(expr_string)
end

#has_content?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/rspec/given/natural_assertion.rb', line 46

def has_content?
  assertion_sexp != VOID_SEXP
end

#messageObject



50
51
52
53
54
55
56
57
# File 'lib/rspec/given/natural_assertion.rb', line 50

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

#using_rspec_assertion?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/rspec/given/natural_assertion.rb', line 42

def using_rspec_assertion?
  using_should? || using_expect?
end