How to use seed method of Spinach Package

Best Spinach_ruby code snippet using Spinach.seed

seed_spec.rb

Source:seed_spec.rb Github

copy

Full Screen

2require 'spec_helper'3RSpec.describe Gitlab::Ci::Pipeline::Chain::Seed do4 let_it_be(:project) { create(:project, :repository) }5 let_it_be(:user) { create(:user, developer_projects: [project]) }6 let(:seeds_block) { }7 let(:command) { initialize_command }8 let(:pipeline) { build(:ci_pipeline, project: project) }9 describe '#perform!' do10 before do11 stub_ci_pipeline_yaml_file(YAML.dump(config))12 end13 let(:config) do14 { rspec: { script: 'rake' } }15 end16 subject(:run_chain) do17 run_previous_chain(pipeline, command)18 perform_seed(pipeline, command)19 end20 it 'allocates next IID' do21 run_chain22 expect(pipeline.iid).to be_present23 end24 it 'ensures ci_ref' do25 run_chain26 expect(pipeline.ci_ref).to be_present27 end28 it 'sets the seeds in the command object' do29 run_chain30 expect(command.pipeline_seed).to be_a(Gitlab::Ci::Pipeline::Seed::Pipeline)31 expect(command.pipeline_seed.size).to eq 132 end33 context 'when no ref policy is specified' do34 let(:config) do35 {36 production: { stage: 'deploy', script: 'cap prod' },37 rspec: { stage: 'test', script: 'rspec' },38 spinach: { stage: 'test', script: 'spinach' }39 }40 end41 it 'correctly fabricates stages and builds' do42 run_chain43 seed = command.pipeline_seed44 expect(seed.stages.size).to eq 245 expect(seed.size).to eq 346 expect(seed.stages.first.name).to eq 'test'47 expect(seed.stages.second.name).to eq 'deploy'48 expect(seed.stages[0].statuses[0].name).to eq 'rspec'49 expect(seed.stages[0].statuses[1].name).to eq 'spinach'50 expect(seed.stages[1].statuses[0].name).to eq 'production'51 end52 end53 context 'when refs policy is specified' do54 let(:pipeline) do55 build(:ci_pipeline, project: project, ref: 'feature', tag: true)56 end57 let(:config) do58 {59 production: { stage: 'deploy', script: 'cap prod', only: ['master'] },60 spinach: { stage: 'test', script: 'spinach', only: ['tags'] }61 }62 end63 it 'returns pipeline seed with jobs only assigned to master' do64 run_chain65 seed = command.pipeline_seed66 expect(seed.size).to eq 167 expect(seed.stages.first.name).to eq 'test'68 expect(seed.stages[0].statuses[0].name).to eq 'spinach'69 end70 end71 context 'when source policy is specified' do72 let(:pipeline) { create(:ci_pipeline, source: :schedule) }73 let(:config) do74 {75 production: { stage: 'deploy', script: 'cap prod', only: ['triggers'] },76 spinach: { stage: 'test', script: 'spinach', only: ['schedules'] }77 }78 end79 it 'returns pipeline seed with jobs only assigned to schedules' do80 run_chain81 seed = command.pipeline_seed82 expect(seed.size).to eq 183 expect(seed.stages.first.name).to eq 'test'84 expect(seed.stages[0].statuses[0].name).to eq 'spinach'85 end86 end87 context 'when kubernetes policy is specified' do88 let(:config) do89 {90 spinach: { stage: 'test', script: 'spinach' },91 production: {92 stage: 'deploy',93 script: 'cap',94 only: { kubernetes: 'active' }95 }96 }97 end98 context 'when kubernetes is active' do99 context 'when user configured kubernetes from CI/CD > Clusters' do100 let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }101 let(:project) { cluster.project }102 let(:pipeline) { build(:ci_pipeline, project: project) }103 it 'returns seeds for kubernetes dependent job' do104 run_chain105 seed = command.pipeline_seed106 expect(seed.size).to eq 2107 expect(seed.stages[0].statuses[0].name).to eq 'spinach'108 expect(seed.stages[1].statuses[0].name).to eq 'production'109 end110 end111 end112 context 'when kubernetes is not active' do113 it 'does not return seeds for kubernetes dependent job' do114 run_chain115 seed = command.pipeline_seed116 expect(seed.size).to eq 1117 expect(seed.stages[0].statuses[0].name).to eq 'spinach'118 end119 end120 end121 context 'when variables policy is specified' do122 let(:config) do123 {124 unit: { script: 'minitest', only: { variables: ['$CI_PIPELINE_SOURCE'] } },125 feature: { script: 'spinach', only: { variables: ['$UNDEFINED'] } }126 }127 end128 it 'returns stage seeds only when variables expression is truthy' do129 run_chain130 seed = command.pipeline_seed131 expect(seed.size).to eq 1132 expect(seed.stages[0].statuses[0].name).to eq 'unit'133 end134 end135 context 'when there is seeds_block' do136 let(:seeds_block) do137 ->(pipeline) { pipeline.variables.build(key: 'VAR', value: '123') }138 end139 it 'does not execute the block' do140 run_chain141 expect(pipeline.variables.size).to eq(0)142 end143 end144 describe '#root_variables' do145 let(:config) do146 {147 variables: { VAR1: 'var 1' },148 workflow: {149 rules: [{ if: '$CI_PIPELINE_SOURCE',150 variables: { VAR1: 'overridden var 1' } },151 { when: 'always' }]152 },153 rspec: { script: 'rake' }154 }155 end156 let(:rspec_variables) { command.pipeline_seed.stages[0].statuses[0].variables.to_hash }157 it 'sends root variable with overridden by rules' do158 run_chain159 expect(rspec_variables['VAR1']).to eq('overridden var 1')160 end161 end162 context 'N+1 queries' do163 it 'avoids N+1 queries when calculating variables of jobs', :use_sql_query_cache do164 warm_up_pipeline, warm_up_command = prepare_pipeline1165 perform_seed(warm_up_pipeline, warm_up_command)166 pipeline1, command1 = prepare_pipeline1167 pipeline2, command2 = prepare_pipeline2168 control = ActiveRecord::QueryRecorder.new(skip_cached: false) do169 perform_seed(pipeline1, command1)170 end171 expect { perform_seed(pipeline2, command2) }.not_to exceed_all_query_limit(172 control.count + expected_extra_queries173 )174 end175 private176 def prepare_pipeline1177 config1 = { build: { stage: 'build', script: 'build' } }178 stub_ci_pipeline_yaml_file(YAML.dump(config1))179 pipeline1 = build(:ci_pipeline, project: project)180 command1 = initialize_command181 run_previous_chain(pipeline1, command1)182 [pipeline1, command1]183 end184 def prepare_pipeline2185 config2 = { build1: { stage: 'build', script: 'build1' },186 build2: { stage: 'build', script: 'build2' },187 test: { stage: 'build', script: 'test' } }188 stub_ci_pipeline_yaml_file(YAML.dump(config2))189 pipeline2 = build(:ci_pipeline, project: project)190 command2 = initialize_command191 run_previous_chain(pipeline2, command2)192 [pipeline2, command2]193 end194 def expected_extra_queries195 extra_jobs = 2196 non_handled_sql_queries = 2197 # 1. Ci::InstanceVariable Load => `Ci::InstanceVariable#cached_data` => already cached with `fetch_memory_cache`198 # 2. Ci::Variable Load => `Project#ci_variables_for` => already cached with `Gitlab::SafeRequestStore`199 extra_jobs * non_handled_sql_queries200 end201 end202 private203 def run_previous_chain(pipeline, command)204 [205 Gitlab::Ci::Pipeline::Chain::Config::Content.new(pipeline, command),206 Gitlab::Ci::Pipeline::Chain::Config::Process.new(pipeline, command),207 Gitlab::Ci::Pipeline::Chain::EvaluateWorkflowRules.new(pipeline, command)208 ].map(&:perform!)209 end210 def perform_seed(pipeline, command)211 described_class.new(pipeline, command).perform!212 end213 end214 private215 def initialize_command216 Gitlab::Ci::Pipeline::Chain::Command.new(217 project: project,218 current_user: user,219 origin_ref: 'master',220 seeds_block: seeds_block221 )222 end223end...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Spinach_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful