Module: Oktest
- Defined in:
- lib/oktest.rb
Defined Under Namespace
Modules: Color, SpecHelper, Util, UtilHelper
Classes: AssertionFailed, AssertionObject, BaseReporter, CompactReporter, Config, Context, Filter, FixtureManager, FixtureNotFoundError, Item, JsonMatcher, LoopedDependencyError, MainApp, Matcher, Node, OktestError, PlainReporter, QuietReporter, Reporter, Runner, ScopeNode, SimpleReporter, SkipException, SpecLeaf, TestGenerator, TodoException, TopicNode, Traverser, VerboseReporter, Visitor
Constant Summary
collapse
- VERSION =
'$Release: 1.5.0 $'.split()[1]
- FAIL_EXCEPTION =
FAIL_EXCEPTION = (defined?(MiniTest) ? MiniTest::Assertion :
defined?(Test::Unit) ? Test::Unit::AssertionFailedError : AssertionFailed)
AssertionFailed
- SKIP_EXCEPTION =
SkipException
- TODO_EXCEPTION =
TodoException
- THE_GLOBAL_SCOPE =
ScopeNode.new(nil, __FILE__)
- STATUSES =
[:PASS, :FAIL, :ERROR, :SKIP, :TODO]
- RUNNER_CLASS =
Runner
- THE_FIXTURE_MANAGER =
FixtureManager.new()
- REPORTER_CLASSES =
{
'verbose' => VerboseReporter, 'v' => VerboseReporter,
'simple' => SimpleReporter, 's' => SimpleReporter,
'compact' => CompactReporter, 'c' => CompactReporter,
'plain' => PlainReporter, 'p' => PlainReporter,
'quiet' => QuietReporter, 'q' => QuietReporter,
}
- DEFAULT_REPORTING_STYLE =
'verbose'
- FILTER_CLASS =
Filter
Class Method Summary
collapse
Class Method Details
.__scope(scope, &block) ⇒ Object
1235
1236
1237
1238
1239
1240
1241
1242
|
# File 'lib/oktest.rb', line 1235
def self.__scope(scope, &block) ! @_in_scope or
raise OktestError, "scope() and global_scope() are not nestable."
@_in_scope = true
scope.run_block_in_context_class(&block)
ensure
@_in_scope = false
end
|
.auto_run? ⇒ Boolean
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
|
# File 'lib/oktest.rb', line 2911
def self.auto_run?() exc = $!
return false if exc && !exc.is_a?(SystemExit)
return false unless THE_GLOBAL_SCOPE.has_child?
return Config.auto_run
end
|
.DEFAULT_REPORTING_STYLE=(style) ⇒ Object
2195
2196
2197
2198
2199
2200
2201
2202
|
# File 'lib/oktest.rb', line 2195
def self.DEFAULT_REPORTING_STYLE=(style)
REPORTER_CLASSES.key?(style) or
raise ArgumentError, "#{style}: Unknown reporting style."
remove_const :DEFAULT_REPORTING_STYLE
const_set :DEFAULT_REPORTING_STYLE, style
end
|
.filter(filter_obj) ⇒ Object
2558
2559
2560
|
# File 'lib/oktest.rb', line 2558
def self.filter(filter_obj)
filter_obj.filter_children!(THE_GLOBAL_SCOPE)
end
|
.global_scope(&block) ⇒ Object
1206
1207
1208
1209
1210
1211
1212
|
# File 'lib/oktest.rb', line 1206
def self.global_scope(&block)
self.__scope(THE_GLOBAL_SCOPE, &block)
return THE_GLOBAL_SCOPE
end
|
.main(argv = nil) ⇒ Object
2902
2903
2904
2905
|
# File 'lib/oktest.rb', line 2902
def self.main(argv=nil)
status = MainApp.main(argv)
exit(status)
end
|
.on_exit ⇒ Object
2907
2908
2909
|
# File 'lib/oktest.rb', line 2907
def self.on_exit() Oktest.main() if self.auto_run?()
end
|
.run(reporter: nil, style: nil) ⇒ Object
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
|
# File 'lib/oktest.rb', line 2205
def self.run(reporter: nil, style: nil)
style ||= DEFAULT_REPORTING_STYLE
klass = REPORTER_CLASSES[style] or
raise ArgumentError, "#{style.inspect}: unknown style."
reporter ||= klass.new
runner = RUNNER_CLASS.new(reporter)
runner.start()
! THE_GLOBAL_SCOPE.has_child? or "** internal error"
counts = reporter.counts
return counts[:FAIL] + counts[:ERROR]
end
|
.scope(tag: nil, &block) ⇒ Object
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
|
# File 'lib/oktest.rb', line 1214
def self.scope(tag: nil, &block)
location = caller_locations(1, 1).first
filename = location.path.to_s
if filename
pwd = Dir.pwd()
if filename.start_with?(pwd)
filename = filename[pwd.length..-1].sub(/\A\//, '')
elsif filename.start_with?('./')
filename = filename[2..-1]
end
end
scope = ScopeNode.new(THE_GLOBAL_SCOPE, filename, tag: tag)
self.__scope(scope, &block)
return scope
end
|
.topic(target, &block) ⇒ Object
1244
1245
1246
1247
1248
1249
|
# File 'lib/oktest.rb', line 1244
def self.topic(target, &block)
self.scope do
topic(target, &block)
end
end
|