spec/unit/source/git_spec.rb in r10k-3.5.2 vs spec/unit/source/git_spec.rb in r10k-3.6.0
- old
+ new
@@ -91,12 +91,48 @@
describe "filtering branches with ignore prefixes" do
let(:branches) { ['master', 'development', 'production', 'not_dev_test_me', 'dev_test', 'dev', 'test_2'] }
let(:ignore_prefixes) { ['dev', 'test'] }
it "filters branches" do
- expect(subject.filter_branches(branches, ignore_prefixes)).to eq(['master', 'production', 'not_dev_test_me'])
+ expect(subject.filter_branches_by_regexp(branches, ignore_prefixes)).to eq(['master', 'production', 'not_dev_test_me'])
end
end
+
+ describe "filtering branches with command" do
+ let(:branches) { ['master', 'development', 'production'] }
+ let(:filter_command) { 'sh -c "[ $R10K_BRANCH != development ]"' }
+
+ it "filters branches" do
+ expect(subject.filter_branches_by_command(branches, filter_command)).to eq(['master', 'production'])
+ end
+ end
+
+ describe "generate_environments respects filter_command setting" do
+ before do
+ allow(subject.cache).to receive(:branches).and_return ['master', 'development', 'production']
+ subject.instance_variable_set(:@filter_command, '[ $R10K_BRANCH != master ]')
+ end
+
+ let(:environments) { subject.generate_environments }
+
+ it "creates an environment for each branch not filtered by filter_command" do
+ expect(subject.generate_environments.size).to eq(2)
+ end
+ end
+
+ describe "generate_environments respects filter_command setting and name" do
+ before do
+ allow(subject.cache).to receive(:branches).and_return ['master', 'development', 'production']
+ subject.instance_variable_set(:@filter_command, '[ $R10K_NAME = mysource ]')
+ end
+
+ let(:environments) { subject.generate_environments }
+
+ it "creates an environment for each branch not filtered by filter_command" do
+ expect(subject.generate_environments.size).to eq(3)
+ end
+ end
+
end
describe R10K::Source::Git, "handling invalid branch names" do
%w[correct_and_warn correct].each do |setting|
describe "when invalid is #{setting}" do