Class: RSpecLive::Suite
- Inherits:
-
Object
- Object
- RSpecLive::Suite
- Defined in:
- lib/rspec-live/suite.rb
Instance Method Summary collapse
- #activity_status ⇒ Object
- #example_count(number) ⇒ Object
-
#initialize(runner, file_watcher) ⇒ Suite
constructor
A new instance of Suite.
- #ordered_example_names ⇒ Object
- #ordered_examples ⇒ Object
- #process_updates ⇒ Object
- #reset ⇒ Object
- #stale_example_names ⇒ Object
- #summary ⇒ Object
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_status ⇒ Object
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_names ⇒ Object
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_examples ⇒ Object
54 55 56 |
# File 'lib/rspec-live/suite.rb', line 54 def ordered_examples ordered_example_names.map { |name| @examples[name] } end |
#process_updates ⇒ Object
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 |
#reset ⇒ Object
58 59 60 |
# File 'lib/rspec-live/suite.rb', line 58 def reset @examples = {} end |
#stale_example_names ⇒ Object
34 35 36 |
# File 'lib/rspec-live/suite.rb', line 34 def stale_example_names @examples.values.select(&:stale?).map(&:name) end |
#summary ⇒ Object
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 |