From 0379495857310c091e53db869e720901997ed1fe Mon Sep 17 00:00:00 2001
From: Sergei Zharinov <zharinov@users.noreply.github.com>
Date: Sat, 14 Aug 2021 10:09:26 +0300
Subject: [PATCH] refactor(bundler): Better snapshot tests (#11263)

---
 lib/manager/azure-pipelines/extract.spec.ts   |   1 -
 .../__snapshots__/artifacts.spec.ts.snap      | 103 +-----------------
 lib/manager/bundler/artifacts.spec.ts         |  46 ++++----
 lib/manager/bundler/gemfile.spec.ts           |   5 +-
 lib/manager/bundler/locked-version.spec.ts    |  10 +-
 5 files changed, 33 insertions(+), 132 deletions(-)

diff --git a/lib/manager/azure-pipelines/extract.spec.ts b/lib/manager/azure-pipelines/extract.spec.ts
index e1ef95b9fe..cf96d37f0c 100644
--- a/lib/manager/azure-pipelines/extract.spec.ts
+++ b/lib/manager/azure-pipelines/extract.spec.ts
@@ -72,7 +72,6 @@ describe(getName(), () => {
 
   describe('extractContainer()', () => {
     it('should extract container information', () => {
-      // FIXME: explicit assert condition
       expect(
         extractContainer({
           image: 'ubuntu:16.04',
diff --git a/lib/manager/bundler/__snapshots__/artifacts.spec.ts.snap b/lib/manager/bundler/__snapshots__/artifacts.spec.ts.snap
index 391f66766b..03d956dd1f 100644
--- a/lib/manager/bundler/__snapshots__/artifacts.spec.ts.snap
+++ b/lib/manager/bundler/__snapshots__/artifacts.spec.ts.snap
@@ -1,17 +1,6 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
 exports[`bundler.updateArtifacts() Docker .ruby-version 1`] = `
-Array [
-  Object {
-    "file": Object {
-      "contents": "Updated Gemfile.lock",
-      "name": "Gemfile.lock",
-    },
-  },
-]
-`;
-
-exports[`bundler.updateArtifacts() Docker .ruby-version 2`] = `
 Array [
   Object {
     "cmd": "docker pull renovate/ruby:1.2.0",
@@ -48,17 +37,6 @@ Array [
 `;
 
 exports[`bundler.updateArtifacts() Docker constraints options 1`] = `
-Array [
-  Object {
-    "file": Object {
-      "contents": "Updated Gemfile.lock",
-      "name": "Gemfile.lock",
-    },
-  },
-]
-`;
-
-exports[`bundler.updateArtifacts() Docker constraints options 2`] = `
 Array [
   Object {
     "cmd": "docker pull renovate/ruby:latest",
@@ -95,17 +73,6 @@ Array [
 `;
 
 exports[`bundler.updateArtifacts() Docker injects bundler host configuration as command with bundler < 2 1`] = `
-Array [
-  Object {
-    "file": Object {
-      "contents": "Updated Gemfile.lock",
-      "name": "Gemfile.lock",
-    },
-  },
-]
-`;
-
-exports[`bundler.updateArtifacts() Docker injects bundler host configuration as command with bundler < 2 2`] = `
 Array [
   Object {
     "cmd": "docker pull renovate/ruby:1.2.0",
@@ -142,17 +109,6 @@ Array [
 `;
 
 exports[`bundler.updateArtifacts() Docker injects bundler host configuration as command with bundler == latest 1`] = `
-Array [
-  Object {
-    "file": Object {
-      "contents": "Updated Gemfile.lock",
-      "name": "Gemfile.lock",
-    },
-  },
-]
-`;
-
-exports[`bundler.updateArtifacts() Docker injects bundler host configuration as command with bundler == latest 2`] = `
 Array [
   Object {
     "cmd": "docker pull renovate/ruby:1.2.0",
@@ -189,17 +145,6 @@ Array [
 `;
 
 exports[`bundler.updateArtifacts() Docker injects bundler host configuration as command with bundler >= 2 1`] = `
-Array [
-  Object {
-    "file": Object {
-      "contents": "Updated Gemfile.lock",
-      "name": "Gemfile.lock",
-    },
-  },
-]
-`;
-
-exports[`bundler.updateArtifacts() Docker injects bundler host configuration as command with bundler >= 2 2`] = `
 Array [
   Object {
     "cmd": "docker pull renovate/ruby:1.2.0",
@@ -236,17 +181,6 @@ Array [
 `;
 
 exports[`bundler.updateArtifacts() Docker injects bundler host configuration environment variables 1`] = `
-Array [
-  Object {
-    "file": Object {
-      "contents": "Updated Gemfile.lock",
-      "name": "Gemfile.lock",
-    },
-  },
-]
-`;
-
-exports[`bundler.updateArtifacts() Docker injects bundler host configuration environment variables 2`] = `
 Array [
   Object {
     "cmd": "docker pull renovate/ruby:1.2.0",
@@ -284,17 +218,6 @@ Array [
 `;
 
 exports[`bundler.updateArtifacts() Docker invalid constraints options 1`] = `
-Array [
-  Object {
-    "file": Object {
-      "contents": "Updated Gemfile.lock",
-      "name": "Gemfile.lock",
-    },
-  },
-]
-`;
-
-exports[`bundler.updateArtifacts() Docker invalid constraints options 2`] = `
 Array [
   Object {
     "cmd": "docker pull renovate/ruby:latest",
@@ -390,9 +313,7 @@ Array [
 ]
 `;
 
-exports[`bundler.updateArtifacts() returns null if Gemfile.lock was not changed 1`] = `null`;
-
-exports[`bundler.updateArtifacts() returns null if Gemfile.lock was not changed 2`] = `
+exports[`bundler.updateArtifacts() returns null if Gemfile.lock was not changed 1`] = `
 Array [
   Object {
     "cmd": "bundle lock --update foo bar",
@@ -417,17 +338,6 @@ Array [
 `;
 
 exports[`bundler.updateArtifacts() works explicit global binarySource 1`] = `
-Array [
-  Object {
-    "file": Object {
-      "contents": "Updated Gemfile.lock",
-      "name": "Gemfile.lock",
-    },
-  },
-]
-`;
-
-exports[`bundler.updateArtifacts() works explicit global binarySource 2`] = `
 Array [
   Object {
     "cmd": "bundle lock --update foo bar",
@@ -452,17 +362,6 @@ Array [
 `;
 
 exports[`bundler.updateArtifacts() works for default binarySource 1`] = `
-Array [
-  Object {
-    "file": Object {
-      "contents": "Updated Gemfile.lock",
-      "name": "Gemfile.lock",
-    },
-  },
-]
-`;
-
-exports[`bundler.updateArtifacts() works for default binarySource 2`] = `
 Array [
   Object {
     "cmd": "bundle lock --update foo bar",
diff --git a/lib/manager/bundler/artifacts.spec.ts b/lib/manager/bundler/artifacts.spec.ts
index 6e78726d50..63ad89c2ea 100644
--- a/lib/manager/bundler/artifacts.spec.ts
+++ b/lib/manager/bundler/artifacts.spec.ts
@@ -34,6 +34,13 @@ const adminConfig: RepoAdminConfig = {
 
 const config: UpdateArtifactsConfig = {};
 
+const updatedGemfileLock = {
+  file: {
+    contents: 'Updated Gemfile.lock',
+    name: 'Gemfile.lock',
+  },
+};
+
 describe('bundler.updateArtifacts()', () => {
   beforeEach(() => {
     jest.resetAllMocks();
@@ -72,7 +79,6 @@ describe('bundler.updateArtifacts()', () => {
       modified: [],
     } as StatusResult);
     fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
-    // FIXME: explicit assert condition
     expect(
       await updateArtifacts({
         packageFileName: 'Gemfile',
@@ -80,7 +86,7 @@ describe('bundler.updateArtifacts()', () => {
         newPackageFileContent: 'Updated Gemfile content',
         config,
       })
-    ).toMatchSnapshot();
+    ).toBeNull();
     expect(execSnapshots).toMatchSnapshot();
   });
   it('works for default binarySource', async () => {
@@ -92,7 +98,6 @@ describe('bundler.updateArtifacts()', () => {
       modified: ['Gemfile.lock'],
     } as StatusResult);
     fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
-    // FIXME: explicit assert condition
     expect(
       await updateArtifacts({
         packageFileName: 'Gemfile',
@@ -100,7 +105,7 @@ describe('bundler.updateArtifacts()', () => {
         newPackageFileContent: 'Updated Gemfile content',
         config,
       })
-    ).toMatchSnapshot();
+    ).toEqual([updatedGemfileLock]);
     expect(execSnapshots).toMatchSnapshot();
   });
   it('works explicit global binarySource', async () => {
@@ -113,7 +118,6 @@ describe('bundler.updateArtifacts()', () => {
       modified: ['Gemfile.lock'],
     } as StatusResult);
     fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
-    // FIXME: explicit assert condition
     expect(
       await updateArtifacts({
         packageFileName: 'Gemfile',
@@ -121,7 +125,7 @@ describe('bundler.updateArtifacts()', () => {
         newPackageFileContent: 'Updated Gemfile content',
         config,
       })
-    ).toMatchSnapshot();
+    ).toEqual([updatedGemfileLock]);
     expect(execSnapshots).toMatchSnapshot();
   });
   describe('Docker', () => {
@@ -147,7 +151,6 @@ describe('bundler.updateArtifacts()', () => {
         modified: ['Gemfile.lock'],
       } as StatusResult);
       fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
-      // FIXME: explicit assert condition
       expect(
         await updateArtifacts({
           packageFileName: 'Gemfile',
@@ -155,7 +158,7 @@ describe('bundler.updateArtifacts()', () => {
           newPackageFileContent: 'Updated Gemfile content',
           config,
         })
-      ).toMatchSnapshot();
+      ).toEqual([updatedGemfileLock]);
       expect(execSnapshots).toMatchSnapshot();
     });
     it('constraints options', async () => {
@@ -174,7 +177,6 @@ describe('bundler.updateArtifacts()', () => {
         modified: ['Gemfile.lock'],
       } as StatusResult);
       fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
-      // FIXME: explicit assert condition
       expect(
         await updateArtifacts({
           packageFileName: 'Gemfile',
@@ -188,7 +190,7 @@ describe('bundler.updateArtifacts()', () => {
             },
           },
         })
-      ).toMatchSnapshot();
+      ).toEqual([updatedGemfileLock]);
       expect(execSnapshots).toMatchSnapshot();
     });
     it('invalid constraints options', async () => {
@@ -207,7 +209,6 @@ describe('bundler.updateArtifacts()', () => {
         modified: ['Gemfile.lock'],
       } as StatusResult);
       fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
-      // FIXME: explicit assert condition
       expect(
         await updateArtifacts({
           packageFileName: 'Gemfile',
@@ -221,7 +222,7 @@ describe('bundler.updateArtifacts()', () => {
             },
           },
         })
-      ).toMatchSnapshot();
+      ).toEqual([updatedGemfileLock]);
       expect(execSnapshots).toMatchSnapshot();
     });
 
@@ -254,7 +255,6 @@ describe('bundler.updateArtifacts()', () => {
         modified: ['Gemfile.lock'],
       } as StatusResult);
       fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
-      // FIXME: explicit assert condition
       expect(
         await updateArtifacts({
           packageFileName: 'Gemfile',
@@ -262,7 +262,7 @@ describe('bundler.updateArtifacts()', () => {
           newPackageFileContent: 'Updated Gemfile content',
           config,
         })
-      ).toMatchSnapshot();
+      ).toEqual([updatedGemfileLock]);
       expect(execSnapshots).toMatchSnapshot();
     });
 
@@ -295,7 +295,6 @@ describe('bundler.updateArtifacts()', () => {
         modified: ['Gemfile.lock'],
       } as StatusResult);
       fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
-      // FIXME: explicit assert condition
       expect(
         await updateArtifacts({
           packageFileName: 'Gemfile',
@@ -308,7 +307,7 @@ describe('bundler.updateArtifacts()', () => {
             },
           },
         })
-      ).toMatchSnapshot();
+      ).toEqual([updatedGemfileLock]);
       expect(execSnapshots).toMatchSnapshot();
     });
 
@@ -341,7 +340,6 @@ describe('bundler.updateArtifacts()', () => {
         modified: ['Gemfile.lock'],
       } as StatusResult);
       fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
-      // FIXME: explicit assert condition
       expect(
         await updateArtifacts({
           packageFileName: 'Gemfile',
@@ -354,7 +352,7 @@ describe('bundler.updateArtifacts()', () => {
             },
           },
         })
-      ).toMatchSnapshot();
+      ).toEqual([updatedGemfileLock]);
       expect(execSnapshots).toMatchSnapshot();
     });
 
@@ -387,7 +385,6 @@ describe('bundler.updateArtifacts()', () => {
         modified: ['Gemfile.lock'],
       } as StatusResult);
       fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
-      // FIXME: explicit assert condition
       expect(
         await updateArtifacts({
           packageFileName: 'Gemfile',
@@ -395,7 +392,7 @@ describe('bundler.updateArtifacts()', () => {
           newPackageFileContent: 'Updated Gemfile content',
           config,
         })
-      ).toMatchSnapshot();
+      ).toEqual([updatedGemfileLock]);
       expect(execSnapshots).toMatchSnapshot();
     });
   });
@@ -410,7 +407,6 @@ describe('bundler.updateArtifacts()', () => {
     git.getRepoStatus.mockResolvedValueOnce({
       modified: ['Gemfile.lock'],
     } as StatusResult);
-    // FIXME: explicit assert condition
     expect(
       await updateArtifacts({
         packageFileName: 'Gemfile',
@@ -421,7 +417,13 @@ describe('bundler.updateArtifacts()', () => {
           isLockFileMaintenance: true,
         },
       })
-    ).toMatchSnapshot();
+    ).toMatchSnapshot([
+      {
+        artifactError: {
+          lockFile: 'Gemfile.lock',
+        },
+      },
+    ]);
     expect(execSnapshots).toMatchSnapshot();
   });
   it('performs lockFileMaintenance', async () => {
diff --git a/lib/manager/bundler/gemfile.spec.ts b/lib/manager/bundler/gemfile.spec.ts
index ba3b0e8641..74485bd4f7 100644
--- a/lib/manager/bundler/gemfile.spec.ts
+++ b/lib/manager/bundler/gemfile.spec.ts
@@ -5,7 +5,8 @@ const gemLockFile = loadFixture('Gemfile.rails.lock');
 
 describe('extract lib/manager/bundler/gemfile.rails.lock', () => {
   it('matches the expected output', () => {
-    // FIXME: explicit assert condition
-    expect(extractLockFileEntries(gemLockFile)).toMatchSnapshot();
+    const res = extractLockFileEntries(gemLockFile);
+    expect(res.size).toEqual(185);
+    expect(res).toMatchSnapshot();
   });
 });
diff --git a/lib/manager/bundler/locked-version.spec.ts b/lib/manager/bundler/locked-version.spec.ts
index bdaa82ec43..d2fee8a097 100644
--- a/lib/manager/bundler/locked-version.spec.ts
+++ b/lib/manager/bundler/locked-version.spec.ts
@@ -10,27 +10,27 @@ const gitlabFossGemfileLock = loadFixture('Gemfile.gitlab-foss.lock');
 describe('/lib/manager/bundler/locked-version', () => {
   test('Parse Rails Gem Lock File', () => {
     const parsedLockEntries = extractLockFileEntries(railsGemfileLock);
-    // FIXME: explicit assert condition
+    expect(parsedLockEntries.size).toEqual(185);
     expect(parsedLockEntries).toMatchSnapshot();
   });
   test('Parse WebPacker Gem Lock File', () => {
     const parsedLockEntries = extractLockFileEntries(webPackerGemfileLock);
-    // FIXME: explicit assert condition
+    expect(parsedLockEntries.size).toEqual(53);
     expect(parsedLockEntries).toMatchSnapshot();
   });
   test('Parse Mastodon Gem Lock File', () => {
     const parsedLockEntries = extractLockFileEntries(mastodonGemfileLock);
-    // FIXME: explicit assert condition
+    expect(parsedLockEntries.size).toEqual(266);
     expect(parsedLockEntries).toMatchSnapshot();
   });
   test('Parse Ruby CI Gem Lock File', () => {
     const parsedLockEntries = extractLockFileEntries(rubyCIGemfileLock);
-    // FIXME: explicit assert condition
+    expect(parsedLockEntries.size).toEqual(64);
     expect(parsedLockEntries).toMatchSnapshot();
   });
   test('Parse Gitlab Foss Gem Lock File', () => {
     const parsedLockEntries = extractLockFileEntries(gitlabFossGemfileLock);
-    // FIXME: explicit assert condition
+    expect(parsedLockEntries.size).toEqual(478);
     expect(parsedLockEntries).toMatchSnapshot();
   });
 });
-- 
GitLab