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
- #die! ⇒ Object
- #exit_code ⇒ Object
- #handle_interrupt!(type = Interrupt) ⇒ Object
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
- #invoke ⇒ Object
- #parse_options(args) ⇒ Object
- #paths ⇒ Object
- #run(path) ⇒ Object
- #run_paths ⇒ Object
- #run_specs ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize(args) ⇒ CLI
Returns a new instance of CLI.
5 6 7 8 9 10 |
# File 'lib/uspec/cli.rb', line 5 def initialize args @paths = args @pwd = Pathname.pwd.freeze @stats = Uspec::Stats.new @harness = Uspec::Harness.new self end |
Instance Attribute Details
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
11 12 13 |
# File 'lib/uspec/cli.rb', line 11 def stats @stats end |
Instance Method Details
#die! ⇒ Object
50 51 52 53 |
# File 'lib/uspec/cli.rb', line 50 def die! puts @stats.summary exit exit_code end |
#exit_code ⇒ Object
32 33 34 |
# File 'lib/uspec/cli.rb', line 32 def exit_code [@stats.failure.size, 255].min end |
#handle_interrupt!(type = Interrupt) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/uspec/cli.rb', line 36 def handle_interrupt! type = Interrupt if SignalException === type || SystemExit === type then if type === Module then err = type msg = "signal" else err = type.class msg = type. end puts "Uspec received #{err} #{msg} - exiting!" die! end end |
#invoke ⇒ Object
26 27 28 29 30 |
# File 'lib/uspec/cli.rb', line 26 def invoke @paths run_specs die! end |
#parse_options(args) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/uspec/cli.rb', line 89 def args args.each_with_index do |arg, i| if arg == '--' then return args elsif arg == '--full_backtrace' then Uspec::Errors.full_backtrace! args.delete_at i elsif !(args & %w[-h --help -? /? -v --version]).empty? usage elsif arg[0] == ?- then warn "unknown option: #{arg}" args.delete_at i end end end |
#paths ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/uspec/cli.rb', line 55 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
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/uspec/cli.rb', line 73 def run path p, line = path.to_s.split(?:) path = Pathname.new p 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}:" harness.file_eval path, line else warn "path not found: #{path}" end end |
#run_paths ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/uspec/cli.rb', line 65 def run_paths = true paths.each do |path| run @pwd.join path end end |
#run_specs ⇒ Object
22 23 24 |
# File 'lib/uspec/cli.rb', line 22 def run_specs run_paths end |
#usage ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/uspec/cli.rb', line 13 def usage warn "uspec v#{::Uspec::VERSION} - minimalistic ruby testing framework" warn "usage: #{File.basename $0} [<file_or_path>...]" warn "" warn "\t\t--full_backtrace\tshow full backtrace" warn "\t\t--\t\t\tstop checking paths for options (good if a path begins with a dash)" exit 1 end |