1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
require 'support/aruba_support'
require 'rspec/core/bisect/shell_command'
require 'rspec/core/bisect/shell_runner'
require 'rspec/core/bisect/fork_runner'
module RSpec::Core
RSpec.shared_examples_for "a bisect runner" do
include_context "aruba support"
before { setup_aruba }
let(:shell_command) { Bisect::ShellCommand.new([]) }
def with_runner(&block)
handle_current_dir_change do
cd '.' do
options = ConfigurationOptions.new(shell_command.original_cli_args)
runner = Runner.new(options)
output = StringIO.new
runner.configure(output, output)
described_class.start(shell_command, runner, &block)
end
end
end
it 'runs the specs in an isolated environment and reports the results' do
RSpec.configuration.formatter = 'progress'
write_file 'spec/a_spec.rb', "
formatters = RSpec.configuration.formatter_loader.formatters
if formatters.any? { |f| f.is_a?(RSpec::Core::Formatters::ProgressFormatter) }
raise 'Leaked progress formatter from host environment'
end
RSpec.describe 'A group' do
it('passes') { expect(1).to eq 1 }
it('fails') { expect(1).to eq 2 }
end
"
with_runner do |runner|
expect(runner.original_results).to have_attributes(
:all_example_ids => %w[ ./spec/a_spec.rb[1:1] ./spec/a_spec.rb[1:2] ],
:failed_example_ids => %w[ ./spec/a_spec.rb[1:2] ]
)
expect(runner.run(%w[ ./spec/a_spec.rb[1:1] ])).to have_attributes(
:all_example_ids => %w[ ./spec/a_spec.rb[1:1] ],
:failed_example_ids => %w[]
)
end
end
it 'honors `run_all_when_everything_filtered`' do
write_file 'spec/a_spec.rb', "
RSpec.configure do |c|
c.filter_run :focus
c.run_all_when_everything_filtered = true
end
RSpec.describe 'A group' do
it('passes') { expect(1).to eq 1 }
it('fails') { expect(1).to eq 2 }
end
"
with_runner do |runner|
expect(runner.original_results).to have_attributes(
:all_example_ids => %w[ ./spec/a_spec.rb[1:1] ./spec/a_spec.rb[1:2] ],
:failed_example_ids => %w[ ./spec/a_spec.rb[1:2] ]
)
end
end
it 'raises BisectFailedError with all run output when it encounters an error loading spec files' do
write_file 'spec/a_spec.rb', "
puts 'stdout in a_spec'
warn 'stderr in a_spec'
RSpec.escribe 'A group' do
it('passes') { expect(1).to eq 1 }
it('fails') { expect(1).to eq 2 }
end
"
rspec_description =
if RUBY_VERSION.to_f > 3.2
"module RSpec"
else
"RSpec:Module"
end
with_runner do |runner|
expect {
runner.original_results
}.to raise_error(Bisect::BisectFailedError, a_string_including(
"undefined method `escribe' for #{rspec_description}",
'stdout in a_spec',
'stderr in a_spec'
))
end
end
end
RSpec.describe Bisect::ShellRunner, :slow do
include_examples 'a bisect runner'
end
RSpec.describe Bisect::ForkRunner, :if => RSpec::Support::RubyFeatures.fork_supported? do
include_examples 'a bisect runner'
context 'when a `--require` option has been provided' do
let(:shell_command) { Bisect::ShellCommand.new(['--require', './spec/a_spec_helper']) }
it 'loads the specified file only once (rather than once per subset run)' do
write_file 'spec_helper_loads', ''
write_file 'spec/a_spec_helper.rb', "
File.open('spec_helper_loads', 'a') do |f|
f.print('.')
end
"
write_file 'spec/a_spec.rb', "
RSpec.describe 'A group' do
it('passes') { expect(1).to eq 1 }
it('fails') { expect(1).to eq 2 }
end
"
with_runner do |runner|
runner.run(%w[ ./spec/a_spec.rb[1:1] ])
runner.run(%w[ ./spec/a_spec.rb[1:1] ])
end
cd '.' do
expect(File.read('spec_helper_loads')).to eq(".")
end
end
end
end
end
|