Class: TestBoosters::Rspec::Booster

Inherits:
Object
  • Object
show all
Defined in:
lib/test_boosters/rspec/booster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(thread_index, thread_count) ⇒ Booster

Returns a new instance of Booster.



8
9
10
11
# File 'lib/test_boosters/rspec/booster.rb', line 8

def initialize(thread_index, thread_count)
  @thread_index = thread_index
  @thread_count = thread_count
end

Instance Attribute Details

#thread_countObject (readonly)

Returns the value of attribute thread_count.



6
7
8
# File 'lib/test_boosters/rspec/booster.rb', line 6

def thread_count
  @thread_count
end

#thread_indexObject (readonly)

Returns the value of attribute thread_index.



5
6
7
# File 'lib/test_boosters/rspec/booster.rb', line 5

def thread_index
  @thread_index
end

Instance Method Details

#all_leftover_specsObject



38
39
40
# File 'lib/test_boosters/rspec/booster.rb', line 38

def all_leftover_specs
  @all_leftover_specs ||= all_specs - split_configuration.all_files
end

#all_specsObject



34
35
36
# File 'lib/test_boosters/rspec/booster.rb', line 34

def all_specs
  @all_specs ||= Dir["#{specs_path}/**/*_spec.rb"].sort
end

#runObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/test_boosters/rspec/booster.rb', line 13

def run
  TestBoosters::Shell.display_title("RSpec Booster v#{TestBoosters::VERSION}")

  unless split_configuration.valid?
    puts "[ERROR] The split configuration file is malformed!"

    return 1 # failure exit status
  end

  threads[@thread_index].run
end

#specs_pathObject



46
47
48
# File 'lib/test_boosters/rspec/booster.rb', line 46

def specs_path
  @specs_path ||= ENV["SPEC_PATH"] || "spec"
end

#split_configurationObject



42
43
44
# File 'lib/test_boosters/rspec/booster.rb', line 42

def split_configuration
  @split_configuration ||= TestBoosters::SplitConfiguration.new(split_configuration_path)
end

#split_configuration_pathObject



50
51
52
# File 'lib/test_boosters/rspec/booster.rb', line 50

def split_configuration_path
  ENV["RSPEC_SPLIT_CONFIGURATION_PATH"] || "#{ENV["HOME"]}/rspec_split_configuration.json"
end

#threadsObject



25
26
27
28
29
30
31
32
# File 'lib/test_boosters/rspec/booster.rb', line 25

def threads
  @threads ||= Array.new(@thread_count) do |thread_index|
    known_files = all_specs & split_configuration.files_for_thread(thread_index)
    leftover_files = TestBoosters::LeftoverFiles.select(all_leftover_specs, thread_count, thread_index)

    TestBoosters::Rspec::Thread.new(known_files, leftover_files)
  end
end