Class: Lucid::Runtime

Inherits:
Object show all
Includes:
Formatter::Duration, InterfaceIO
Defined in:
lib/lucid/runtime.rb,
lib/lucid/runtime/facade.rb,
lib/lucid/runtime/results.rb,
lib/lucid/runtime/interface_io.rb,
lib/lucid/runtime/orchestrator.rb,
lib/lucid/runtime/specs_loader.rb

Defined Under Namespace

Modules: InterfaceIO Classes: Facade, Orchestrator, Results, SpecsLoader

Instance Attribute Summary collapse

Attributes included from InterfaceIO

#visitor

Instance Method Summary collapse

Methods included from InterfaceIO

#ask, #embed, #puts

Methods included from Formatter::Duration

#format_duration

Constructor Details

#initialize(configuration = Configuration.default) ⇒ Runtime

Returns a new instance of Runtime.



21
22
23
24
25
26
27
28
29
30
# File 'lib/lucid/runtime.rb', line 21

def initialize(configuration = Configuration.default)
  if defined?(Test::Unit::Runner)
    Test::Unit::Runner.module_eval("@@stop_auto_run = true")
  end

  @current_scenario = nil
  @configuration = Configuration.parse(configuration)
  @orchestrator = Orchestrator.new(self, @configuration)
  @results = Results.new(@configuration)
end

Instance Attribute Details

#orchestratorObject (readonly)

Returns the value of attribute orchestrator.



16
17
18
# File 'lib/lucid/runtime.rb', line 16

def orchestrator
  @orchestrator
end

#resultsObject (readonly)

Returns the value of attribute results.



16
17
18
# File 'lib/lucid/runtime.rb', line 16

def results
  @results
end

Instance Method Details

#after(scenario) ⇒ Object

:nodoc:



111
112
113
114
115
# File 'lib/lucid/runtime.rb', line 111

def after(scenario) #:nodoc:
  @current_scenario = nil
  return if @configuration.dry_run?
  @orchestrator.fire_hook(:after, scenario)
end

#after_stepObject

:nodoc:



117
118
119
120
# File 'lib/lucid/runtime.rb', line 117

def after_step #:nodoc:
  return if @configuration.dry_run?
  @orchestrator.fire_hook(:execute_after_step, @current_scenario)
end

#around(scenario, skip_hooks = false, &block) ⇒ Object

:nodoc:



89
90
91
92
93
94
95
96
# File 'lib/lucid/runtime.rb', line 89

def around(scenario, skip_hooks=false, &block) #:nodoc:
  if skip_hooks
    yield
    return
  end

  @orchestrator.around(scenario, block)
end

#before(scenario) ⇒ Object

:nodoc:



105
106
107
108
109
# File 'lib/lucid/runtime.rb', line 105

def before(scenario) #:nodoc:
  return if @configuration.dry_run? || @current_scenario
  @current_scenario = scenario
  @orchestrator.fire_hook(:before, scenario)
end

#before_and_after(scenario, skip_hooks = false) {|scenario| ... } ⇒ Object

:nodoc:

Yields:

  • (scenario)


98
99
100
101
102
103
# File 'lib/lucid/runtime.rb', line 98

def before_and_after(scenario, skip_hooks=false) #:nodoc:
  before(scenario) unless skip_hooks
  yield scenario
  after(scenario) unless skip_hooks
  @results.scenario_visited(scenario)
end

#configure(new_configuration) ⇒ Object

Used to take an existing runtime and change its configuration.



33
34
35
36
37
# File 'lib/lucid/runtime.rb', line 33

def configure(new_configuration)
  @configuration = Configuration.parse(new_configuration)
  @orchestrator.configure(@configuration)
  @results.configure(@configuration)
end

#doc_string(string_without_triple_quotes, content_type = '', line_offset = 0) ⇒ Object

Returns AST::DocString for string_without_triple_quotes.



164
165
166
# File 'lib/lucid/runtime.rb', line 164

