Class: Lucid::CLI::Context

Inherits:
Object show all
Includes:
Factory
Defined in:
lib/lucid/cli/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Factory

#create_object_of

Constructor Details

#initialize(out_stream = STDOUT, err_stream = STDERR) ⇒ Context

Returns a new instance of Context.



16
17
18
19
20
# File 'lib/lucid/cli/context.rb', line 16

def initialize(out_stream = STDOUT, err_stream = STDERR)
  @out_stream = out_stream
  @err_stream = err_stream
  @options = Options.new(@out_stream, @err_stream, :default_profile => 'default')
end

Instance Attribute Details

#out_streamObject (readonly)

Returns the value of attribute out_stream.



14
15
16
# File 'lib/lucid/cli/context.rb', line 14

def out_stream
  @out_stream
end

Instance Method Details

#debug?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/lucid/cli/context.rb', line 40

def debug?
  @options[:debug]
end

#definition_contextArray

Returns all definition files that exist in the default or provided execution path.

Returns:

  • (Array)

    executable files outside of the library path

See Also:

  • Lucid::ContextLoader.load_execution_context


113
114
115
116
117
118
119
120
121
# File 'lib/lucid/cli/context.rb', line 113

def definition_context
  definition_files = spec_requires.reject { |f| f =~ %r{#{library_path}} }
  log.info("Definition Files:\n#{definition_files}")

  non_test_definitions = spec_requires.reject { |f| f =~ %r{#{steps_path}|#{library_path}} }
  log.info("Non-Test Definition Files:\n#{non_test_definitions}")

  @options[:dry_run] ? definition_files - non_test_definitions : definition_files
end

#definitions_pathObject



196
197
198
# File 'lib/lucid/cli/context.rb', line 196

def definitions_path
  @options[:definitions_path]
end

#driver_fileObject



188
189
190
# File 'lib/lucid/cli/context.rb', line 188

def driver_file
  @options[:driver_file]
end

#dry_run?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/lucid/cli/context.rb', line 56

def dry_run?
  @options[:dry_run]
end

#establish_ast_walker(runtime) ⇒ Object

See Also:

  • Lucid::ContextLoader.execute


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

def establish_ast_walker(runtime)
  Lucid::AST::Walker.new(runtime, formatters(runtime), self)
end

#expand?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/lucid/cli/context.rb', line 60

def expand?
  @options[:expand]
end

#filtersObject



213
214
215
# File 'lib/lucid/cli/context.rb', line 213

def filters
  @options.filters
end

#formatsObject



217
218
219
# File 'lib/lucid/cli/context.rb', line 217

def formats
  @options[:formats]
end

#formatter_instance(name) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/lucid/cli/context.rb', line 77

def formatter_instance(name)
  if lucid_format = Options::LUCID_FORMATS[name]
    create_object_of(lucid_format[0])
  else
    create_object_of(name)
  end
end

#guess?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/lucid/cli/context.rb', line 52

def guess?
  @options[:guess]
end

#library_contextArray

Returns all library files that exist in the default or provided library path. During a dry run, the driver file will not be returned as part of the executing context.

Returns:

  • (Array)

    valid executable files in the library path

See Also:

  • Lucid::ContextLoader.load_execution_context


129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/lucid/cli/context.rb', line 129

def library_context
  library_files = spec_requires.select { |f| f =~ %r{#{library_path}} }
  log.info("(Library Context) Library Files:\n#{library_files}")

  driver = library_files.select {|f| f =~ %r{#{driver_file}} }
  log.info("(Library Context) Driver File:\n#{driver}")

  non_driver_files = library_files - driver
  log.info("(Library Context) Non-Driver Files:\n#{non_driver_files}")

  @options[:dry_run] ? non_driver_files : driver + non_driver_files
end

#library_pathObject



184
185
186
# File 'lib/lucid/cli/context.rb', line 184

def library_path
  @options[:library_path]
end

#logObject



200
201
202
203
204
205
206
207
# File 'lib/lucid/cli/context.rb', line 200

def log
  logger = Logger.new(@out_stream)
  logger.formatter = LogFormatter.new
  logger.level = Logger::WARN
  logger.level = Logger::INFO  if self.verbose?
  logger.level = Logger::DEBUG if self.debug?
  logger
end

#matcher_typeObject



68
69
70
# File 'lib/lucid/cli/context.rb', line 68

def matcher_type
  @options[:matcher_type] || :regexp
end

#parse_options(args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lucid/cli/context.rb', line 22

def parse_options(args)
  @args = args
  @options.parse(args)
  log.debug('Options:')
  log.debug(@options)

  set_formatter
  raise('You cannot use both --strict and --wip tags.') if strict? && wip?

  @options[:tag_expression] = Gherkin::TagExpression.new(@options[:tag_expressions])

  set_environment_variables
end

#spec_contextArray

Returns all spec files that exist in the default or provided spec repository.

Returns:

  • (Array)

    spec files from the repo

See Also:

  • RepoRunner.load_spec_context


147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/lucid/cli/context.rb', line 147

def spec_context
  files = specs_path(spec_source).map do |path|
    path = path.gsub(/\\/, '/')
    path = path.chomp('/')

    files_to_sort = []

    if File.directory?(path)
      spec_type.each do |type|
        files_to_sort << Dir["#{path}/**/*.#{type}"].sort
      end

      files_to_sort
    elsif path[0..0] == '@' and # @listfile.txt
      File.file?(path[1..-1]) # listfile.txt is a file
      IO.read(path[1..-1]).split
    else
      path
    end
  end.flatten.uniq

  extract_excluded_files(files)

  files
end

#spec_locationObject



173
174
175
176
177
178
# File 'lib/lucid/cli/context.rb', line 173

def spec_location
  dirs = spec_source.map { |f| File.directory?(f) ? f : File.dirname(f) }.uniq
  dirs.delete('.') unless spec_source.include?('.')

  specs_path(dirs)
end

#spec_requiresArray

Returns list of non-spec, executable files from all required locations.

Returns:

  • (Array)

    list of non-spec, executable files from all required locations



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/lucid/cli/context.rb', line 86

def spec_requires
  requires = @options[:require].empty? ? require_dirs : @options[:require]

  files = requires.map do |path|
    path = path.gsub(/\\/, '/')
    path = path.gsub(/\/$/, '')
    File.directory?(path) ? Dir["#{path}/**/*"] : path
  end.flatten.uniq

  extract_excluded_files(files)

  files.reject! {|f| !File.file?(f)}

  spec_type.each do |type|
    files.reject! {|f| File.extname(f) == ".#{type}" }
  end

  files.reject! {|f| f =~ /^http/}

  files.sort
end

#spec_sourceObject



221
222
223
# File 'lib/lucid/cli/context.rb', line 221

def spec_source
  @options[:spec_source]
end

#spec_typeObject



180
181
182
# File 'lib/lucid/cli/context.rb', line 180

def spec_type
  @options[:spec_types]
end

#steps_pathObject



192
193
194
# File 'lib/lucid/cli/context.rb', line 192

def steps_path
  @options[:steps_path]
end

#strict?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/lucid/cli/context.rb', line 44

def strict?
  @options[:strict]
end

#tag_expressionObject



209
210
211
# File 'lib/lucid/cli/context.rb', line 209

def tag_expression
  Gherkin::TagExpression.new(@options[:tag_expressions])
end

#testdefsObject



64
65
66
# File 'lib/lucid/cli/context.rb', line 64

def testdefs
  @options[:testdefs]
end

#verbose?Boolean

Returns:

  • (Boolean)


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

def verbose?
  @options[:verbose]
end

#wip?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/lucid/cli/context.rb', line 48

def wip?
  @options[:wip]
end