From 1a3b36ea5b73ec1a35c533d5913859524875b08e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 28 Feb 2019 13:47:17 +0100 Subject: [PATCH 1/3] Little refactor Get `have_lockfile` helper method actually used. --- spec/support/matchers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index 0a9285837a7..f9efe32a38a 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -194,7 +194,7 @@ def indent(string, padding = 4, indent_character = " ") RSpec::Matchers.alias_matcher :include_gem, :include_gems def have_lockfile(expected) - read_as(strip_whitespace(expected)) + read_as(normalize_uri_file(strip_whitespace(expected))) end def plugin_should_be_installed(*names) @@ -212,7 +212,7 @@ def plugin_should_not_be_installed(*names) end def lockfile_should_be(expected) - expect(bundled_app("Gemfile.lock")).to read_as(normalize_uri_file(strip_whitespace(expected))) + expect(bundled_app("Gemfile.lock")).to have_lockfile(expected) end def gemfile_should_be(expected) From bd5e0cf17c8119397cbd1cf9745c62c3352e9caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 28 Feb 2019 13:47:51 +0100 Subject: [PATCH 2/3] Clarify lockfile and gemfile helpers --- spec/support/helpers.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 151c99c3ff9..72a94ea326f 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -268,18 +268,22 @@ def create_file(*args) end def gemfile(*args) - if args.empty? + contents = args.shift + + if contents.nil? File.open("Gemfile", "r", &:read) else - create_file("Gemfile", *args) + create_file("Gemfile", contents, *args) end end def lockfile(*args) - if args.empty? + contents = args.shift + + if contents.nil? File.open("Gemfile.lock", "r", &:read) else - create_file("Gemfile.lock", *args) + create_file("Gemfile.lock", contents, *args) end end From 5f7f860dc5ba5cfeecc8c35e4616cd55e205b431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 1 Apr 2019 17:23:42 +0200 Subject: [PATCH 3/3] Fix spec about lockfile writing This change is simple but not easy to explain. What this test does is to ensure that if bundle install doesn't change anything, then the bundler version in the lockfile does not get rewritten. Whereas this test was passing, the implementation was wrong, but two bugs were "compesating for each other" and making it pass. The explanation is the following: Due to a regression in rubygems, in rubygems 3+ "2.0.0.0.a" is considered higher than "2.0.0.dev". This changes the test because bundler will never dowgrade the bundler version in a lockfile, so even if the lockfile gets rewritten, it will still keep "2.0.0.0.a", since it's considered higher. However, if we change the test to use "2.0.0.a" instead of "2.0.0.dev", then the test starts failing and shows the bug in the test. The bug is that the lock file in the test is written with "file://localhost" style URLs. However, the lockfile that would be generated would contain "file://" style URLs. This would trick bundler into thinking that something has been changed by `bundle install`, so it will rewrite the lock file, use "2.0.0.dev" as the locked bundler version, and cause the test to fail. --- spec/lock/lockfile_spec.rb | 2 +- spec/support/helpers.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/lock/lockfile_spec.rb b/spec/lock/lockfile_spec.rb index 0809258859e..e9c366009a2 100644 --- a/spec/lock/lockfile_spec.rb +++ b/spec/lock/lockfile_spec.rb @@ -76,7 +76,7 @@ end it "does not update the lockfile's bundler version if nothing changed during bundle install" do - version = "#{Bundler::VERSION.split(".").first}.0.0.0.a" + version = "#{Bundler::VERSION.split(".").first}.0.0.a" lockfile <<-L GEM diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 72a94ea326f..896d60435ed 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -283,7 +283,7 @@ def lockfile(*args) if contents.nil? File.open("Gemfile.lock", "r", &:read) else - create_file("Gemfile.lock", contents, *args) + create_file("Gemfile.lock", normalize_uri_file(contents), *args) end end