Class: Concordion::State

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/concordion/state.rb

Overview

Concordion State manages memory for Concordion specs as they are being parsed (e.g. when #var is declared in a spec, this class holds the memory reference).

Constant Summary collapse

@@TEXT_VAR =
"#TEXT"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utility

#concordion_arguments, #concordion_cmd_attr_exists?, #concordion_cmd_attr_for, #concordion_property_reference, #concordion_variable_name, #has_property_reference?, #instrumentation

Methods included from StringUtility

#assignment, #attr_writer_method?, #concordion_assignment, #concordion_method_name, #ends_in_empty_parens?, #escape_single_quotes, #has_arguments?, #has_assignment?, #is_direct_method_call?

Methods included from PluralToSingularUtility

#singular

Methods included from SnakeCaseUtility

#snake_case, #snake_cased_goldmaster_name, #snake_cased_test_name

Methods included from Constants

#concordion_command_attributes, #supported?

Constructor Details

#initializeState

Returns a new instance of State.



18
19
20
21
22
23
24
25
# File 'lib/concordion/state.rb', line 18

def initialize
  @memory = {}
  @lookahead_handler = Concordion::LookaheadHandler.new
  @verifier = Concordion::Verifier.new(self)
  @invoker = Concordion::Invoker.new(self)
  @binder = Concordion::Binder.new(self)
  set_variable(@@TEXT_VAR, @@TEXT_VAR)
end

Instance Attribute Details

#verification_variableObject (readonly)

Returns the value of attribute verification_variable.



16
17
18
# File 'lib/concordion/state.rb', line 16

def verification_variable
  @verification_variable
end

#verifierObject (readonly)

Returns the value of attribute verifier.



16
17
18
# File 'lib/concordion/state.rb', line 16

def verifier
  @verifier
end

Class Method Details

.TEXT_VARObject



13
14
15
# File 'lib/concordion/state.rb', line 13

def self.TEXT_VAR
  @@TEXT_VAR
end

Instance Method Details

#dereference(conc_call) ⇒ Object

Deferences concordion method calls. For example if memory held:

  • #foo => 12

  • #bar => 4

Then the following mappings hold:

  • #foo => 12

  • #foo.to_f => 12.0

  • method(#foo, #bar) => method(12, 4)



45
46
47
48
49
50
51
52
53
54
# File 'lib/concordion/state.rb', line 45

def dereference(conc_call)
  var_name = concordion_variable_name(conc_call)
  var = get_variable(var_name)

  if !has_property_reference?(conc_call)
    return var
  end

  var.send(concordion_property_reference(conc_call))
end

#evaluate(cpr, test_context, processor) ⇒ Object

Evaluate an expression

  1. Lookahead in the tag to see if needed variables are bound later.

  2. Bind a value to the variable from the spec, if needed. Returns early if bound successfully.

  3. Update the current value of the iterator for verification commands, if needed.

  4. Invoke the system under test

  5. Bind a value to the variable on the left hand side of an equation, if needed.

  6. Hand the system under test return value to the concordion invoker, which makes the assertion.



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/concordion/state.rb', line 63

def evaluate(cpr, test_context, processor)
  @lookahead_handler.handle_lookahead(cpr, test_context, processor)

  return { :result => true } if @binder.bind_if_set_command(cpr) 

  @verifier.update_if_verify_command(cpr)

  sut_rv = @invoker.invoke_sut(cpr, test_context)
  @binder.handle_assignment(cpr, sut_rv)
  conc_rv = @invoker.invoke_concordion(cpr, sut_rv)

  conc_rv
end

#get_variable(variable) ⇒ Object



31
32
33
# File 'lib/concordion/state.rb', line 31

def get_variable(variable)
  @memory[variable]
end

#set_variable(variable, value) ⇒ Object



27
28
29
# File 'lib/concordion/state.rb', line 27

def set_variable(variable, value)
  @memory[variable] = value
end