Best Rr_ruby code snippet using Project.run_tests
create_server.rb
Source:create_server.rb
...59 prepare ec260 env_os = project["deploy_envs"][0]61 env_ec2 = project["deploy_envs"][1]62 self.title = TITLE + "Create project '#{project["name"]}'"63 run_tests [64 "project create #{project["name"]} --groups #{env_os["groups"].join(",")} --deploy_env #{env_os["identifier"]} --subnets #{env_os["subnets"].join(",")} --flavor #{env_os["flavor"]} --image #{env_os["image"]} --run_list role[#{project["name"]}_#{env_os["identifier"]}] --users #{env_os["users"].join(",")} --provider openstack -y --no_expires",65 "project create #{project["name"]} --groups #{env_ec2["groups"].join(",")} --deploy_env #{env_ec2["identifier"]} --flavor #{env_ec2["flavor"]} --image #{env_ec2["image"]} --run_list role[#{project["name"]}_#{env_ec2["identifier"]}] --users #{env_ec2["users"].join(",")} --provider ec2 -y --no_expires"66 ]67 self.title = TITLE + "Project list"68 run_test_with_block "project list --format json" do |l|69 projects = JSON.parse(l)70 projects.include? project["name"]71 end72 self.title = TITLE + "Show project '#{project["name"]}'"73 run_test_with_block "project show #{project["name"]} --format json" do |p|74 pr = JSON.parse(p)75 name = (project["name"] == pr["name"])76 envs = (project["deploy_envs"].size == pr["deploy_envs"].size)77 o = pr["deploy_envs"].detect{|e| e["identifier"] == "openstack"}78 po = project["deploy_envs"][0]79 e = pr["deploy_envs"].detect{|e| e["identifier"] == "ec2"}80 pe = project["deploy_envs"][1]81 unless name82 puts "Project name is not a '#{project["name"]}'"83 end84 unless envs85 puts "Project environments not equals #{project["deploy_envs"].size}"86 end87 name and envs and check_envs(po, o) and check_envs(pe, e)88 end89 self.title = TITLE + "Add user 'root' to project '#{project["name"]}'"90 run_tests [ "project user add #{project["name"]} root" ]91 self.title = TITLE + "Show project '#{project["name"]}' with user 'root'"92 run_test_with_block "project show #{project["name"]} --format json" do |p|93 pr = JSON.parse(p)94 envs = true95 pr["deploy_envs"].each {|e| envs = (envs and e["users"].include?("root"))}96 envs97 end98 self.title = TITLE + "Delete user 'root' from project '#{project["name"]}'"99 run_tests [ "project user delete #{project["name"]} root -y" ]100 self.title = TITLE + "Show project '#{project["name"]}' without user 'root'"101 run_test_with_block "project show #{project["name"]} --format json" do |p|102 pr = JSON.parse(p)103 envs = true104 pr["deploy_envs"].each {|e| envs = (envs and !e["users"].include?("root"))}105 envs106 end107 create_server project["name"], env_os["identifier"], openstack108 create_server project["name"], env_ec2["identifier"], ec2109 self.title = TITLE + "Delete project '#{project["name"]}'"110 run_tests [ "project delete #{project["name"]} -y" ]111 clear openstack112 clear ec2113 end114 def check_envs origin, created115 r = true116 %w(flavor groups identifier image provider run_list subnets users expires).each do |key|117 flag = (origin[key] == created[key])118 unless flag119 puts "Environments params '#{key}' not equals ('#{origin[key].inspect}' and '#{created[key].inspect}')"120 end121 r = r and flag122 end123 r124 end125 def prepare conf126 name = conf[:name]127 self.title = TITLE + "Check #{name} flavor"128 run_test_with_block "flavor list #{name} --format json" do |f|129 flavors = JSON.parse(f)130 !flavors.detect{|o| o["id"] == conf[:flavor]}.nil?131 end132 image_in_filter = false133 self.title = TITLE + "Check #{name} filter"134 run_test_with_block "filter image list #{name} --format json" do |i|135 images = JSON.parse(i)136 image_in_filter = !images.index(conf[:image]).nil?137 true138 end139 if image_in_filter140 puts_warn "Image '#{conf[:image]}' for '#{name}' already in filter"141 else142 self.title = TITLE + "Add #{name} filter"143 run_tests [ "filter image add #{name} #{conf[:image]}" ]144 end145 image_created = false146 self.title = TITLE + "Check image for #{name}"147 run_test_with_block "image list #{name} --format json" do |s|148 images = JSON.parse s149 image_created = !images.detect{|i| i["id"] == conf[:image]}.nil?150 true151 end152 if image_created153 puts_warn "Image '#{conf[:image]}' for '#{name}' already created"154 else155 self.title = TITLE + "Create image for #{name}"156 run_tests [ "image create --image #{conf[:image]} --ssh_user #{conf[:ssh_user]} --provider #{name} --no_bootstrap_template -y" ]157 end158 end159 def create_server project, env, conf160 self.title = TITLE + "Create server '#{conf[:server_name]}'"161 run_tests [ "server create #{project} #{env} -N #{conf[:server_name]}" ]162 self.title = TITLE + "Is server '#{conf[:server_name]}' created"163 run_test_with_block "server list --format json" do |l|164 servers = JSON.parse l165 !servers.detect{|s| s["chef_node_name"] == conf[:server_name].to_s }.nil?166 end167 self.title = TITLE + "Pause server '#{conf[:server_name]}'"168 run_tests [ "server pause #{conf[:server_name]}" ]169 delay = (conf[:name] == "openstack" ? 5 : 90)170 puts "Sleeping for #{delay} seconds"171 sleep(delay)172 self.title = TITLE + "Check server '#{conf[:server_name]}' state"173 run_test_with_block "server list #{conf[:name]} --format json" do |s|174 servers = JSON.parse s175 state = servers.detect{|o| o["name"] == conf[:server_name]}["state"]176 if state == conf[:states][:pause]177 true178 else179 puts_error "State should be '#{conf[:states][:pause]}' but it is '#{state}'"180 false181 end182 end183 self.title = TITLE + "Unpause server '#{conf[:server_name]}'"184 run_tests [ "server unpause #{conf[:server_name]}" ]185 delay = (conf[:name] == "openstack" ? 5 : 90)186 puts "Sleeping for #{delay} seconds"187 sleep(delay)188 self.title = TITLE + "Check server '#{conf[:server_name]}' state"189 run_test_with_block "server list #{conf[:name]} --format json" do |s|190 servers = JSON.parse s191 state = servers.detect{|o| o["name"] == conf[:server_name]}["state"]192 if state == conf[:states][:unpause]193 true194 else195 puts_error "State should be '#{conf[:states][:unpause]}' but it is '#{state}'"196 false197 end198 end199 tag = "tag_" + conf[:name]200 self.title = TITLE + "Add tag '#{tag}' to server '#{conf[:server_name]}'"201 run_tests [202 "tag create #{conf[:server_name]} #{tag}",203 "tag create #{conf[:server_name]} #{tag}"204 ]205 self.title = TITLE + "Check tag '#{tag}' for server '#{conf[:server_name]}'"206 run_test_with_block "tag list #{conf[:server_name]} --format json" do |t|207 JSON.parse(t).include?(tag)208 end209 tag2 = tag + "_2"210 self.title = TITLE + "Check deploy with tag '#{tag2}' for server '#{conf[:server_name]}'"211 run_tests ["deploy #{conf[:server_name]} -t #{tag2}"]212 self.title = TITLE + "Check tag '#{tag}' for server '#{conf[:server_name]}'"213 run_test_with_block "tag list #{conf[:server_name]} --format json" do |t|214 JSON.parse(t).include?(tag)215 !JSON.parse(t).include?(tag2)216 end217 self.title = TITLE + "Delete tag '#{tag}' from server '#{conf[:server_name]}'"218 run_tests [219 "tag delete #{conf[:server_name]} #{tag} -y",220 "tag delete #{conf[:server_name]} #{tag} -y"221 ]222 self.title = TITLE + "Delete server '#{conf[:server_name]}'"223 run_tests [ "server delete #{conf[:server_name]} -y" ]224 end225 def clear conf226 name = conf[:name]227 self.title = TITLE + "Delete image for #{name}"228 run_tests [ "image delete #{conf[:image]} -y" ]229 self.title = TITLE + "Check image for #{name}"230 run_test_with_block "image list #{name} --format json" do |s|231 images = JSON.parse s232 images.detect{|i| i["id"] == conf[:image]}.nil?233 end234 self.title = TITLE + "Delete #{name} filter"235 run_tests [ "filter image delete #{name} #{conf[:image]} -y" ]236 self.title = TITLE + "Check #{name} filter"237 run_test_with_block "filter image list #{name} --format json" do |i|238 images = JSON.parse(i)239 images.index(conf[:image]).nil?240 end241 end242end...
Rakefile
Source:Rakefile
1def run_tests(platform, browser, version)2 system("platform=\"#{platform}\" browserName=\"#{browser}\" version=\"#{version}\"")3end4task :windows_10_ie_11 do5 run_tests('Windows 10', 'internet explorer', '11')6end7task :windows_7_firefox_latest do8 run_tests('Windows 7', 'firefox', 'latest')9end10task :os_x_10_14_chrome_latest do11 run_tests('OS X 10.14', 'chrome', 'latest')12end13task :ubuntu_20_04_chrome_latest do14 run_tests('Ubuntu-20.04 10.14', 'chrome', 'latest')15end16task :single_exec, [:project, :browser] do17 project = project18 browser = browser19 puts ("<< Project: #{project}, Process: 1, Browser: #{browser} >>")20 system "rspec spec/features/step_definitions/homepage_steps.rb"21end22task :default do23 Rake::Task[:single_exec].invoke('ubuntu_20_04_chrome_latest', 'chrome', 'latest')24end...
project.rb
Source:project.rb
2class Project < BaseTest3 TITLE = "Project tests"4 def run5 self.title = TITLE6 run_tests ["project list"]7 run_tests ["project create endtest --groups default --deploy_env dev --flavor c1.small --image cirros --run_list role[devops_service_dev] -y"]8 run_tests ["project show test"]9 run_tests ["project servers test"]10 run_tests ["project set run_list test dev role[devops_service_dev]"]11 run_tests ["project update test project_update_test_file"]12 run_tests ["project delete test"]13 end14end...
run_tests
Using AI Code Generation
1 before(:each) do2 @project1 = Project.new("Project 1", "description 1", "John Doe")3 @project2 = Project.new("Project 2", "description 2", "Jane Doe")4 expect(@project1.name).to eq("Changed Name")5 expect(@project1.elevator_pitch).to eq("Project 1, description 1")6 expect(@project2.elevator_pitch).to eq("Project 2, description 2")7 @project1.add_to_team("Jane Doe")8 @project1.add_to_team("Jimmy Doe")9 expect(@project1.team).to eq(["John Doe", "Jane Doe", "Jimmy Doe"])10 def initialize(name, description, owner)11 def add_to_team(member)
run_tests
Using AI Code Generation
1 @project1 = Project.new('Project 1', 'description 1', 'John Doe')2 @project2 = Project.new('Project 2', 'description 2', 'Jane Doe')3 expect(@project1.name).to eq("Changed Name")4 expect(@project1.elevator_pitch).to eq("Project 1, description 1")5 expect(@project2.elevator_pitch).to eq("Project 2, description 2")6 @project1.add_to_team("Jane Doe")7 expect(@project1.team).to eq(["John Doe", "Jane Doe"])8 def initialize(name, description, owner)9 def add_to_team(member)10 @team.push(member)
run_tests
Using AI Code Generation
1 before(:each) do2 @project1 = Project.new('Project 1', 'description 1', 'John Doe')3 @project2 = Project.new('Project 2', 'description 2', 'Jane Doe')4 expect(@project1.name).to eq('Changed Name')5 expect(@project1.elevator_pitch).to eq('Project 1, description 1')6 expect(@project2.elevator_pitch).to eq('Project 2, description 2')7 expect(@project1.owner).to eq('Changed Owner')8 expect(@project1.tasks).to eq([])9 @project1.add_tasks('This is a task')10 expect(@project1.tasks).to eq(['This is a task'])11 @project1.add_tasks('This is a task')12 expect(@project1.print_tasks).to eq('This is a task')13 expect(@project1.run_tests).to eq('Project 1, description 1, John Doe, []')14 before(:each) do15 @project1 = Project.new('Project 1', 'description 1', 'John Doe')16 @project2 = Project.new('Project 2', 'description 2', 'Jane Doe')17 expect(@project1.name).to eq('Changed Name')
run_tests
Using AI Code Generation
1 before(:each) do2 @project1 = Project.new("Project 1", "description 1")3 @project2 = Project.new("Project 2", "description 2")4 expect(@project1.name).to eq("Changed Name")5 expect(@project1.elevator_pitch).to eq("Project 1, description 1")6 @project1.add_to_team("John")7 expect(@project1.team).to eq(["John"])8 @project1.add_to_team("John")9 @project1.add_to_team("Jane")10 expect(@project1.print_team).to eq("John Jane ")11 @project1.add_to_team("John")12 expect(@project1.team).to eq(["John"])13 @project1.add_to_team("John")14 @project1.add_to_team("Jane")15 expect(@project1.print_team).to eq("John Jane ")16 expect(@project2.name).to eq("Changed Name")17 expect(@project2.elevator_pitch).to eq("Project 2, description 2")18 @project2.add_to_team("John")19 expect(@project2.team).to eq(["John"])20 @project2.add_to_team("John")
run_tests
Using AI Code Generation
1project1 = Project.new('Project ABC', 'description 1', 'John Doe')2project2 = Project.new('Project LMN', 'description 2', 'Jane Doe')3 def initialize(name, description, owner)
run_tests
Using AI Code Generation
1project1 = Project.new("Project ABC", "I am a project", "John Doe")2project2 = Project.new("Project LMN", "I am also a project", "Jane Doe")3project3 = Project.new("Project XYZ", "I am yet another project", "John Doe")4project4 = Project.new("Project 123", "I am yet another project", "John Doe")5project5 = Project.new("Project 456", "I am yet another project", "John Doe")6project6 = Project.new("Project 789", "I am yet another project", "John Doe")7project7 = Project.new("Project 101112", "I am yet another project", "John Doe")8project8 = Project.new("Project 131415", "I am yet another project", "John Doe")9project9 = Project.new("Project 161718", "I am yet another project", "John Doe")10project10 = Project.new("Project 192021", "I am yet another project", "John Doe")11project11 = Project.new("Project 222324", "I am yet another project", "John Doe")12project12 = Project.new("Project 252627", "I am yet another project", "John Doe")13project13 = Project.new("Project 282930", "I am yet another project", "John Doe")14project14 = Project.new("Project 313233", "I am yet another project", "John Doe")15project15 = Project.new("Project 343536", "I am yet another project", "John Doe")16portfolio1.add_projects(project1, project2, project3, project4, project5, project6, project7, project8, project9, project
run_tests
Using AI Code Generation
1 before(:each) do2 @project = Project.new("Project ABC", 1000, 25)3 backer = Backer.new("John Doe")4 @project.add_backer(backer)5 expect(@project.backers.include?(backer)).to eq(true)6 before(:each) do7 @project = Project.new("Project ABC", 1000, 25)8 @backer = Backer.new("John Doe")9 @project.add_backer(@backer)10 expect(@backer.backed_projects.include?(@project)).to eq(true)11 before(:each) do12 @project = Project.new("Project ABC", 1000, 25)13 @backer = Backer.new("John Doe")14 @project.add_backer(@backer)15 expect(@project.backers
run_tests
Using AI Code Generation
1 def add_file(file)2 Test::Unit::UI::Console::TestRunner.run(Object.const_get(File.basename(file, ".rb").capitalize))3project.add_file("test1.rb")4project.add_file("test2.rb")5project.add_file("test3.rb")6 def add_file(file)7 Test::Unit::UI::Console::TestRunner.run(Object.const_get(File.basename(file, ".rb").capitalize))8project.add_file("test1.rb")9project.add_file("test2.rb")10project.add_file("test3.rb")
run_tests
Using AI Code Generation
1 before(:each) do2 @project1 = Project.new("Project 1", "description 1")3 @project2 = Project.new("Project 2", "description 2")4 expect(@project1.name).to eq("Changed Name")5 expect(@project1.elevator_pitch).to eq("Project 1, description 1")6 @project1.add_to_team("John")7 expect(@project1.team).to eq(["John"])8 @project1.add_to_team("John")9 @project1.add_to_team("Jane")10 expect(@project1.print_team).to eq("John Jane ")11 @project1.add_to_team("John")12 expect(@project1.team).to eq(["John"])13 @project1.add_to_team("John")14 @project1.add_to_team("Jane")15 expect(@project1.print_team).to eq("John Jane ")16 expect(@project2.name).to eq("Changed Name")17 expect(@project2.elevator_pitch).to eq("Project 2, description 2")18 @project2.add_to_team("John")19 expect(@project2.team).to eq(["John"])20 @project2.add_to_team("John")
run_tests
Using AI Code Generation
1project1 = Project.new("Project ABC", "I am a project", "John Doe")2project2 = Project.new("Project LMN", "I am also a project", "Jane Doe")3project3 = Project.new("Project XYZ", "I am yet another project", "John Doe")4project4 = Project.new("Project 123", "I am yet another project", "John Doe")5project5 = Project.new("Project 456", "I am yet another project", "John Doe")6project6 = Project.new("Project 789", "I am yet another project", "John Doe")7project7 = Project.new("Project 101112", "I am yet another project", "John Doe")8project8 = Project.new("Project 131415", "I am yet another project", "John Doe")9project9 = Project.new("Project 161718", "I am yet another project", "John Doe")10project10 = Project.new("Project 192021", "I am yet another project", "John Doe")11project11 = Project.new("Project 222324", "I am yet another project", "John Doe")12project12 = Project.new("Project 252627", "I am yet another project", "John Doe")13project13 = Project.new("Project 282930", "I am yet another project", "John Doe")14project14 = Project.new("Project 313233", "I am yet another project", "John Doe")15project15 = Project.new("Project 343536", "I am yet another project", "John Doe")16portfolio1.add_projects(project1, project2, project3, project4, project5, project6, project7, project8, project9, project
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!