Class: Guard::Teabag

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/teabag.rb,
lib/guard/teabag/runner.rb,
lib/guard/teabag/resolver.rb

Defined Under Namespace

Classes: Resolver, Runner

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Teabag.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/guard/teabag.rb', line 11

def initialize(watchers = [], options = {})
  super
  @options = {
    focus_on_failed: false,
    all_after_pass:  true,
    all_on_start:    true,
    keep_failed:     true,
    formatters:      "clean",
    run_all:         {},
    run_on_changes:  {}
  }.merge(options)
  reload

  @resolver = Resolver.new(@options)
  @runner = Runner.new(@options)
end

Instance Attribute Details

#failed_pathsObject

Returns the value of attribute failed_paths.



9
10
11
# File 'lib/guard/teabag.rb', line 9

def failed_paths
  @failed_paths
end

#last_failedObject

Returns the value of attribute last_failed.



9
10
11
# File 'lib/guard/teabag.rb', line 9

def last_failed
  @last_failed
end

#runnerObject

Returns the value of attribute runner.



9
10
11
# File 'lib/guard/teabag.rb', line 9

def runner
  @runner
end

Instance Method Details

#reloadObject



43
44
45
46
# File 'lib/guard/teabag.rb', line 43

def reload
  @last_failed = false
  @failed_paths = []
end

#run_allObject



33
34
35
36
37
38
39
40
41
# File 'lib/guard/teabag.rb', line 33

def run_all
  passed = @runner.run_all(@options[:run_all])

  unless @last_failed = !passed
    @failed_paths = []
  else
    throw :task_has_failed
  end
end

#run_on_changes(original_paths) ⇒ Object



48
49
50
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/guard/teabag.rb', line 48

def run_on_changes(original_paths)
  @resolver.resolve(original_paths)

  failed = false
  @resolver.suites.each do |suite, files|
    failed = @runner.run(files, @options[:run_on_changes].merge(suite: suite))
  end

  if failed
    @last_failed = true
    Notifier.notify("Failed", title: "Teabag Guard", image: :failed)
  else
    Notifier.notify("Success", title: "Teabag Guard", image: :success)
  end

  #original_paths = paths.dup
  #
  #focused = false
  #if last_failed && @options[:focus_on_failed]
  #  path = './tmp/teabag_guard_result'
  #  if File.exist?(path)
  #    # todo: this should ask a "resolver" to see if it's a spec or not
  #    single_spec = paths && paths.length == 1 && paths[0].include?("_spec") ? paths[0] : nil
  #    failed_specs = File.open(path) { |file| file.read.split("\n") }
  #
  #    File.delete(path)
  #
  #    if single_spec && @inspector.clean([single_spec]).length == 1
  #      failed_specs = failed_specs.select{|p| p.include? single_spec}
  #    end
  #
  #    if failed_specs.any?
  #      # some sane limit, stuff will explode if all tests fail
  #      #   ... cap at 10
  #
  #      paths = failed_specs[0..10]
  #      focused = true
  #    end
  #
  #    # switch focus to the single spec
  #    focused = true if single_spec and failed_specs.length > 0
  #  end
  #end
  #
  #if focused
  #  add_failed(original_paths)
  #  add_failed(paths.map{|p| p.split(":")[0]})
  #else
  #  paths += failed_paths if @options[:keep_failed]
  #  paths = @inspector.clean(paths)
  #end
  #
  #if @runner.run(paths)
  #  remove_failed(paths) unless focused
  #
  #  if last_failed && focused
  #    run_on_changes(failed_paths)
  #  elsif last_failed && @options[:all_after_pass]
  #    @last_failed = false
  #    run_all
  #  end
  #else
  #  @last_failed = true
  #  add_failed(paths) unless focused
  #
  #  throw :task_has_failed
  #end
end

#startObject



28
29
30
31
# File 'lib/guard/teabag.rb', line 28

def start
  UI.info "Guard::Teabag is running"
  run_all if @options[:all_on_start]
end