Class: Uspec::CLI
- Inherits:
-
Object
- Object
- Uspec::CLI
- Defined in:
- lib/uspec/cli.rb
Instance Attribute Summary collapse
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Instance Method Summary collapse
- #exit_code ⇒ Object
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
- #invoke ⇒ Object
- #paths ⇒ Object
- #run(path) ⇒ Object
- #run_paths ⇒ Object
- #run_specs ⇒ Object
- #usage ⇒ Object
Constructor Details
Instance Attribute Details
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
13 14 15 |
# File 'lib/uspec/cli.rb', line 13 def stats @stats end |
Instance Method Details
#exit_code ⇒ Object
31 32 33 |
# File 'lib/uspec/cli.rb', line 31 def exit_code [@stats.failure.size, 255].min end |
#invoke ⇒ Object
25 26 27 28 29 |
# File 'lib/uspec/cli.rb', line 25 def invoke run_specs puts @stats.summary exit exit_code end |
#paths ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/uspec/cli.rb', line 35 def paths if @paths.empty? then ['spec', 'uspec', 'test'].each do |path| @paths << path if Pathname.new(path).directory? end end @paths end |
#run(path) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/uspec/cli.rb', line 51 def run path spec = nil if path.directory? then Pathname.glob(path.join('**', '**_spec.rb')).each do |spec| run spec end elsif path.exist? then puts "#{path.basename path.extname}:" dsl.instance_eval(path.read, path.to_s) else warn "path not found: #{path}" end rescue Exception => error error_file, error_line, _ = error.backtrace.first.split ?: = <<-MSG #{error.class} : #{error.} Uspec encountered an error when loading a test file. This is probably a typo in the test file or the file it is testing. If you think this is a bug in Uspec please report it: https://github.com/acook/uspec/issues/new Error occured when loading test file `#{spec || path}`. The origin of the error may be in file `#{error_file}` on line ##{error_line}. \t#{error.backtrace[0,3].join "\n\t"} MSG puts warn stats.failure << Uspec::Result.new(, error, caller) end |
#run_paths ⇒ Object
45 46 47 48 49 |
# File 'lib/uspec/cli.rb', line 45 def run_paths paths.each do |path| run @pwd.join path end end |
#run_specs ⇒ Object
21 22 23 |
# File 'lib/uspec/cli.rb', line 21 def run_specs run_paths end |