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
|
require 'support/aruba_support'
RSpec.describe 'Fail if no examples' do
include_context "aruba support"
before { setup_aruba }
context 'when 1 passing example' do
def passing_example(fail_if_no_examples)
"
RSpec.configure { |c| c.fail_if_no_examples = #{fail_if_no_examples} }
RSpec.describe 'something' do
it 'succeeds' do
true
end
end
"
end
it 'succeeds if fail_if_no_examples set to true' do
write_file 'spec/example_spec.rb', passing_example(true)
run_command ""
expect(last_cmd_stdout).to include("1 example, 0 failures")
expect(last_cmd_exit_status).to eq(0)
end
it 'succeeds if fail_if_no_examples set to false' do
write_file 'spec/example_spec.rb', passing_example(false)
run_command ""
expect(last_cmd_stdout).to include("1 example, 0 failures")
expect(last_cmd_exit_status).to eq(0)
end
end
context 'when 1 failing example' do
def failing_example(fail_if_no_examples)
"
RSpec.configure { |c| c.fail_if_no_examples = #{fail_if_no_examples} }
RSpec.describe 'something' do
it 'fails' do
fail
end
end
"
end
it 'fails if fail_if_no_examples set to true' do
write_file 'spec/example_spec.rb', failing_example(true)
run_command ""
expect(last_cmd_stdout).to include("1 example, 1 failure")
expect(last_cmd_exit_status).to eq(1)
end
it 'fails if fail_if_no_examples set to false' do
write_file 'spec/example_spec.rb', failing_example(false)
run_command ""
expect(last_cmd_stdout).to include("1 example, 1 failure")
expect(last_cmd_exit_status).to eq(1)
end
end
context 'when 0 examples' do
def no_examples(fail_if_no_examples)
"
RSpec.configure { |c| c.fail_if_no_examples = #{fail_if_no_examples} }
RSpec.describe 'something' do
end
"
end
it 'fails if fail_if_no_examples set to true' do
write_file 'spec/example_spec.rb', no_examples(true)
run_command ""
expect(last_cmd_stdout).to include("0 examples, 0 failures")
expect(last_cmd_exit_status).to eq(1)
end
it 'succeeds if fail_if_no_examples set to false' do
write_file 'spec/example_spec.rb', no_examples(false)
run_command ""
expect(last_cmd_stdout).to include("0 examples, 0 failures")
expect(last_cmd_exit_status).to eq(0)
end
context 'when custom failure_exit_code set' do
def no_examples_custom_failure_exit_code(fail_if_no_examples)
"
RSpec.configure do |c|
c.fail_if_no_examples = #{fail_if_no_examples}
c.failure_exit_code = 15
end
RSpec.describe 'something' do
end
"
end
it 'fails if fail_if_no_examples set to true' do
write_file 'spec/example_spec.rb', no_examples_custom_failure_exit_code(true)
run_command ""
expect(last_cmd_stdout).to include("0 examples, 0 failures")
expect(last_cmd_exit_status).to eq(15)
end
end
end
end
|