Class: RspecChunked::ChunkedTests

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_chunked/chunked_tests.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(qty_groups, job_number, cmd: nil, order_logic: :file_size) ⇒ ChunkedTests

Returns a new instance of ChunkedTests.

Parameters:

  • order_logic (:qty_specs|:file_size*) (defaults to: :file_size)


11
12
13
14
15
16
17
# File 'lib/rspec_chunked/chunked_tests.rb', line 11

def initialize(qty_groups, job_number, cmd: nil, order_logic: :file_size)
  @qty_groups = qty_groups
  @job_number = job_number - 1
  @order_logic = order_logic
  @balance_settings = self.class.balance_settings || {}
  @cmd = cmd || 'bundle exec rspec'
end

Class Attribute Details

.balance_settingsObject

Returns the value of attribute balance_settings.



6
7
8
# File 'lib/rspec_chunked/chunked_tests.rb', line 6

def balance_settings
  @balance_settings
end

Instance Attribute Details

#balance_settingsObject

Returns the value of attribute balance_settings.



8
9
10
# File 'lib/rspec_chunked/chunked_tests.rb', line 8

def balance_settings
  @balance_settings
end

#cmdObject

Returns the value of attribute cmd.



8
9
10
# File 'lib/rspec_chunked/chunked_tests.rb', line 8

def cmd
  @cmd
end

#job_numberObject

Returns the value of attribute job_number.



8
9
10
# File 'lib/rspec_chunked/chunked_tests.rb', line 8

def job_number
  @job_number
end

#order_logicObject

Returns the value of attribute order_logic.



8
9
10
# File 'lib/rspec_chunked/chunked_tests.rb', line 8

def order_logic
  @order_logic
end

#qty_groupsObject

Returns the value of attribute qty_groups.



8
9
10
# File 'lib/rspec_chunked/chunked_tests.rb', line 8

def qty_groups
  @qty_groups
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
# File 'lib/rspec_chunked/chunked_tests.rb', line 19

def run
  balanced_tests = balance_tests(group_tests, balance_settings)
  tests = balanced_tests[job_number]
  qty = balanced_tests.flatten.count
  Kernel.puts "**** running #{tests.count}/#{qty} test files (group number: #{job_number + 1})"
  Kernel.abort('failed running command') unless Kernel.system "#{cmd} #{tests.join(' ')}"
end