Class: Guard::RebarEunit

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/rebar-eunit.rb

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = {}) ⇒ RebarEunit

Returns a new instance of RebarEunit.



6
7
8
9
# File 'lib/guard/rebar-eunit.rb', line 6

def initialize(watchers = [], options = {})
  super
  options[:skip_deps] = true if options[:skip_deps].nil?
end

Instance Method Details

#directory_nameObject



55
56
57
# File 'lib/guard/rebar-eunit.rb', line 55

def directory_name
  "#{File.basename(Dir.pwd)}"
end

#handle_output(output, suite = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/guard/rebar-eunit.rb', line 36

def handle_output(output, suite = nil)
  suite = directory_name unless suite
  if $? == 0
    Notifier.notify(suite, title: title, image: :success)
    UI.info output
  else
    Notifier.notify(suite, title: title, image: :failed)
    UI.error output
  end
end

#handle_skip_depsObject



47
48
49
# File 'lib/guard/rebar-eunit.rb', line 47

def handle_skip_deps
  options[:skip_deps] ? "skip_deps=true " : ""
end

#run_allObject



15
16
17
18
19
# File 'lib/guard/rebar-eunit.rb', line 15

def run_all
  cmd = "rebar eunit #{handle_skip_deps}"
  UI.info "#{cmd}"
  handle_output(`#{cmd}`)
end

#run_on_change(paths = []) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/guard/rebar-eunit.rb', line 21

def run_on_change(paths = [])
  suites = []
  paths.each do |path|
    UI.info "changed: #{path}"
    if suite = path.match(%r{.*?/([^.].*?)_tests?.erl$})
      suites << suite[1]
    elsif suite = path.match(%r{.*?/([^.].*?)?.erl$})
      suites << suite[1]
    end
  end
  cmd = "rebar eunit #{handle_skip_deps}suites=#{suites.join(",")}"
  UI.info "#{cmd}"
  handle_output(`#{cmd}`, suites.join(" "))
end

#startObject



11
12
13
# File 'lib/guard/rebar-eunit.rb', line 11

def start
  run_all if options[:all_on_start]
end

#titleObject



51
52
53
# File 'lib/guard/rebar-eunit.rb', line 51

def title
  "Rebar EUnit: #{directory_name}"
end