Commit 7babc59e authored by Grzegorz Bizon's avatar Grzegorz Bizon

Use parameterized RSpec to improve variables expressions specs

parent 65f4e7b2
require 'fast_spec_helper' require 'fast_spec_helper'
require 'rspec-parameterized'
describe Gitlab::Ci::Pipeline::Expression::Statement do describe Gitlab::Ci::Pipeline::Expression::Statement do
subject do subject do
...@@ -82,54 +83,54 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do ...@@ -82,54 +83,54 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
end end
describe '#evaluate' do describe '#evaluate' do
statements = [ using RSpec::Parameterized::TableSyntax
['$PRESENT_VARIABLE == "my variable"', true],
['"my variable" == $PRESENT_VARIABLE', true], where(:expression, :value) do
['$PRESENT_VARIABLE == null', false], '$PRESENT_VARIABLE == "my variable"' | true
['$EMPTY_VARIABLE == null', false], '"my variable" == $PRESENT_VARIABLE' | true
['"" == $EMPTY_VARIABLE', true], '$PRESENT_VARIABLE == null' | false
['$EMPTY_VARIABLE', ''], '$EMPTY_VARIABLE == null' | false
['$UNDEFINED_VARIABLE == null', true], '"" == $EMPTY_VARIABLE' | true
['null == $UNDEFINED_VARIABLE', true], '$EMPTY_VARIABLE' | ''
['$PRESENT_VARIABLE', 'my variable'], '$UNDEFINED_VARIABLE == null' | true
['$UNDEFINED_VARIABLE', nil], 'null == $UNDEFINED_VARIABLE' | true
["$PRESENT_VARIABLE =~ /var.*e$/", true], '$PRESENT_VARIABLE' | 'my variable'
["$PRESENT_VARIABLE =~ /^var.*/", false], '$UNDEFINED_VARIABLE' | nil
["$EMPTY_VARIABLE =~ /var.*/", false], "$PRESENT_VARIABLE =~ /var.*e$/" | true
["$UNDEFINED_VARIABLE =~ /var.*/", false] "$PRESENT_VARIABLE =~ /^var.*/" | false
] "$EMPTY_VARIABLE =~ /var.*/" | false
"$UNDEFINED_VARIABLE =~ /var.*/" | false
statements.each do |expression, value| end
context "when using expression `#{expression}`" do
let(:text) { expression } with_them do
let(:text) { expression }
it "evaluates to `#{value.inspect}`" do
expect(subject.evaluate).to eq value it "evaluates to `#{params[:value].inspect}`" do
end expect(subject.evaluate).to eq value
end end
end end
end end
describe '#truthful?' do describe '#truthful?' do
statements = [ using RSpec::Parameterized::TableSyntax
['$PRESENT_VARIABLE == "my variable"', true],
["$PRESENT_VARIABLE == 'no match'", false], where(:expression, :value) do
['$UNDEFINED_VARIABLE == null', true], '$PRESENT_VARIABLE == "my variable"' | true
['$PRESENT_VARIABLE', true], "$PRESENT_VARIABLE == 'no match'" | false
['$UNDEFINED_VARIABLE', false], '$UNDEFINED_VARIABLE == null' | true
['$EMPTY_VARIABLE', false], '$PRESENT_VARIABLE' | true
['$INVALID = 1', false], '$UNDEFINED_VARIABLE' | false
["$PRESENT_VARIABLE =~ /var.*/", true], '$EMPTY_VARIABLE' | false
["$UNDEFINED_VARIABLE =~ /var.*/", false] '$INVALID = 1' | false
] "$PRESENT_VARIABLE =~ /var.*/" | true
"$UNDEFINED_VARIABLE =~ /var.*/" | false
statements.each do |expression, value| end
context "when using expression `#{expression}`" do
let(:text) { expression } with_them do
let(:text) { expression }
it "returns `#{value.inspect}`" do
expect(subject.truthful?).to eq value it "returns `#{params[:value].inspect}`" do
end expect(subject.truthful?).to eq value
end 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