How to use outdated method of Gem Package

Best Rr_ruby code snippet using Gem.outdated

outdated_spec.rb

Source:outdated_spec.rb Github

copy

Full Screen

1# frozen_string_literal: true2RSpec.describe "bundle outdated" do3 before :each do4 build_repo2 do5 build_git "foo", :path => lib_path("foo")6 build_git "zebra", :path => lib_path("zebra")7 end8 install_gemfile <<-G9 source "file://#{gem_repo2}"10 gem "zebra", :git => "#{lib_path("zebra")}"11 gem "foo", :git => "#{lib_path("foo")}"12 gem "activesupport", "2.3.5"13 gem "weakling", "~> 0.0.1"14 gem "duradura", '7.0'15 gem "terranova", '8'16 G17 end18 describe "with no arguments" do19 it "returns a sorted list of outdated gems" do20 update_repo2 do21 build_gem "activesupport", "3.0"22 build_gem "weakling", "0.2"23 update_git "foo", :path => lib_path("foo")24 update_git "zebra", :path => lib_path("zebra")25 end26 bundle "outdated"27 expect(out).to include("activesupport (newest 3.0, installed 2.3.5, requested = 2.3.5)")28 expect(out).to include("weakling (newest 0.2, installed 0.0.3, requested ~> 0.0.1)")29 expect(out).to include("foo (newest 1.0")30 # Gem names are one per-line, between "*" and their parenthesized version.31 gem_list = out.split("\n").map {|g| g[/\* (.*) \(/, 1] }.compact32 expect(gem_list).to eq(gem_list.sort)33 end34 it "returns non zero exit status if outdated gems present" do35 update_repo2 do36 build_gem "activesupport", "3.0"37 update_git "foo", :path => lib_path("foo")38 end39 bundle "outdated"40 expect(exitstatus).to_not be_zero if exitstatus41 end42 it "returns success exit status if no outdated gems present" do43 bundle "outdated"44 expect(exitstatus).to be_zero if exitstatus45 end46 it "adds gem group to dependency output when repo is updated" do47 install_gemfile <<-G48 source "file://#{gem_repo2}"49 group :development, :test do50 gem 'activesupport', '2.3.5'51 end52 G53 update_repo2 { build_gem "activesupport", "3.0" }54 bundle "outdated --verbose"55 expect(out).to include("activesupport (newest 3.0, installed 2.3.5, requested = 2.3.5) in groups \"development, test\"")56 end57 end58 describe "with --group option" do59 def test_group_option(group = nil, gems_list_size = 1)60 install_gemfile <<-G61 source "file://#{gem_repo2}"62 gem "weakling", "~> 0.0.1"63 gem "terranova", '8'64 group :development, :test do65 gem "duradura", '7.0'66 gem 'activesupport', '2.3.5'67 end68 G69 update_repo2 do70 build_gem "activesupport", "3.0"71 build_gem "terranova", "9"72 build_gem "duradura", "8.0"73 end74 bundle "outdated --group #{group}"75 # Gem names are one per-line, between "*" and their parenthesized version.76 gem_list = out.split("\n").map {|g| g[/\* (.*) \(/, 1] }.compact77 expect(gem_list).to eq(gem_list.sort)78 expect(gem_list.size).to eq gems_list_size79 end80 it "not outdated gems" do81 install_gemfile <<-G82 source "file://#{gem_repo2}"83 gem "weakling", "~> 0.0.1"84 gem "terranova", '8'85 group :development, :test do86 gem 'activesupport', '2.3.5'87 gem "duradura", '7.0'88 end89 G90 bundle "outdated --group"91 expect(out).to include("Bundle up to date!")92 end93 it "returns a sorted list of outdated gems from one group => 'default'" do94 test_group_option("default")95 expect(out).to include("===== Group default =====")96 expect(out).to include("terranova (")97 expect(out).not_to include("===== Group development, test =====")98 expect(out).not_to include("activesupport")99 expect(out).not_to include("duradura")100 end101 it "returns a sorted list of outdated gems from one group => 'development'" do102 test_group_option("development", 2)103 expect(out).not_to include("===== Group default =====")104 expect(out).not_to include("terranova (")105 expect(out).to include("===== Group development, test =====")106 expect(out).to include("activesupport")107 expect(out).to include("duradura")108 end109 end110 describe "with --groups option" do111 it "not outdated gems" do112 install_gemfile <<-G113 source "file://#{gem_repo2}"114 gem "weakling", "~> 0.0.1"115 gem "terranova", '8'116 group :development, :test do117 gem 'activesupport', '2.3.5'118 gem "duradura", '7.0'119 end120 G121 bundle "outdated --groups"122 expect(out).to include("Bundle up to date!")123 end124 it "returns a sorted list of outdated gems by groups" do125 install_gemfile <<-G126 source "file://#{gem_repo2}"127 gem "weakling", "~> 0.0.1"128 gem "terranova", '8'129 group :development, :test do130 gem 'activesupport', '2.3.5'131 gem "duradura", '7.0'132 end133 G134 update_repo2 do135 build_gem "activesupport", "3.0"136 build_gem "terranova", "9"137 build_gem "duradura", "8.0"138 end139 bundle "outdated --groups"140 expect(out).to include("===== Group default =====")141 expect(out).to include("terranova (newest 9, installed 8, requested = 8)")142 expect(out).to include("===== Group development, test =====")143 expect(out).to include("activesupport (newest 3.0, installed 2.3.5, requested = 2.3.5)")144 expect(out).to include("duradura (newest 8.0, installed 7.0, requested = 7.0)")145 expect(out).not_to include("weakling (")146 # TODO: check gems order inside the group147 end148 end149 describe "with --local option" do150 it "uses local cache to return a list of outdated gems" do151 update_repo2 do152 build_gem "activesupport", "2.3.4"153 end154 bundle! "config clean false"155 install_gemfile <<-G156 source "file://#{gem_repo2}"157 gem "activesupport", "2.3.4"158 G159 bundle "outdated --local"160 expect(out).to include("activesupport (newest 2.3.5, installed 2.3.4, requested = 2.3.4)")161 end162 it "doesn't hit repo2" do163 FileUtils.rm_rf(gem_repo2)164 bundle "outdated --local"165 expect(out).not_to match(/Fetching (gem|version|dependency) metadata from/)166 end167 end168 shared_examples_for "a minimal output is desired" do169 context "and gems are outdated" do170 before do171 update_repo2 do172 build_gem "activesupport", "3.0"173 build_gem "weakling", "0.2"174 end175 end176 it "outputs a sorted list of outdated gems with a more minimal format" do177 minimal_output = "activesupport (newest 3.0, installed 2.3.5, requested = 2.3.5)\n" \178 "weakling (newest 0.2, installed 0.0.3, requested ~> 0.0.1)"179 subject180 expect(out).to eq(minimal_output)181 end182 end183 context "and no gems are outdated" do184 it "has empty output" do185 subject186 expect(out).to eq("")187 end188 end189 end190 describe "with --parseable option" do191 subject { bundle "outdated --parseable" }192 it_behaves_like "a minimal output is desired"193 end194 describe "with aliased --porcelain option" do195 subject { bundle "outdated --porcelain" }196 it_behaves_like "a minimal output is desired"197 end198 describe "with specified gems" do199 it "returns list of outdated gems" do200 update_repo2 do201 build_gem "activesupport", "3.0"202 update_git "foo", :path => lib_path("foo")203 end204 bundle "outdated foo"205 expect(out).not_to include("activesupport (newest")206 expect(out).to include("foo (newest 1.0")207 end208 end209 describe "pre-release gems" do210 context "without the --pre option" do211 it "ignores pre-release versions" do212 update_repo2 do213 build_gem "activesupport", "3.0.0.beta"214 end215 bundle "outdated"216 expect(out).not_to include("activesupport (3.0.0.beta > 2.3.5)")217 end218 end219 context "with the --pre option" do220 it "includes pre-release versions" do221 update_repo2 do222 build_gem "activesupport", "3.0.0.beta"223 end224 bundle "outdated --pre"225 expect(out).to include("activesupport (newest 3.0.0.beta, installed 2.3.5, requested = 2.3.5)")226 end227 end228 context "when current gem is a pre-release" do229 it "includes the gem" do230 update_repo2 do231 build_gem "activesupport", "3.0.0.beta.1"232 build_gem "activesupport", "3.0.0.beta.2"233 end234 install_gemfile <<-G235 source "file://#{gem_repo2}"236 gem "activesupport", "3.0.0.beta.1"237 G238 bundle "outdated"239 expect(out).to include("(newest 3.0.0.beta.2, installed 3.0.0.beta.1, requested = 3.0.0.beta.1)")240 end241 end242 end243 describe "with --strict option" do244 it "only reports gems that have a newer version that matches the specified dependency version requirements" do245 update_repo2 do246 build_gem "activesupport", "3.0"247 build_gem "weakling", "0.0.5"248 end249 bundle "outdated --strict"250 expect(out).to_not include("activesupport (newest")251 expect(out).to include("(newest 0.0.5, installed 0.0.3, requested ~> 0.0.1)")252 end253 it "only reports gem dependencies when they can actually be updated" do254 install_gemfile <<-G255 source "file://#{gem_repo2}"256 gem "rack_middleware", "1.0"257 G258 bundle "outdated --strict"259 expect(out).to_not include("rack (1.2")260 end261 describe "and filter options" do262 it "only reports gems that match requirement and patch filter level" do263 install_gemfile <<-G264 source "file://#{gem_repo2}"265 gem "activesupport", "~> 2.3"266 gem "weakling", ">= 0.0.1"267 G268 update_repo2 do269 build_gem "activesupport", %w[2.4.0 3.0.0]270 build_gem "weakling", "0.0.5"271 end272 bundle "outdated --strict --filter-patch"273 expect(out).to_not include("activesupport (newest")274 expect(out).to include("(newest 0.0.5, installed 0.0.3")275 end276 it "only reports gems that match requirement and minor filter level" do277 install_gemfile <<-G278 source "file://#{gem_repo2}"279 gem "activesupport", "~> 2.3"280 gem "weakling", ">= 0.0.1"281 G282 update_repo2 do283 build_gem "activesupport", %w[2.3.9]284 build_gem "weakling", "0.1.5"285 end286 bundle "outdated --strict --filter-minor"287 expect(out).to_not include("activesupport (newest")288 expect(out).to include("(newest 0.1.5, installed 0.0.3")289 end290 it "only reports gems that match requirement and major filter level" do291 install_gemfile <<-G292 source "file://#{gem_repo2}"293 gem "activesupport", "~> 2.3"294 gem "weakling", ">= 0.0.1"295 G296 update_repo2 do297 build_gem "activesupport", %w[2.4.0 2.5.0]298 build_gem "weakling", "1.1.5"299 end300 bundle "outdated --strict --filter-major"301 expect(out).to_not include("activesupport (newest")302 expect(out).to include("(newest 1.1.5, installed 0.0.3")303 end304 end305 end306 describe "with invalid gem name" do307 it "returns could not find gem name" do308 bundle "outdated invalid_gem_name"309 expect(out).to include("Could not find gem 'invalid_gem_name'.")310 end311 it "returns non-zero exit code" do312 bundle "outdated invalid_gem_name"313 expect(exitstatus).to_not be_zero if exitstatus314 end315 end316 it "performs an automatic bundle install" do317 gemfile <<-G318 source "file://#{gem_repo1}"319 gem "rack", "0.9.1"320 gem "foo"321 G322 bundle "config auto_install 1"323 bundle :outdated324 expect(out).to include("Installing foo 1.0")325 end326 context "after bundle install --deployment", :bundler => "< 2" do327 before do328 install_gemfile <<-G, forgotten_command_line_options(:deployment => true)329 source "file://#{gem_repo2}"330 gem "rack"331 gem "foo"332 G333 end334 it "outputs a helpful message about being in deployment mode" do335 update_repo2 { build_gem "activesupport", "3.0" }336 bundle "outdated"337 expect(last_command).to be_failure338 expect(out).to include("You are trying to check outdated gems in deployment mode.")339 expect(out).to include("Run `bundle outdated` elsewhere.")340 expect(out).to include("If this is a development machine, remove the ")341 expect(out).to include("Gemfile freeze\nby running `bundle install --no-deployment`.")342 end343 end344 context "after bundle config deployment true" do345 before do346 install_gemfile <<-G347 source "file://#{gem_repo2}"348 gem "rack"349 gem "foo"350 G351 bundle! "config deployment true"352 end353 it "outputs a helpful message about being in deployment mode" do354 update_repo2 { build_gem "activesupport", "3.0" }355 bundle "outdated"356 expect(last_command).to be_failure357 expect(out).to include("You are trying to check outdated gems in deployment mode.")358 expect(out).to include("Run `bundle outdated` elsewhere.")359 expect(out).to include("If this is a development machine, remove the ")360 expect(out).to include("Gemfile freeze\nby running `bundle config --delete deployment`.")361 end362 end363 context "update available for a gem on a different platform" do364 before do365 install_gemfile <<-G366 source "file://#{gem_repo2}"367 gem "laduradura", '= 5.15.2'368 G369 end370 it "reports that no updates are available" do371 bundle "outdated"372 expect(out).to include("Bundle up to date!")373 end374 end375 context "update available for a gem on the same platform while multiple platforms used for gem" do376 it "reports that updates are available if the Ruby platform is used" do377 install_gemfile <<-G378 source "file://#{gem_repo2}"379 gem "laduradura", '= 5.15.2', :platforms => [:ruby, :jruby]380 G381 bundle "outdated"382 expect(out).to include("Bundle up to date!")383 end384 it "reports that updates are available if the JRuby platform is used" do385 simulate_ruby_engine "jruby", "1.6.7" do386 simulate_platform "jruby" do387 install_gemfile <<-G388 source "file://#{gem_repo2}"389 gem "laduradura", '= 5.15.2', :platforms => [:ruby, :jruby]390 G391 bundle "outdated"392 expect(out).to include("Outdated gems included in the bundle:")393 expect(out).to include("laduradura (newest 5.15.3, installed 5.15.2, requested = 5.15.2)")394 end395 end396 end397 end398 shared_examples_for "version update is detected" do399 it "reports that a gem has a newer version" do400 subject401 expect(out).to include("Outdated gems included in the bundle:")402 expect(out).to include("activesupport (newest")403 expect(out).to_not include("ERROR REPORT TEMPLATE")404 end405 end406 shared_examples_for "major version updates are detected" do407 before do408 update_repo2 do409 build_gem "activesupport", "3.3.5"410 build_gem "weakling", "0.8.0"411 end412 end413 it_behaves_like "version update is detected"414 end415 context "when on a new machine" do416 before do417 simulate_new_machine418 update_git "foo", :path => lib_path("foo")419 update_repo2 do420 build_gem "activesupport", "3.3.5"421 build_gem "weakling", "0.8.0"422 end423 end424 subject { bundle "outdated" }425 it_behaves_like "version update is detected"426 end427 shared_examples_for "minor version updates are detected" do428 before do429 update_repo2 do430 build_gem "activesupport", "2.7.5"431 build_gem "weakling", "2.0.1"432 end433 end434 it_behaves_like "version update is detected"435 end436 shared_examples_for "patch version updates are detected" do437 before do438 update_repo2 do439 build_gem "activesupport", "2.3.7"440 build_gem "weakling", "0.3.1"441 end442 end443 it_behaves_like "version update is detected"444 end445 shared_examples_for "no version updates are detected" do446 it "does not detect any version updates" do447 subject448 expect(out).to include("updates to display.")449 expect(out).to_not include("ERROR REPORT TEMPLATE")450 expect(out).to_not include("activesupport (newest")451 expect(out).to_not include("weakling (newest")452 end453 end454 shared_examples_for "major version is ignored" do455 before do456 update_repo2 do457 build_gem "activesupport", "3.3.5"458 build_gem "weakling", "1.0.1"459 end460 end461 it_behaves_like "no version updates are detected"462 end463 shared_examples_for "minor version is ignored" do464 before do465 update_repo2 do466 build_gem "activesupport", "2.4.5"467 build_gem "weakling", "0.3.1"468 end469 end470 it_behaves_like "no version updates are detected"471 end472 shared_examples_for "patch version is ignored" do473 before do474 update_repo2 do475 build_gem "activesupport", "2.3.6"476 build_gem "weakling", "0.0.4"477 end478 end479 it_behaves_like "no version updates are detected"480 end481 describe "with --filter-major option" do482 subject { bundle "outdated --filter-major" }483 it_behaves_like "major version updates are detected"484 it_behaves_like "minor version is ignored"485 it_behaves_like "patch version is ignored"486 end487 describe "with --filter-minor option" do488 subject { bundle "outdated --filter-minor" }489 it_behaves_like "minor version updates are detected"490 it_behaves_like "major version is ignored"491 it_behaves_like "patch version is ignored"492 end493 describe "with --filter-patch option" do494 subject { bundle "outdated --filter-patch" }495 it_behaves_like "patch version updates are detected"496 it_behaves_like "major version is ignored"497 it_behaves_like "minor version is ignored"498 end499 describe "with --filter-minor --filter-patch options" do500 subject { bundle "outdated --filter-minor --filter-patch" }501 it_behaves_like "minor version updates are detected"502 it_behaves_like "patch version updates are detected"503 it_behaves_like "major version is ignored"504 end505 describe "with --filter-major --filter-minor options" do506 subject { bundle "outdated --filter-major --filter-minor" }507 it_behaves_like "major version updates are detected"508 it_behaves_like "minor version updates are detected"509 it_behaves_like "patch version is ignored"510 end511 describe "with --filter-major --filter-patch options" do512 subject { bundle "outdated --filter-major --filter-patch" }513 it_behaves_like "major version updates are detected"514 it_behaves_like "patch version updates are detected"515 it_behaves_like "minor version is ignored"516 end517 describe "with --filter-major --filter-minor --filter-patch options" do518 subject { bundle "outdated --filter-major --filter-minor --filter-patch" }519 it_behaves_like "major version updates are detected"520 it_behaves_like "minor version updates are detected"521 it_behaves_like "patch version updates are detected"522 end523 context "conservative updates" do524 context "without update-strict" do525 before do526 build_repo4 do527 build_gem "patch", %w[1.0.0 1.0.1]528 build_gem "minor", %w[1.0.0 1.0.1 1.1.0]529 build_gem "major", %w[1.0.0 1.0.1 1.1.0 2.0.0]530 end531 # establish a lockfile set to 1.0.0532 install_gemfile <<-G533 source "file://#{gem_repo4}"534 gem 'patch', '1.0.0'535 gem 'minor', '1.0.0'536 gem 'major', '1.0.0'537 G538 # remove 1.4.3 requirement and bar altogether539 # to setup update specs below540 gemfile <<-G541 source "file://#{gem_repo4}"542 gem 'patch'543 gem 'minor'544 gem 'major'545 G546 end547 it "shows nothing when patching and filtering to minor" do548 bundle "outdated --patch --filter-minor"549 expect(out).to include("No minor updates to display.")550 expect(out).not_to include("patch (newest")551 expect(out).not_to include("minor (newest")552 expect(out).not_to include("major (newest")553 end554 it "shows all gems when patching and filtering to patch" do555 bundle "outdated --patch --filter-patch"556 expect(out).to include("patch (newest 1.0.1")557 expect(out).to include("minor (newest 1.0.1")558 expect(out).to include("major (newest 1.0.1")559 end560 it "shows minor and major when updating to minor and filtering to patch and minor" do561 bundle "outdated --minor --filter-minor"562 expect(out).not_to include("patch (newest")563 expect(out).to include("minor (newest 1.1.0")564 expect(out).to include("major (newest 1.1.0")565 end566 it "shows minor when updating to major and filtering to minor with parseable" do567 bundle "outdated --major --filter-minor --parseable"568 expect(out).not_to include("patch (newest")569 expect(out).to include("minor (newest")570 expect(out).not_to include("major (newest")571 end572 end573 context "with update-strict" do574 before do575 build_repo4 do576 build_gem "foo", %w[1.4.3 1.4.4] do |s|577 s.add_dependency "bar", "~> 2.0"578 end579 build_gem "foo", %w[1.4.5 1.5.0] do |s|580 s.add_dependency "bar", "~> 2.1"581 end582 build_gem "foo", %w[1.5.1] do |s|583 s.add_dependency "bar", "~> 3.0"584 end585 build_gem "bar", %w[2.0.3 2.0.4 2.0.5 2.1.0 2.1.1 3.0.0]586 build_gem "qux", %w[1.0.0 1.1.0 2.0.0]587 end588 # establish a lockfile set to 1.4.3589 install_gemfile <<-G590 source "file://#{gem_repo4}"591 gem 'foo', '1.4.3'592 gem 'bar', '2.0.3'593 gem 'qux', '1.0.0'594 G595 # remove 1.4.3 requirement and bar altogether596 # to setup update specs below597 gemfile <<-G598 source "file://#{gem_repo4}"599 gem 'foo'600 gem 'qux'601 G602 end603 it "shows gems with update-strict updating to patch and filtering to patch" do604 bundle "outdated --patch --update-strict --filter-patch"605 expect(out).to include("foo (newest 1.4.4")606 expect(out).to include("bar (newest 2.0.5")607 expect(out).not_to include("qux (newest")608 end609 end610 end611 describe "with --only-explicit" do612 it "does not report outdated dependent gems" do613 build_repo4 do614 build_gem "weakling", %w[0.2 0.3] do |s|615 s.add_dependency "bar", "~> 2.1"616 end617 build_gem "bar", %w[2.1 2.2]618 end619 install_gemfile <<-G620 source "file://#{gem_repo4}"621 gem 'weakling', '0.2'622 gem 'bar', '2.1'623 G624 gemfile <<-G625 source "file://#{gem_repo4}"626 gem 'weakling'627 G628 bundle "outdated --only-explicit"629 expect(out).to include("weakling (newest 0.3")630 expect(out).not_to include("bar (newest 2.2")631 end632 end633end...

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful