Commit f793677f authored by Mehmet Emin INAC's avatar Mehmet Emin INAC

Use parameterized syntax to simplify test cases

parent a99ddab6
......@@ -113,47 +113,22 @@ RSpec.describe MergeRequestPresenter do
subject(:missing_security_scan_types) { presenter.missing_security_scan_types }
before do
stub_feature_flags(missing_mr_security_scan_types: feature_enabled?)
allow(merge_request).to receive(:actual_head_pipeline).and_return(pipeline)
allow(presenter).to receive(:can?).with(user, :read_pipeline, pipeline).and_return(can_read_pipeline?)
where(:feature_flag_enabled?, :can_read_pipeline?, :attribute_value) do
false | false | nil
false | true | nil
true | false | nil
true | true | %w(sast)
end
context 'when the `missing_mr_security_scan_types` feature flag is not enabled' do
let(:feature_enabled?) { false }
context 'when the `current_user` can not read the pipeline' do
let(:can_read_pipeline?) { false }
it { is_expected.to be_nil }
end
context 'when the `current_user` can read the pipeline' do
let(:can_read_pipeline?) { true }
it { is_expected.to be_nil }
end
end
context 'when the `missing_mr_security_scan_types` feature flag is enabled' do
let(:feature_enabled?) { true }
context 'when the `current_user` can not read the pipeline' do
let(:can_read_pipeline?) { false }
it { is_expected.to be_nil }
with_them do
before do
stub_feature_flags(missing_mr_security_scan_types: feature_flag_enabled?)
allow(merge_request).to receive(:actual_head_pipeline).and_return(pipeline)
allow(presenter).to receive(:can?).with(user, :read_pipeline, pipeline).and_return(can_read_pipeline?)
allow(merge_request).to receive(:missing_security_scan_types).and_return(%w(sast))
end
context 'when the `current_user` can read the pipeline' do
let(:can_read_pipeline?) { true }
let(:missing_types) { %w(sast) }
before do
allow(merge_request).to receive(:missing_security_scan_types).and_return(missing_types)
end
it { is_expected.to eq(missing_types) }
end
it { is_expected.to eq(attribute_value) }
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment