Skip to content

Commit

Permalink
Merge pull request #2090 from Shopify/andyw8/add-test-for-lockfile-di…
Browse files Browse the repository at this point in the history
…ff-parser

Add test for lockfile diff parser
  • Loading branch information
andyw8 authored Nov 25, 2024
2 parents 01306e6 + 4b2eb3a commit 7f173a8
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions spec/tapioca/lockfile_diff_parser_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# typed: strict
# frozen_string_literal: true

require "spec_helper"
require "ruby_lsp/tapioca/lockfile_diff_parser"

module RubyLsp
module Tapioca
class LockFileDiffParserSpec < Minitest::Spec
describe "#parse_added_or_modified_gems" do
it "parses added or modified gems from git diff" do
diff_output = <<~DIFF
+ new_gem (1.0.0)
+ updated_gem (2.0.0)
- removed_gem (1.0.0)
DIFF

lockfile_parser = RubyLsp::Tapioca::LockfileDiffParser.new(diff_output)
assert_equal ["new_gem", "updated_gem"], lockfile_parser.added_or_modified_gems
end

it "is empty when there is no diff" do
diff_output = ""

lockfile_parser = RubyLsp::Tapioca::LockfileDiffParser.new(diff_output)
assert_empty lockfile_parser.added_or_modified_gems
end
end

describe "#parse_removed_gems" do
it "parses removed gems from git diff" do
diff_output = <<~DIFF
+ new_gem (1.0.0)
- removed_gem (1.0.0)
- outdated_gem (2.3.4)
DIFF

lockfile_parser = RubyLsp::Tapioca::LockfileDiffParser.new(diff_output)
assert_equal ["removed_gem", "outdated_gem"], lockfile_parser.removed_gems
end
end

it "handles gem names with awkward names" do
diff_output = <<~DIFF
- my-gem_extra2 (1.0.0.beta1)
DIFF

lockfile_parser = RubyLsp::Tapioca::LockfileDiffParser.new(diff_output)
assert_equal ["my-gem_extra2"], lockfile_parser.removed_gems
end
end
end
end

0 comments on commit 7f173a8

Please sign in to comment.