Class: Uspec::CLI
- Inherits:
-
Object
- Object
- Uspec::CLI
- Defined in:
- lib/uspec/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(paths) ⇒ CLI
constructor
A new instance of CLI.
- #paths ⇒ Object
- #run(path) ⇒ Object
- #run_paths ⇒ Object
Constructor Details
#initialize(paths) ⇒ CLI
Returns a new instance of CLI.
25 26 27 28 |
# File 'lib/uspec/cli.rb', line 25 def initialize paths @paths = paths @pwd = Pathname.pwd.freeze end |
Class Method Details
.invoke(args) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/uspec/cli.rb', line 16 def invoke args if (args & %w[-h --help -? /?]).empty? then run_specs args else usage end end |
.run_specs(paths) ⇒ Object
11 12 13 14 |
# File 'lib/uspec/cli.rb', line 11 def run_specs paths uspec_cli = self.new paths uspec_cli.run_paths end |
.usage ⇒ Object
6 7 8 9 |
# File 'lib/uspec/cli.rb', line 6 def usage warn "uspec - minimalistic ruby testing framework" warn "usage: #{File.basename $0} [<file_or_path>...]" end |
Instance Method Details
#paths ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/uspec/cli.rb', line 30 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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/uspec/cli.rb', line 46 def run path 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}:" Uspec::DSL.instance_eval(path.read, path.to_s) else warn "path not found: #{path}" end rescue LoadError => result formatter = Uspec::Formatter.new print ' -- FAILED TO LOAD TEST FILE DUE TO: ' Uspec::Stats.results << result puts formatter.colorize(result, result.backtrace) end |
#run_paths ⇒ Object
40 41 42 43 44 |
# File 'lib/uspec/cli.rb', line 40 def run_paths paths.each do |path| run @pwd.join path end end |