Class: Lucid::CLI::Context
- Includes:
- Factory
- Defined in:
- lib/lucid/cli/context.rb
Instance Attribute Summary collapse
-
#out_stream ⇒ Object
readonly
Returns the value of attribute out_stream.
Instance Method Summary collapse
- #debug? ⇒ Boolean
-
#definition_context ⇒ Array
Returns all definition files that exist in the default or provided execution path.
- #definitions_path ⇒ Object
- #driver_file ⇒ Object
- #dry_run? ⇒ Boolean
- #establish_ast_walker(runtime) ⇒ Object
- #expand? ⇒ Boolean
- #filters ⇒ Object
- #formats ⇒ Object
- #formatter_instance(name) ⇒ Object
- #guess? ⇒ Boolean
-
#initialize(out_stream = STDOUT, err_stream = STDERR) ⇒ Context
constructor
A new instance of Context.
-
#library_context ⇒ Array
Returns all library files that exist in the default or provided library path.
- #library_path ⇒ Object
- #log ⇒ Object
- #matcher_type ⇒ Object
- #parse_options(args) ⇒ Object
-
#spec_context ⇒ Array
Returns all spec files that exist in the default or provided spec repository.
- #spec_location ⇒ Object
-
#spec_requires ⇒ Array
List of non-spec, executable files from all required locations.
- #spec_source ⇒ Object
- #spec_type ⇒ Object
- #steps_path ⇒ Object
- #strict? ⇒ Boolean
- #tag_expression ⇒ Object
- #testdefs ⇒ Object
- #verbose? ⇒ Boolean
- #wip? ⇒ Boolean
Methods included from Factory
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_stream ⇒ Object (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
40 41 42 |
# File 'lib/lucid/cli/context.rb', line 40 def debug? @options[:debug] end |
#definition_context ⇒ Array
Returns all definition files that exist in the default or provided execution path.
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_path ⇒ Object
196 197 198 |
# File 'lib/lucid/cli/context.rb', line 196 def definitions_path @options[:definitions_path] end |
#driver_file ⇒ Object
188 189 190 |
# File 'lib/lucid/cli/context.rb', line 188 def driver_file @options[:driver_file] end |
#dry_run? ⇒ Boolean
56 57 58 |
# File 'lib/lucid/cli/context.rb', line 56 def dry_run? @options[:dry_run] end |
#establish_ast_walker(runtime) ⇒ Object
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
60 61 62 |
# File 'lib/lucid/cli/context.rb', line 60 def @options[:expand] end |
#filters ⇒ Object
213 214 215 |
# File 'lib/lucid/cli/context.rb', line 213 def filters @options.filters end |
#formats ⇒ Object
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
52 53 54 |
# File 'lib/lucid/cli/context.rb', line 52 def guess? @options[:guess] end |
#library_context ⇒ Array
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.
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_path ⇒ Object
184 185 186 |
# File 'lib/lucid/cli/context.rb', line 184 def library_path @options[:library_path] end |
#log ⇒ Object
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_type ⇒ Object
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 (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_context ⇒ Array
Returns all spec files that exist in the default or provided spec repository.
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_location ⇒ Object
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_requires ⇒ Array
Returns 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_source ⇒ Object
221 222 223 |
# File 'lib/lucid/cli/context.rb', line 221 def spec_source @options[:spec_source] end |
#spec_type ⇒ Object
180 181 182 |
# File 'lib/lucid/cli/context.rb', line 180 def spec_type @options[:spec_types] end |
#steps_path ⇒ Object
192 193 194 |
# File 'lib/lucid/cli/context.rb', line 192 def steps_path @options[:steps_path] end |
#strict? ⇒ Boolean
44 45 46 |
# File 'lib/lucid/cli/context.rb', line 44 def strict? @options[:strict] end |
#tag_expression ⇒ Object
209 210 211 |
# File 'lib/lucid/cli/context.rb', line 209 def tag_expression Gherkin::TagExpression.new(@options[:tag_expressions]) end |
#testdefs ⇒ Object
64 65 66 |
# File 'lib/lucid/cli/context.rb', line 64 def testdefs @options[:testdefs] end |
#verbose? ⇒ Boolean
36 37 38 |
# File 'lib/lucid/cli/context.rb', line 36 def verbose? @options[:verbose] end |
#wip? ⇒ Boolean
48 49 50 |
# File 'lib/lucid/cli/context.rb', line 48 def wip? @options[:wip] end |