Module: KnapsackPro::Extensions::RSpecExtension::Runner

Defined in:
lib/knapsack_pro/extensions/rspec_extension.rb

Instance Method Summary collapse

Instance Method Details

#knapsack__deprecated_run_all_when_everything_filtered_enabled?Boolean

must be called after ‘Runner#knapsack__setup` that loads the `spec_helper.rb` configuration

Returns:

  • (Boolean)


56
57
58
# File 'lib/knapsack_pro/extensions/rspec_extension.rb', line 56

def knapsack__deprecated_run_all_when_everything_filtered_enabled?
  configuration.respond_to?(:run_all_when_everything_filtered) && !!configuration.run_all_when_everything_filtered
end

#knapsack__error_exit_codeObject



51
52
53
# File 'lib/knapsack_pro/extensions/rspec_extension.rb', line 51

def knapsack__error_exit_code
  configuration.error_exit_code # nil unless `--error-exit-code` is specified
end

#knapsack__exit_earlyObject



45
46
47
# File 'lib/knapsack_pro/extensions/rspec_extension.rb', line 45

def knapsack__exit_early
  _exit_status = configuration.reporter.exit_early(exit_code)
end

#knapsack__load_spec_files_batch(test_file_paths) ⇒ Object

Parameters:

  • test_file_paths

    Array Example: [‘a_spec.rb’, ‘b_spec.rb’]



66
67
68
69
70
71
72
73
74
75
# File 'lib/knapsack_pro/extensions/rspec_extension.rb', line 66

def knapsack__load_spec_files_batch(test_file_paths)
  world.reset

  # Reset filters, but do not reset `configuration.static_config_filter_manager` to preserve the --tag option
  filter_manager = RSpec::Core::FilterManager.new
  options.configure_filter_manager(filter_manager)
  configuration.filter_manager = filter_manager

  configuration.knapsack__load_spec_files(test_file_paths)
end

#knapsack__persist_example_statusesObject



118
119
120
# File 'lib/knapsack_pro/extensions/rspec_extension.rb', line 118

def knapsack__persist_example_statuses
  persist_example_statuses
end

#knapsack__rspec_is_quitting?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/knapsack_pro/extensions/rspec_extension.rb', line 41

def knapsack__rspec_is_quitting?
  world.respond_to?(:rspec_is_quitting) && world.rspec_is_quitting
end

#knapsack__run_specs(queue_runner) ⇒ Fixnum

Based on: github.com/rspec/rspec-core/blob/f8c8880dabd8f0544a6f91d8d4c857c1bd8df903/lib/rspec/core/runner.rb#L113

Ignore ‘configuration.fail_if_no_examples` in Queue Mode:

* a late CI node, started after all tests were executed by other nodes, is expected to receive an empty batch
* a batch could contain tests with no examples (e.g. commented out)

Returns:

  • (Fixnum)

    exit status code.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/knapsack_pro/extensions/rspec_extension.rb', line 85

def knapsack__run_specs(queue_runner)
  # Based on:
  # https://github.com/rspec/rspec-core/blob/f8c8880dabd8f0544a6f91d8d4c857c1bd8df903/lib/rspec/core/world.rb#L53
  ordering_strategy = configuration.ordering_registry.fetch(:global)
  node_examples_passed = true

  configuration.reporter.report(_expected_example_count = 0) do |reporter|
    configuration.with_suite_hooks do
      queue_runner.with_batch do |test_file_paths|
        knapsack__load_spec_files_batch(test_file_paths)

        examples_passed = ordering_strategy.order(world.example_groups).map do |example_group|
          queue_runner.handle_signal!
          example_group.run(reporter)
        end.all?

        node_examples_passed = false unless examples_passed

        knapsack__persist_example_statuses

        if reporter.fail_fast_limit_met?
          queue_runner.log_fail_fast_limit_met
          break
        end
      end
    end

    exit_code(node_examples_passed)
  end
end

#knapsack__seedObject



60
61
62
# File 'lib/knapsack_pro/extensions/rspec_extension.rb', line 60

def knapsack__seed
  Seed.new(configuration.seed.to_s, configuration.seed_used?)
end

#knapsack__setup(stream_error = $stderr, stream_out = $stdout) ⇒ Object

Based on: github.com/rspec/rspec-core/blob/f8c8880dabd8f0544a6f91d8d4c857c1bd8df903/lib/rspec/core/runner.rb#L98

‘@configuration.load_spec_files` is not called because we load tests in batches with `knapsack__load_spec_files_batch` later on.



31
32
33
34
35
# File 'lib/knapsack_pro/extensions/rspec_extension.rb', line 31

def knapsack__setup(stream_error = $stderr, stream_out = $stdout)
  configure(stream_error, stream_out)
ensure
  world.knapsack__announce_filters
end

#knapsack__wants_to_quit?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/knapsack_pro/extensions/rspec_extension.rb', line 37

def knapsack__wants_to_quit?
  world.wants_to_quit
end