Class: Turn::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/turn/configuration.rb

Overview

Central interface for Turn configuration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#excludeObject

List of file names or globs to exclude from tests list.



20
21
22
# File 'lib/turn/configuration.rb', line 20

def exclude
  @exclude
end

#formatObject

Reporter type.



37
38
39
# File 'lib/turn/configuration.rb', line 37

def format
  @format
end

#frameworkObject

Test framework, either ‘:minitest` or `:testunit`. TODO: Is this used any more?



60
61
62
# File 'lib/turn/configuration.rb', line 60

def framework
  @framework
end

#liveObject

Test against live install (i.e. Don’t use loadpath option)



47
48
49
# File 'lib/turn/configuration.rb', line 47

def live
  @live
end

#loadpathObject

Add these folders to the $LOAD_PATH.



31
32
33
# File 'lib/turn/configuration.rb', line 31

def loadpath
  @loadpath
end

#logObject

Log results? May be true/false or log file name. (TODO)



50
51
52
# File 'lib/turn/configuration.rb', line 50

def log
  @log
end

#markObject

Runtime threshold.



56
57
58
# File 'lib/turn/configuration.rb', line 56

def mark
  @mark
end

#matchcaseObject

Regexp pattern that all test cases must match to be eligible to run.



28
29
30
# File 'lib/turn/configuration.rb', line 28

def matchcase
  @matchcase
end

#modeObject

Report modifier. These act as decorators on the reporter class.



40
41
42
# File 'lib/turn/configuration.rb', line 40

def mode
  @mode
end

#naturalObject

Use natural language case names.



66
67
68
# File 'lib/turn/configuration.rb', line 66

def natural
  @natural
end

#patternObject

Regexp pattern that all test name’s must match to be eligible to run.



24
25
26
# File 'lib/turn/configuration.rb', line 24

def pattern
  @pattern
end

#requiresObject

Libs to require when running tests.



34
35
36
# File 'lib/turn/configuration.rb', line 34

def requires
  @requires
end

#runmodeObject

Run mode, which defaults to ‘nil`, but can also be `:solo`, `:cross` or `:marshal`.



44
45
46
# File 'lib/turn/configuration.rb', line 44

def runmode
  @runmode
end

#testsObject

List of if file names or glob pattern of tests to run.



17
18
19
# File 'lib/turn/configuration.rb', line 17

def tests
  @tests
end

#traceObject

Enable full backtrace



63
64
65
# File 'lib/turn/configuration.rb', line 63

def trace
  @trace
end

#verboseObject

Verbose output?



53
54
55
# File 'lib/turn/configuration.rb', line 53

def verbose
  @verbose
end

Instance Method Details

#ansi=(boolean) ⇒ Object



147
148
149
# File 'lib/turn/configuration.rb', line 147

def ansi=(boolean)
  @ansi = boolean ? true : false
end

#ansi?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/turn/configuration.rb', line 84

def ansi?
  @ansi
end

#decorate_reporter(reporter) ⇒ Object



212
213
214
215
216
217
218
# File 'lib/turn/configuration.rb', line 212

def decorate_reporter(reporter)
  if mode
    decorator_class.new(reporter)
  else
    reporter
  end
end

#decorator_classObject



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/turn/configuration.rb', line 221

def decorator_class
  return nil unless mode

  class_name = mode.to_s.capitalize + "Decorator"

  path = "turn/decorators/#{mode}_decorator"
  [File.expand_path('~'), Dir.pwd].each do |dir|
    file = File.join(dir, ".turn", "decorators", "#{mode}_reporter.rb")
    path = file if File.exist?(file)
  end

  require path

  Turn.const_get(class_name)
end

#environment_ansiObject



258
259
260
261
262
263
264
265
266
267
# File 'lib/turn/configuration.rb', line 258

def environment_ansi
  case ENV['ansi']
  when 'true','yes','on'
    true
  when 'false','no','off'
    false
  else
    nil
  end
end

#environment_formatObject



243
244
245
# File 'lib/turn/configuration.rb', line 243

def environment_format
  ENV['rpt']
end

#environment_modeObject



248
249
250
# File 'lib/turn/configuration.rb', line 248

def environment_mode
  ENV['mode']
end

#environment_traceObject



253
254
255
# File 'lib/turn/configuration.rb', line 253

def environment_trace
  (ENV['backtrace'] ? ENV['backtrace'].to_i : nil)
end

#filesObject

Test files.



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/turn/configuration.rb', line 168

def files
  @files ||= (
    fs = tests.map do |t|
      File.directory?(t) ? Dir[File.join(t, '**', '*')] : Dir[t]
    end
    fs = fs.flatten.reject{ |f| File.directory?(f) }

    ex = exclude.map do |x|
      File.directory?(x) ? Dir[File.join(x, '**', '*')] : Dir[x]
    end
    ex = ex.flatten.reject{ |f| File.directory?(f) }

    (fs - ex).uniq.map{ |f| File.expand_path(f) }
  ).flatten
end

#live?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/turn/configuration.rb', line 74

def live?
  @live
end

#natural?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/turn/configuration.rb', line 79

def natural?
  @natural
end

#reporterObject

Get selected reporter with any mode decorator.



190
191
192
# File 'lib/turn/configuration.rb', line 190

def reporter
  @reporter ||= decorate_reporter(reporter_class.new($stdout, reporter_options))
end

#reporter_classObject

Load reporter based on output mode and return its class.



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/turn/configuration.rb', line 195

def reporter_class
  rpt_format = format || :pretty
  class_name = rpt_format.to_s.capitalize + "Reporter"

  path = "turn/reporters/#{rpt_format}_reporter"

  [File.expand_path('~'), Dir.pwd].each do |dir|
    file = File.join(dir, ".turn", "reporters", "#{rpt_format}_reporter.rb")
    path = file if File.exist?(file)
  end

  require path

  Turn.const_get(class_name)
end

#reporter_optionsObject



238
239
240
# File 'lib/turn/configuration.rb', line 238

def reporter_options
  { :trace=>trace, :natural=>natural?, :verbose=>verbose?, :mark=>mark }
end

#suite_nameObject

TODO: Better name ?



185
186
187
# File 'lib/turn/configuration.rb', line 185

def suite_name
  files.map{ |path| File.dirname(path).sub(Dir.pwd+'/','') }.uniq.join(',')
end

#verbose?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/turn/configuration.rb', line 69

def verbose?
  @verbose
end