Class: Turn::Controller

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

Overview

Controller

– TODO: Add support to test run loggging. ++

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#excludeObject

Files globs to specially exclude.



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

def exclude
  @exclude
end

#formatObject

Reporter type.



33
34
35
# File 'lib/turn/controller.rb', line 33

def format
  @format
end

#frameworkObject

Test framework, either :minitest or :testunit



48
49
50
# File 'lib/turn/controller.rb', line 48

def framework
  @framework
end

#liveObject

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



39
40
41
# File 'lib/turn/controller.rb', line 39

def live
  @live
end

#loadpathObject

Add these folders to the $LOAD_PATH.



27
28
29
# File 'lib/turn/controller.rb', line 27

def loadpath
  @loadpath
end

#logObject

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



42
43
44
# File 'lib/turn/controller.rb', line 42

def log
  @log
end

#patternObject

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



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

def pattern
  @pattern
end

#requiresObject

Libs to require when running tests.



30
31
32
# File 'lib/turn/controller.rb', line 30

def requires
  @requires
end

#runmodeObject

Run mode.



36
37
38
# File 'lib/turn/controller.rb', line 36

def runmode
  @runmode
end

#testsObject

File glob pattern of tests to run. Can be an array of files/globs.



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

def tests
  @tests
end

#verboseObject

Verbose output?



45
46
47
# File 'lib/turn/controller.rb', line 45

def verbose
  @verbose
end

Instance Method Details

#filesObject



115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/turn/controller.rb', line 115

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) }
  )
end

#live?Boolean

Returns:

  • (Boolean)


51
# File 'lib/turn/controller.rb', line 51

def live?    ; @live    ; end

#reporterObject

Select reporter based on output mode.



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/turn/controller.rb', line 143

def reporter
  @reporter ||= (
    case format
    when :marshal
      require 'turn/reporters/marshal_reporter'
      Turn::MarshalReporter.new($stdout)
    when :progress
      require 'turn/reporters/progress_reporter'
      Turn::ProgressReporter.new($stdout)
    when :dotted
      require 'turn/reporters/dot_reporter'
      Turn::DotReporter.new($stdout)
    when :pretty
      require 'turn/reporters/pretty_reporter'
      Turn::PrettyReporter.new($stdout)
    when :cue
      require 'turn/reporters/cue_reporter'
      Turn::CueReporter.new($stdout)
    else
      require 'turn/reporters/outline_reporter'
      Turn::OutlineReporter.new($stdout)
    end
  )
end

#runnerObject

# Insatance of Runner, selected based on format and runmode.



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/turn/controller.rb', line 169

def runner
  @runner ||= (
    case framework
    when :minitest
      require 'turn/runners/minirunner'
    else
      require 'turn/runners/testrunner'
    end

    case runmode
    when :marshal
      if framework == :minitest
        Turn::MiniRunner
      else
        Turn::TestRunner
      end
    when :solo
      require 'turn/runners/solorunner'
      Turn::SoloRunner
    when :cross
      require 'turn/runners/crossrunner'
      Turn::CrossRunner
    else
      if framework == :minitest
        Turn::MiniRunner
      else
        Turn::TestRunner
      end
    end
  )
end

#startObject



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

def start
  @files = nil  # reset files just in case

  if files.empty?
    $stderr.puts "No tests."
    return
  end

  testrun = runner.new(self)

  testrun.start
end

#verbose?Boolean

Returns:

  • (Boolean)


50
# File 'lib/turn/controller.rb', line 50

def verbose? ; @verbose ; end