Class: RSpecLive::Suite

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-live/suite.rb

Instance Method Summary collapse

Constructor Details

#initialize(runner, file_watcher) ⇒ Suite

Returns a new instance of Suite.



5
6
7
8
9
# File 'lib/rspec-live/suite.rb', line 5

def initialize(runner, file_watcher)
  @runner = runner
  @file_watcher = file_watcher
  @examples = {}
end

Instance Method Details

#activity_statusObject



38
39
40
41
# File 'lib/rspec-live/suite.rb', line 38

def activity_status
  run_count = stale_example_names.count
  run_count.zero? ? "watching for updates..." : "running #{example_count run_count}"
end

#example_count(number) ⇒ Object



50
51
52
# File 'lib/rspec-live/suite.rb', line 50

def example_count(number)
  "#{number} example" + (number == 1 ? "" : "s")
end

#ordered_example_namesObject



62
63
64
65
66
67
68
# File 'lib/rspec-live/suite.rb', line 62

def ordered_example_names
  example_names.sort_by do |name|
    file, line = name.split(":")
    line = line.rjust(8, "0")
    [file, line].join(":")
  end
end

#ordered_examplesObject



54
55
56
# File 'lib/rspec-live/suite.rb', line 54

def ordered_examples
  ordered_example_names.map { |name| @examples[name] }
end

#process_updatesObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rspec-live/suite.rb', line 11

def process_updates
  any_processed = need_inventory = false
  @file_watcher.updated.each do |path|
    @examples.values.each { |example| example.file_touched path }
    @examples.delete_if { |name, example| example.in_file? path }
    any_processed = need_inventory = true
  end
  @file_watcher.removed.each do |path|
    @examples.delete_if { |name, example| example.in_file? path }
    any_processed = true
  end
  if @examples.empty? || @file_watcher.added.any?
    any_processed = need_inventory = true
  end
  @runner.request_inventory(need_inventory)
  @runner.request_results stale_example_names
  @runner.results.each do |result|
    update_or_create_example result
    any_processed = true
  end
  any_processed
end

#resetObject



58
59
60
# File 'lib/rspec-live/suite.rb', line 58

def reset
  @examples = {}
end

#stale_example_namesObject



34
35
36
# File 'lib/rspec-live/suite.rb', line 34

def stale_example_names
  @examples.values.select(&:stale?).map(&:name)
end

#summaryObject



43
44
45
46
47
48
# File 'lib/rspec-live/suite.rb', line 43

def summary
  passed = ordered_examples.select(&:passed?).length
  total = ordered_examples.length
  percent = total.zero? ? 0 : (100*passed/total.to_f).round
  "#{passed} of #{example_count total} passed (#{percent}%)"
end