Class: Semaphore::RspecBooster
- Inherits:
-
Object
- Object
- Semaphore::RspecBooster
- Defined in:
- lib/test_boosters/rspec_booster.rb
Instance Method Summary collapse
-
#initialize(thread_index) ⇒ RspecBooster
constructor
A new instance of RspecBooster.
- #run ⇒ Object
- #run_command(specs) ⇒ Object
- #select ⇒ Object
- #with_fallback ⇒ Object
Constructor Details
#initialize(thread_index) ⇒ RspecBooster
Returns a new instance of RspecBooster.
10 11 12 13 14 |
# File 'lib/test_boosters/rspec_booster.rb', line 10 def initialize(thread_index) @thread_index = thread_index @report_path = ENV["REPORT_PATH"] || "#{ENV["HOME"]}/rspec_report.json" @spec_path = ENV["SPEC_PATH"] || "spec" end |
Instance Method Details
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/test_boosters/rspec_booster.rb', line 16 def run begin specs_to_run = select if specs_to_run.empty? puts "No spec files in this thread!" else run_command(specs_to_run.join(" ")) end rescue StandardError => e if @thread_index == 0 run_command(@spec_path) end end end |
#run_command(specs) ⇒ Object
32 33 34 35 36 |
# File 'lib/test_boosters/rspec_booster.rb', line 32 def run_command(specs) = "--format documentation --format json --out #{@report_path}" puts "options: #{}" Semaphore::execute("bundle exec rspec #{} #{specs}") end |
#select ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/test_boosters/rspec_booster.rb', line 38 def select with_fallback do rspec_report = JSON.parse(File.read(@report_path)) thread_count = rspec_report.count thread = rspec_report[@thread_index] all_specs = Dir["#{@spec_path}/**/*_spec.rb"].sort all_known_specs = rspec_report.map { |t| t["files"] }.flatten.sort all_leftover_specs = all_specs - all_known_specs thread_leftover_specs = LeftoverFiles::select(all_leftover_specs, thread_count, @thread_index) thread_specs = all_specs & thread["files"].sort specs_to_run = thread_specs + thread_leftover_specs Semaphore::display_files("This thread specs:", thread_specs) Semaphore::display_title_and_count("All leftover specs:", all_leftover_specs) Semaphore::display_files("This thread leftover specs:", thread_leftover_specs) specs_to_run end end |
#with_fallback ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/test_boosters/rspec_booster.rb', line 61 def with_fallback yield rescue StandardError => e error = %{ WARNING: An error detected while parsing the test boosters report file. WARNING: All tests will be executed on the first thread. } puts error error += %{Exception: #{e.}} Semaphore::log(error) raise end |