def doc_string(string_without_triple_quotes, content_type='', line_offset=0)
  AST::DocString.new(string_without_triple_quotes,content_type)
end

#load_code_language(language) ⇒ Object



39
40
41
# File 'lib/lucid/runtime.rb', line 39

def load_code_language(language)
  @orchestrator.load_code_language(language)
end

#matcher_text(step_keyword, step_name, multiline_arg_class) ⇒ Object

:nodoc:



77
78
79
# File 'lib/lucid/runtime.rb', line 77

def matcher_text(step_keyword, step_name, multiline_arg_class) #:nodoc:
  @orchestrator.matcher_text(Gherkin::I18n.code_keyword_for(step_keyword), step_name, multiline_arg_class)
end

#runObject



43
44
45
46
47
48
49
50
51
# File 'lib/lucid/runtime.rb', line 43

def run
  load_execution_context
  fire_after_configuration_hook

  tdl_walker = @configuration.establish_tdl_walker(self)
  self.visitor = tdl_walker

  specs.accept(tdl_walker)
end

#scenarios(status = nil) ⇒ Object



61
62
63
# File 'lib/lucid/runtime.rb', line 61

def scenarios(status = nil)
  @results.scenarios(status)
end

#specs_pathsObject



53
54
55
# File 'lib/lucid/runtime.rb', line 53

def specs_paths
  @configuration.spec_source
end

#step_match(step_name, name_to_report = nil) ⇒ Object

:nodoc:



69
70
71
# File 'lib/lucid/runtime.rb', line 69

def step_match(step_name, name_to_report=nil) #:nodoc:
  @orchestrator.step_match(step_name, name_to_report)
end

#step_visited(step) ⇒ Object

:nodoc:



57
58
59
# File 'lib/lucid/runtime.rb', line 57

def step_visited(step) #:nodoc:
  @results.step_visited(step)
end

#steps(status = nil) ⇒ Object



65
66
67
# File 'lib/lucid/runtime.rb', line 65

def steps(status = nil)
  @results.steps(status)
end

#unknown_programming_language?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/lucid/runtime.rb', line 122

def unknown_programming_language?
  @orchestrator.unknown_programming_language?
end

#unmatched_step_definitionsObject



73
74
75
# File 'lib/lucid/runtime.rb', line 73

def unmatched_step_definitions
  @orchestrator.unmatched_step_definitions
end

#with_hooks(scenario, skip_hooks = false) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/lucid/runtime.rb', line 81

def with_hooks(scenario, skip_hooks=false)
  around(scenario, skip_hooks) do
    before_and_after(scenario, skip_hooks) do
      yield scenario
    end
  end
end

#write_testdefs_jsonObject



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/lucid/runtime.rb', line 126

def write_testdefs_json
  if(@configuration.testdefs)
    stepdefs = []
    @orchestrator.step_definitions.sort{|a,b| a.to_hash['source'] <=> a.to_hash['source']}.each do |stepdef|
      stepdef_hash = stepdef.to_hash
      steps = []
      specs.each do |feature|
        feature.feature_elements.each do |feature_element|
          feature_element.raw_steps.each do |step|
            args = stepdef.arguments_from(step.name)
            if(args)
              steps << {
                'name' => step.name,
                'args' => args.map do |arg|
                  {
                    'offset' => arg.offset,
                    'val' => arg.val
                  }
                end
              }
            end
          end
        end
      end
      stepdef_hash['file_colon_line'] = stepdef.file_colon_line
      stepdef_hash['steps'] = steps.uniq.sort {|a,b| a['name'] <=> b['name']}
      stepdefs << stepdef_hash
    end
    if !File.directory?(@configuration.testdefs)
      FileUtils.mkdir_p(@configuration.testdefs)
    end
    File.open(File.join(@configuration.testdefs, 'testdefs.json'), 'w') do |io|
      io.write(MultiJson.dump(stepdefs, :pretty => true))
    end
  end
end