Best Rr_ruby code snippet using Project.create_file
client_spec.rb
Source:client_spec.rb
...173 end174 it 'lists files and folders' do175 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')176 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)177 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket)178 expect_output("metis://athena/armor", "ls") { %r!helmet.jpg.*helmet/!m }179 end180 it 'lists files and folders in long format' do181 Timecop.freeze(DateTime.parse("2020-06-17T04:37"))182 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')183 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)184 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket)185 stubs.create_file('athena', 'armor', 'helmet.jpg', HELMET)186 expect_output("metis://athena/armor", "ls", "-l") {187 "metis Jun 17 04:37 n/a n/a helmet/\n"+188 "metis 13 Jun 17 04:37 unarchived 6a0c7b898caf79d8137415427cca3b6e helmet.jpg\n"189 }190 Timecop.return191 end192 it 'lists files and folders recursively' do193 Timecop.freeze(DateTime.parse("2020-06-17T04:37"))194 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')195 blueprints_folder = create_folder('athena', 'blueprints', bucket: bucket)196 helmet_folder = create_folder('athena', 'helmet', bucket: bucket, folder: blueprints_folder)197 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)198 stubs.create_file('athena', 'armor', 'blueprints/helmet/helmet.jpg', HELMET)199 ENV['COLUMNS'] = '80'200 expect_output("metis://athena/armor", "ls", "-r") {201 "armor/blueprints/\n"+202 "armor/blueprints/helmet/ armor/blueprints/helmet/helmet.jpg\n"203 }204 Timecop.return205 end206 it 'lists files and folders recursively in long format' do207 Timecop.freeze(DateTime.parse("2020-06-17T04:37"))208 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')209 blueprints_folder = create_folder('athena', 'blueprints', bucket: bucket)210 helmet_folder = create_folder('athena', 'helmet', bucket: bucket, folder: blueprints_folder)211 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)212 stubs.create_file('athena', 'armor', 'blueprints/helmet/helmet.jpg', HELMET)213 ENV['COLUMNS'] = '80'214 expect_output("metis://athena/armor", "ls", "-r", "-l") {215 "metis Jun 17 04:37 n/a n/a armor/blueprints/\n"+216 "metis Jun 17 04:37 n/a n/a armor/blueprints/helmet/\n"+217 "metis 13 Jun 17 04:37 unarchived 6a0c7b898caf79d8137415427cca3b6e armor/blueprints/helmet/helmet.jpg\n"218 }219 Timecop.return220 end221 it 'lists from a directory' do222 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')223 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)224 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)225 expect_output("metis://athena/armor/helmet", "ls") { "helmet.jpg\n" }226 end227 it 'lists a parent directory' do228 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')229 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)230 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)231 expect_output("metis://athena/armor/helmet", "ls", "..") { "helmet/\n" }232 end233 it 'lists the current directory' do234 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')235 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)236 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)237 expect_output("metis://athena/armor/helmet", "ls", ".") { "helmet.jpg\n" }238 end239 it 'lists a sub-directory' do240 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')241 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)242 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)243 expect_output("metis://athena/armor/", "ls", "helmet") { "helmet.jpg\n" }244 end245 it 'lists the project root directory' do246 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')247 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)248 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)249 expect_output("metis://athena/armor/helmet", "ls", "/") { "armor/\n" }250 end251 it 'lists files directly' do252 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')253 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)254 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)255 stubs.create_file('athena', 'armor', 'helmet/helmet.jpg', HELMET)256 expect_output("metis://athena/armor", "ls", "helmet/helmet.jpg") { %r!armor/helmet/helmet.jpg!m }257 end258 it 'lists files directly in long format' do259 Timecop.freeze(DateTime.parse("2020-06-17T04:37"))260 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')261 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)262 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)263 stubs.create_file('athena', 'armor', 'helmet/helmet.jpg', HELMET)264 expect_output("metis://athena/armor", "ls", "-l", "helmet/helmet.jpg") {265 "metis 13 Jun 17 04:37 unarchived 6a0c7b898caf79d8137415427cca3b6e armor/helmet/helmet.jpg\n"266 }267 Timecop.return268 end269 end270 describe MetisShell::Put do271 # WebMock does not handle multipart/form-data, so it272 # strips out the body data on those POST requests.273 # So this is actually impossible to test except in274 # a 'production' environment.275 it 'puts a file into a bucket' do276 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')277 helmet_path = stubs.create_data('stubs', 'helmet.txt', HELMET)278 expect_output("metis://athena/armor", "put", helmet_path, '.') { nil }279 expect(WebMock).to have_requested(:post, /https:\/\/metis.test\/authorize\/upload/).280 with(body: hash_including({281 "project_name": "athena",282 "bucket_name": "armor",283 "file_path": "helmet.txt"284 }))285 end286 it 'puts a file into a sub-folder' do287 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')288 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)289 helmet_path = stubs.create_data('stubs', 'helmet.txt', HELMET)290 expect_output("metis://athena/armor", "put", helmet_path, 'helmet') { nil }291 expect(WebMock).to have_requested(:post, /https:\/\/metis.test\/authorize\/upload/).292 with(body: hash_including({293 "project_name": "athena",294 "bucket_name": "armor",295 "file_path": "helmet/helmet.txt"296 }))297 end298 it 'retries to upload a file into a bucket on a 422 response' do299 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')300 helmet_path = stubs.create_data('stubs', 'helmet.txt', HELMET)301 expect_output("metis://athena/armor", "put", helmet_path, '.') { nil }302 # There is a call to authorize the upload303 expect(WebMock).to have_requested(:post, /https:\/\/metis.test\/authorize\/upload/).304 with(body: hash_including({305 "project_name": "athena",306 "bucket_name": "armor",307 "file_path": "helmet.txt"308 }))309 # There is a non-reset call to start the upload310 expect(WebMock).to have_requested(:post, /https:\/\/metis.test\/athena\/upload\/armor\/helmet.txt/).311 with(query: hash_including({312 "X-Etna-Id": "metis",313 "X-Etna-Headers": "email,name"314 })).315 with(headers: {316 "Content-Type": "application/json"317 }).318 with { |req| (req.body.include? 'start') && !(req.body.include? 'reset')}319 # There are two attempts to upload blobs. One for the original attempt,320 # and one for the retry.321 expect(WebMock).to have_requested(:post, /https:\/\/metis.test\/athena\/upload\/armor\/helmet.txt/).322 with(query: hash_including({323 "X-Etna-Id": "metis"324 })).325 with(headers: {326 "Content-Type": "multipart/form-data"327 }).twice328 # There is a call to reset the upload329 expect(WebMock).to have_requested(:post, /https:\/\/metis.test\/athena\/upload\/armor\/helmet.txt/).330 with(query: hash_including({331 "X-Etna-Id": "metis"332 })).333 with(headers: {334 "Content-Type": "application/json"335 }).336 with { |req| (req.body.include? 'start') && (req.body.include? 'reset')}337 end338 end339 describe MetisShell::Get do340 before(:each) do341 # cleanup342 FileUtils.rm_rf('spec/data/helmet')343 end344 after(:each) do345 # cleanup346 FileUtils.rm_rf('spec/data/helmet')347 end348 it 'downloads a folder from a bucket' do349 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')350 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)351 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)352 stubs.create_file('athena', 'files', 'armor/helmet/helmet.jpg', HELMET)353 stub_metis_download("/athena/download/armor/helmet/helmet.jpg", HELMET)354 # it shows download progress355 expect_output("metis://athena/armor", "get", "helmet", "spec/data") { /helmet.jpg.*k?B\/s/ }356 end357 it 'does not download data if local file size matches' do358 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')359 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)360 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)361 stubs.create_file('athena', 'files', 'armor/helmet/helmet.jpg', HELMET)362 stub_metis_download("/athena/download/armor/helmet/helmet.jpg", HELMET)363 # first time it shows download progress364 expect_output("metis://athena/armor", "get", "helmet", "spec/data") { /helmet.jpg.*k?B\/s/ }365 # second time it shows no progress366 expect_output("metis://athena/armor", "get", "helmet", "spec/data") { /(?!k?B\/s).*/ }367 end368 it 'will re-download data if the local file size does not match' do369 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')370 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)371 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)372 stubs.create_file('athena', 'files', 'armor/helmet/helmet.jpg', HELMET)373 stub_metis_download("/athena/download/armor/helmet/helmet.jpg", HELMET)374 # first time it shows download progress375 expect_output("metis://athena/armor", "get", "helmet", "spec/data") { /helmet.jpg.*k?B\/s/ }376 # At this point there will be a file created locally, so we'll tweak the377 # server contents to be a different size.378 helmet_file = create_file('athena', 'helmet.jpg', SHINY_HELMET, bucket: bucket, folder: helmet_folder)379 stubs.create_file('athena', 'files', 'armor/helmet/helmet.jpg', SHINY_HELMET)380 stub_metis_download("/athena/download/armor/helmet/helmet.jpg", SHINY_HELMET)381 # second time it still shows download progress382 expect_output("metis://athena/armor", "get", "helmet", "spec/data") { /helmet.jpg.*k?B\/s/ }383 expect(::File.read("spec/data/helmet/helmet.jpg")).to eq(SHINY_HELMET)384 end385 it 'will re-start a download if it is incomplete' do386 allow_any_instance_of(MetisShell::Get).to receive(:sleep)387 388 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')389 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)390 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)391 stubs.create_file('athena', 'files', 'armor/helmet/helmet.jpg', HELMET)392 # Should get Incomplete message393 expect_error("metis://athena/armor", "get", "helmet", "spec/data") { /Incomplete download/ }394 stub_metis_download("/athena/download/armor/helmet/helmet.jpg", HELMET)395 # second time it will finish the download396 expect_output("metis://athena/armor", "get", "helmet", "spec/data") { /helmet.jpg.*k?B\/s/ }397 expect(::File.read("spec/data/helmet/helmet.jpg")).to eq(HELMET)398 end399 end400 describe MetisShell::Mkdir do401 it 'warns if the path folder exists' do402 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')403 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)404 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)405 stubs.create_file('athena', 'files', 'armor/helmet/helmet.jpg', HELMET)406 expect(Metis::Folder.count).to eq(1)407 expect_error("metis://athena/armor", "mkdir", "helmet") { /Folder already exists/ }408 expect(Metis::Folder.count).to eq(1)409 end410 it 'creates a folder hierarchy like mkdir -p' do411 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')412 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)413 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)414 stubs.create_file('athena', 'files', 'armor/helmet/helmet.jpg', HELMET)415 expect(Metis::Folder.count).to eq(1)416 expect_output("metis://athena/armor", "mkdir", "shield/shiny/padded") { // }417 expect(Metis::Folder.count).to eq(4)418 end419 it 'retries if Metis is down' do420 stub_metis_create_folder421 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')422 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)423 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)424 stubs.create_file('athena', 'files', 'armor/helmet/helmet.jpg', HELMET)425 expect_output("metis://athena/armor", "mkdir", "helmet/copy") { /retrying/ }426 expect(WebMock).to have_requested(:post, /folder\/create/).times(2)427 end428 end429 describe MetisShell::Rm do430 it 'warns if the path does not exist' do431 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')432 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)433 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)434 stubs.create_file('athena', 'files', 'armor/helmet/helmet.jpg', HELMET)435 expect(Metis::File.count).to eq(1)436 expect_error("metis://athena/armor", "rm", "helmet/helmet2.jpg") { /Invalid path/ }437 expect(Metis::File.count).to eq(1)438 end439 it 'warns if the parent folder does not exist' do440 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')441 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)442 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)443 stubs.create_file('athena', 'files', 'armor/helmet/helmet.jpg', HELMET)444 expect(Metis::File.count).to eq(1)445 expect_error("metis://athena/armor", "rm", "helmet2/helmet.jpg") { /Invalid folder/ }446 expect(Metis::File.count).to eq(1)447 end448 it 'removes a file' do449 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')450 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)451 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)452 stubs.create_file('athena', 'files', 'armor/helmet/helmet.jpg', HELMET)453 expect(Metis::File.count).to eq(1)454 expect_output("metis://athena/armor", "rm", "helmet/helmet.jpg") { // }455 expect(Metis::File.count).to eq(0)456 end457 it 'does nothing if the source folder does not exist' do458 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')459 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)460 expect(Metis::Folder.count).to eq(1)461 expect_error("metis://athena/armor", "rm", "helmet2") { /Invalid path/ }462 expect(Metis::Folder.count).to eq(1)463 end464 it 'removes a folder' do465 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')466 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)467 expect(Metis::Folder.count).to eq(1)468 expect_output("metis://athena/armor", "rm", "helmet") { // }469 expect(Metis::Folder.count).to eq(0)470 end471 472 it 'removes a folder recursively' do473 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')474 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)475 old_folder = create_folder('athena', 'old', folder: helmet_folder, bucket: bucket)476 expect(Metis::Folder.count).to eq(2)477 expect_output("metis://athena/armor", "rm", "-r", "helmet") { // }478 expect(Metis::Folder.count).to eq(0)479 end480 it 'retries if Metis is down' do481 stub_metis_rm_folder482 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')483 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)484 expect_output("metis://athena/armor", "rm", "helmet") { /retrying/ }485 expect(WebMock).to have_requested(:delete, /folder\/remove/).times(2)486 end487 end488 describe MetisShell::Cp do489 it 'copies a file in the same directory' do490 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')491 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)492 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)493 stubs.create_file('athena', 'files', 'armor/helmet/helmet.jpg', HELMET)494 expect(Metis::File.count).to eq(1)495 expect_output("metis://athena/armor/helmet", "cp", "helmet.jpg", "helmet2.jpg") { // }496 expect(Metis::File.count).to eq(2)497 end498 it 'copies a file using a relative destination path' do499 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')500 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)501 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)502 stubs.create_file('athena', 'files', 'armor/helmet/helmet.jpg', HELMET)503 sub_folder = create_folder('athena', 'sub_helmet', bucket: bucket, folder: helmet_folder)504 expect(Metis::File.count).to eq(1)505 expect_output("metis://athena/armor/helmet/sub_helmet", "cp", "../helmet.jpg", ".") { // }506 expect(Metis::File.count).to eq(2)507 end508 it 'copies a file using a relative parent destination path' do509 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')510 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)511 sub_folder = create_folder('athena', 'sub_helmet', bucket: bucket, folder: helmet_folder)512 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: sub_folder)513 stubs.create_file('athena', 'files', 'armor/helmet/sub_folder/helmet.jpg', HELMET)514 expect(Metis::File.count).to eq(1)515 expect_output("metis://athena/armor/helmet/sub_helmet", "cp", "helmet.jpg", "../") { // }516 expect(Metis::File.count).to eq(2)517 end518 it 'copies a file to a new bucket using metis path' do519 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')520 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)521 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)522 stubs.create_file('athena', 'files', 'armor/helmet/helmet.jpg', HELMET)523 sundry_bucket = create( :bucket, project_name: 'athena', name: 'sundry', access: 'editor', owner: 'metis')524 expect(Metis::File.count).to eq(1)525 expect_output("metis://athena/armor/helmet", "cp", "helmet.jpg", "metis://athena/sundry/helmet.jpg") { // }526 expect(Metis::File.count).to eq(2)527 end528 it 'copies a file from a different bucket using metis path' do529 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')530 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)531 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket, folder: helmet_folder)532 stubs.create_file('athena', 'files', 'armor/helmet/helmet.jpg', HELMET)533 sundry_bucket = create( :bucket, project_name: 'athena', name: 'sundry', access: 'editor', owner: 'metis')534 expect(Metis::File.count).to eq(1)535 expect_output("metis://athena/sundry", "cp", "metis://athena/armor/helmet/helmet.jpg", "helmet.jpg") { // }536 expect(Metis::File.count).to eq(2)537 end538 end539 describe MetisShell::Peek do540 describe 'throws error if you peek at' do541 it 'buckets' do542 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')543 expect_error("metis://athena", "peek", "0", "1", "armor") { %r!Cannot peek at buckets!}544 end545 546 it 'folders' do547 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')548 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)549 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket)550 expect_error("metis://athena/armor", "peek", "0", "1", "helmet") { %r!Cannot peek at folders! }551 end552 it 'non-existent files' do553 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')554 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)555 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket)556 expect_error("metis://athena/armor", "peek", "0", "1", "vaporware.jpg") { %r!File does not exist! }557 end558 end559 560 it 'peeks at a file' do561 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')562 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)563 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket)564 stubs.create_file('athena', 'armor', 'helmet.jpg', HELMET)565 MetisShell.new("metis://athena", "peek", "4", "5", "armor/helmet.jpg").run566 expect(WebMock).to have_requested(:get, /https:\/\/metis.test\/athena\/download/).567 with(headers: {568 "Range": "bytes=4-8"569 })570 end571 it 'can write peek output to a file' do572 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')573 helmet_folder = create_folder('athena', 'helmet', bucket: bucket)574 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket)575 stubs.create_file('athena', 'armor', 'helmet.jpg', HELMET)576 tmp = Tempfile.new577 stub_request(:get, /download/)578 .to_return({579 status: 200,580 body: "partial-chunk"581 })582 MetisShell.new("metis://athena", "peek", "4", "5", "armor/helmet.jpg", tmp.path).run583 expect(WebMock).to have_requested(:get, /https:\/\/metis.test\/athena\/download/).584 with(headers: {585 "Range": "bytes=4-8"586 })587 expect(tmp.read).to eq("partial-chunk")588 tmp.close589 tmp.unlink590 end591 end592 describe MetisShell::Nuke do593 it 'nukes a local directory except for missing files' do594 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')595 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket)596 stubs.create_file('athena', 'armor', 'helmet.jpg', HELMET)597 wisdom_file = create_file('athena', 'wisdom.txt', WISDOM, bucket: bucket)598 stubs.create_file('athena', 'files', 'wisdom.txt', WISDOM)599 stubs.send(:stub_file,'athena-copy/new/wisdom-copy.txt', WISDOM)600 stubs.send(:stub_file,'athena-copy/new/helmet-copy.txt', HELMET)601 stubs.send(:stub_file,'athena-copy/old/folly-copy.txt', WISDOM.reverse)602 MetisShell.new("metis://athena", "nuke", "athena-copy").run603 expect(::File.exists?('athena-copy/old/folly-copy.txt')).to be_truthy604 expect(::File.exists?('athena-copy/old')).to be_truthy605 expect(::File.exists?('athena-copy/new')).to be_falsy606 FileUtils.rm_r('athena-copy')607 end608 it 'nukes a local directory but keeps parent folder' do609 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')610 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket)611 stubs.create_file('athena', 'armor', 'helmet.jpg', HELMET)612 wisdom_file = create_file('athena', 'wisdom.txt', WISDOM, bucket: bucket)613 stubs.create_file('athena', 'files', 'wisdom.txt', WISDOM)614 stubs.send(:stub_file,'athena-copy/new/wisdom-copy.txt', WISDOM)615 stubs.send(:stub_file,'athena-copy/new/helmet-copy.txt', HELMET)616 MetisShell.new("metis://athena", "nuke", "athena-copy").run617 expect(::File.exists?('athena-copy/old')).to be_falsy618 expect(::File.exists?('athena-copy')).to be_truthy619 FileUtils.rm_r('athena-copy')620 end621 end622 describe MetisShell::Validate do623 it 'validates a local directory for missing files' do624 bucket = create( :bucket, project_name: 'athena', name: 'armor', access: 'editor', owner: 'metis')625 helmet_file = create_file('athena', 'helmet.jpg', HELMET, bucket: bucket)626 stubs.create_file('athena', 'armor', 'helmet.jpg', HELMET)627 wisdom_file = create_file('athena', 'wisdom.txt', WISDOM, bucket: bucket)628 stubs.create_file('athena', 'files', 'wisdom.txt', WISDOM)629 stubs.send(:stub_file,'athena-copy/new/wisdom-copy.txt', WISDOM)630 stubs.send(:stub_file,'athena-copy/new/helmet-copy.txt', HELMET)631 stubs.send(:stub_file,'athena-copy/old/folly-copy.txt', WISDOM.reverse)632 expect_output("metis://athena", "validate", "athena-copy") { /Found 2 of 3 files on Metis/ }633 FileUtils.rm_r('athena-copy')634 end635 end636end...
command.rb
Source:command.rb
...92 # invoke :create_fastfile93 end94 private95 def create_github_action_file(is_public, nickname, project_name, template_path)96 create_file("Gemfile.rb", FileTemplate.render_template("Gemfile_py.rb"))97 say("we need your codecov project key", :green)98 say("get your upload key form this url", :green)99 say("https://codecov.io/gh/#{nickname}/#{project_name}/settings", :yellow)100 while !yes?("finished it?")101 end102 say("Add this key to github project setting as a secret, named [CODECOV_SECRET]", :green)103 say("https://github.com/#{nickname}/#{project_name}/settings/secrets/new", :yellow)104 create_file("README.md", FileTemplate.render_template("README.md"))105 create_file(".pylintrc", FileTemplate.render_template("pylintrc"))106 create_file("environment.yml", FileTemplate.render_template("environment.yml"))107 create_file(".gitignore", FileTemplate.render_template("py_gitignore"))108 say("you need create a personal access tokin in github setting, click the link below", :green)109 say("https://github.com/settings/tokens/new", :yellow)110 while !yes?("finished it?")111 end112 say("Add this token to github project setting as a secret, named [REPORT_TOKEN]", :green)113 say("https://github.com/#{nickname}/#{project_name}/settings/secrets/new", :yellow)114 create_file("Dangerfile.rb", FileTemplate.render_template("Dangerfile-py.rb"))115 empty_directory(".github/workflows")116 MyCLI.source_root(template_path)117 copy_file("github/workflows/main.yml", ".github/workflows/main.yml")118 end119 def create_ci_file(is_public, is_project, nickname, project_name)120 create_file("Gemfile", FileTemplate.render_template("Gemfile.rb"))121 if is_public122 create_file("README.md", FileTemplate.render_template("README.md"))123 say("we need your codecov project key", :green)124 say("get your key form this url", :green)125 say("https://codecov.io/gh/#{nickname}/#{project_name}/settings", :yellow)126 codecov_key = ask("your token: ")127 create_file(".travis.yml",128 FileTemplate.render_template(129 "travis.yml",130 {codecov_key: codecov_key}))131 say("you need sync the github project in travis", :green)132 say("https://travis-ci.org/account/repositories", :yellow)133 while !yes?("finished it?")134 end135 unless is_project136 generate_token(nickname, project_name, "PUBLISH_KEY")137 create_file(".travis/publish.rb",138 FileTemplate.render_template(139 "publish.rb",140 {codecov_key: codecov_key}))141 end142 generate_token(nickname, project_name, "DANGER_GITHUB_API_TOKEN")143 create_file("Dangerfile", FileTemplate.render_template("Dangerfile.rb"))144 else145 generate_token(nickname, project_name, "DANGER_GITLAB_API_TOKEN", true)146 create_file(".gitlab-ci.yml", FileTemplate.render_template("gitlab-ci.yml"))147 create_file("DangerfileGitlab", FileTemplate.render_template("Dangerfile.rb"))148 end149 end150 def create_swiftlint(is_project, xcodefile)151 create_file(".swiftlint.yml",152 FileTemplate.render_template("swiftlint.yml"))153 say("Do you need create a build script in xcode?", :yellow)154 if yes?("input y for creating: ")155 project = Xcodeproj::Project.open(xcodefile)156 target = project.targets.first157 puts target.build_phases158 unless target.build_phases.find{|p| p.respond_to?("name") && p.name =="swiftlint"}159 phrase = target.new_shell_script_build_phase("swiftlint")160 swift_lint = is_project ? "swiftlint" : 'swiftlint --path "${PROJECT_DIR}/.."'161 puts phrase162 phrase.shell_script = <<-EOF163if which swiftlint >/dev/null; then164#{swift_lint}165else166echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"167fi168 EOF169 puts "project save"170 puts project.save171 end172 end173 end174 def create_fastfile175 create_file("fastlane/Fastfile",176 FileTemplate.render_template("Fastfile.rb"))177 end178 def generate_token(nickname, project_name, token_name, is_gitlab = false)179 say("you need create a personal access tokin in github setting, click the link below", :green)180 say("https://github.com/settings/tokens/new", :yellow)181 say("you need create a env variables in travis or gitlab setting with name of #{token_name} and with value of the up token", :green)182 if is_gitlab183 say("https://gitlab.com/#{nickname}/#{project_name}/-/settings/ci_cd", :yellow)184 else185 say("https://travis-ci.org/#{nickname}/#{project_name}/settings", :yellow)186 end187 while !yes?("finished it?")188 end189 end...
path_fetcher_spec.rb
Source:path_fetcher_spec.rb
...19 subject { described_class.new(manifest_entry, project_dir, build_dir) }20 describe "#fetch_required?" do21 context "when the directories have different files" do22 before do23 create_file("#{source_path}/directory/file") { "different" }24 create_file("#{project_dir}/directory/file") { "same" }25 end26 it "return true" do27 expect(subject.fetch_required?).to be_truthy28 end29 end30 context "when the directories have the same files" do31 before do32 create_file("#{source_path}/directory/file") { "same" }33 create_file("#{project_dir}/directory/file") { "same" }34 end35 it "returns false" do36 expect(subject.fetch_required?).to be(false)37 end38 end39 end40 describe "#version_guid" do41 it "includes the source path" do42 expect(subject.version_guid).to eq("path:#{source_path}")43 end44 end45 describe "#fetch" do46 before do47 create_file("#{source_path}/file_a")48 create_file("#{source_path}/file_b")49 create_file("#{source_path}/.file_c")50 remove_file("#{source_path}/file_d")51 create_file("#{project_dir}/file_a")52 remove_file("#{project_dir}/file_b")53 remove_file("#{project_dir}/.file_c")54 create_file("#{project_dir}/file_d")55 end56 it "fetches new files" do57 subject.fetch58 expect("#{project_dir}/file_a").to be_a_file59 expect("#{project_dir}/file_b").to be_a_file60 expect("#{project_dir}/.file_c").to be_a_file61 end62 it "removes extraneous files" do63 subject.fetch64 expect("#{project_dir}/file_d").to_not be_a_file65 end66 end67 describe "#clean" do68 it "returns true" do69 expect(subject.clean).to be_truthy70 end71 end72 describe "#version_for_cache" do73 before do74 create_file("#{source_path}/file_a")75 create_file("#{source_path}/file_b")76 create_file("#{source_path}/.file_c")77 end78 let(:sha) { "69553b23b84e69e095b4a231877b38022b1ffb41ae0ecbba6bb2625410c49f7e" }79 it "includes the source_path and shasum" do80 expect(subject.version_for_cache).to eq("path:#{source_path}|shasum:#{sha}")81 end82 end83 describe "#resolve_version" do84 it "just returns the version" do85 expect(NetFetcher.resolve_version("1.2.3", source)).to eq("1.2.3")86 end87 end88 end89end...
create_file
Using AI Code Generation
1project1 = Project.new('Project ABC', 1000, 5000)2 def initialize(name, funding, taeg_t_funding)3 def initialize(name, funding, target_funding)
create_file
Using AI Code Generation
1project = Project.new('Project ABC', 'I am a project', 5000)2 def initialize(name, description, target_funding)3 def initialize(name, description, target_funding)4 def initialize(name, description, target_funding)5 def initialize(name, description
create_file
Using AI Code Generation
1project = Project.new('project_name')2project.create_file('file_name')3project.add_content('file_name', 'content to be added to file')4project = Project.new('project_name')5project.create_file('file_name')6project.add_content('file_name', 'content to be added to file')7 def initialize(name)8 def create_file(file_name)9 def add_content(file_name, content)10 def initialize(name)11 def create_file(file_name)12 def add_content(file_name, content)13 def initialize(name)14 def create_file(file_name)15 def add_content(file_name, content)16 def initialize(name)17 def create_file(file_name)18 def add_content(file_name, content)19 def initialize(name)20 def create_file(file_name)21 def add_content(file_name, content)22 def initialize(name)23 def create_file(file_name)24 def add_content(file_name, content)
create_file
Using AI Code Generation
1project = Projectnew('projec_name')2project.create_file('file_name')3project.add_content('file_name', 'content to be added to file')4project = Project.new('project_name')5project.create_file('file_name')6project.add_content('file_name', 'content to be added to file')7 def initialize(name)8 def create_file(file_name)9 def add_content(file_name, content)10 def initialize(name)11 def create_file(file_name)12 def add_content(file_name, content)13 def initialize(name)14 def create_file(file_name)15 def add_content(file_name, content)16 def initialize(name)17 def create_file(file_name)18 def add_content(file_name, content)19 def initialize(name)20 def create_file(file_name)21 def add_content(file_name, content)22 def initialize(name)23 def create_file(file_name)24 def add_content(file_name, content)
create_file
Using AI Code Generation
1f = Project.create_file('test.txt')2f = Project.read_file('test.txt')3f.each { |line| puts line }4Project.delete_file('test.txt')5Project.create_dir('test')6Project.delete_dir('test')7Project.copy_file('test.txt', 'test2.txt')8Project.move_file('test2.txt', 'test/test2.txt')9Project.rename_file('test/test2.txt', 'test/test3.txt')10Project.copy_dir('test', 'test2')11Project.move_dir('test2', 'test/test2')12Project.rename_dir('test/test2', 'test/test3')13 def initialize(name, funding, target_funding)
create_file
Using AI Code Generation
1my_project = Project.new("Project ABC")2my_project.add_to_team("John Doe")3my_project.create_file("my_file.txt")4my_project = Project.new("Project XYZ")5my_project.add_to_team("Jane Doe")6my_project.create_file("my_file.txt")7def create_file(name)
create_file
Using AI Code Generation
1f = Project.create_file('test.txt')2f = Project.read_file('test.txt')3f.each { |line| puts line }4Project.delete_file('test.txt')5Project.create_dir('test')6Project.delete_dir('test')7Project.copy_file('test.txt', 'test2.txt')8Project.move_file('test2.txt', 'test/test2.txt')9Project.rename_file('test/test2.txt', 'test/test3.txt')10Project.copy_dir('test', 'test2')11Project.move_dir('test2', 'test/test2')12Project.rename_dir('test/test2', 'test/test3')
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!!