Class: Uspec::Exec

Inherits:
Object
  • Object
show all
Defined in:
lib/uspec/exec.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths) ⇒ Exec

Returns a new instance of Exec.



17
18
19
20
# File 'lib/uspec/exec.rb', line 17

def initialize paths
  @paths = paths
  @pwd = Pathname.pwd.freeze
end

Class Method Details

.run_specs(paths) ⇒ Object



11
12
13
14
# File 'lib/uspec/exec.rb', line 11

def run_specs paths
  uspec_exec = self.new paths
  uspec_exec.run_paths
end

.usageObject



6
7
8
9
# File 'lib/uspec/exec.rb', line 6

def usage
  warn "uspec - minimalistic ruby testing framework"
  warn "usage: #{File.basename $0} [<file_or_path>...]"
end

Instance Method Details

#pathsObject



22
23
24
25
26
27
28
29
30
# File 'lib/uspec/exec.rb', line 22

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



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/uspec/exec.rb', line 38

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
end

#run_pathsObject



32
33
34
35
36
# File 'lib/uspec/exec.rb', line 32

def run_paths
  paths.each do |path|
    run @pwd.join path
  end
end