Class: Lucid::ContextLoader

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

Defined Under Namespace

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

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(context = Context.default) ⇒ ContextLoader

Returns a new instance of ContextLoader.



21
22
23
24
25
26
# File 'lib/lucid/context_loader.rb', line 21

def initialize(context = Context.default)
  @current_scenario = nil
  @context = Context.parse(context)
  @orchestrator = Orchestrator.new(self, @context)
  @results = Results.new(@context)
end

Instance Attribute Details

#orchestratorObject (readonly)

Returns the value of attribute orchestrator.



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

def orchestrator
  @orchestrator
end

#resultsObject (readonly)

Returns the value of attribute results.



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

def results
  @results
end

Instance Method Details

#after(scenario) ⇒ Object



108
109
110
111
112
# File 'lib/lucid/context_loader.rb', line 108

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

#after_stepObject

:nodoc:



114
115
116
117
# File 'lib/lucid/context_loader.rb', line 114

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

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



86
87
88
89
90
91
92
93
# File 'lib/lucid/context_loader.rb', line 86

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

  @orchestrator.around(scenario, block)
end

#before(scenario) ⇒ Object



102
103
104
105
106
# File 'lib/lucid/context_loader.rb', line 102

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

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

Yields:

  • (scenario)


95
96
97
98
99
100
# File 'lib/lucid/context_loader.rb', line 95

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

#configure(new_context) ⇒ Object

Used to take an existing Lucid operation context and change the configuration of that context.



30
31
32
33
34
# File 'lib/lucid/context_loader.rb', line 30

def configure(new_context)
  @context = Context.parse(new_context)
  @orchestrator.configure(@context)
  @results.configure(@context)
end

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



160
161
162
# File 'lib/lucid/context_loader.rb', line 160

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

#executeObject



40
41
42
43
44
45
46
47
48
# File 'lib/lucid/context_loader.rb', line 40

def execute
  load_execution_context
  fire_after_configuration_hook

  ast_walker = @context.establish_ast_walker(self)
  self.visitor = ast_walker

  load_spec_context.accept(ast_walker)
end

#load_code_language(language) ⇒ Object



36
37
38
# File 'lib/lucid/context_loader.rb', line 36

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

#matcher_text(step_keyword, step_name, multiline_arg_class) ⇒ Object



74
75
76
# File 'lib/lucid/context_loader.rb', line 74

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

#scenarios(status = nil) ⇒ Object



58
59
60
# File 'lib/lucid/context_loader.rb', line 58

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

#specs_pathsObject



50
51
52
# File 'lib/lucid/context_loader.rb', line 50

def specs_paths
  @context.spec_source
end

#step_match(step_name, name_to_report = nil) ⇒ Object



66
67
68
# File 'lib/lucid/context_loader.rb', line 66

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

#step_visited(step) ⇒ Object



54
55
56
# File 'lib/lucid/context_loader.rb', line 54

def step_visited(step)
  @results.step_visited(step)
end

#steps(status = nil) ⇒ Object



62
63
64
# File 'lib/lucid/context_loader.rb', line 62

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

#unknown_programming_language?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/lucid/context_loader.rb', line 119

def unknown_programming_language?
  @orchestrator.unknown_programming_language?
end

#unmatched_step_definitionsObject



70
71
72
# File 'lib/lucid/context_loader.rb', line 70

def unmatched_step_definitions
  @orchestrator.unmatched_step_definitions
end

#with_hooks(scenario, skip_hooks = false) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/lucid/context_loader.rb', line 78

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



123
124
125
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
# File 'lib/lucid/context_loader.rb', line 123

def write_testdefs_json
  if(@context.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?(@context.testdefs)
      FileUtils.mkdir_p(@context.testdefs)
    end
    File.open(File.join(@context.testdefs, 'testdefs.json'), 'w') do |io|
      io.write(MultiJson.dump(stepdefs, :pretty => true))
    end
  end
end