Skip to content

Commit

Permalink
Add test for lockfile diff parser
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 authored and alexcrocha committed Nov 26, 2024
1 parent 4fd346c commit 5f3dc43
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 5f3dc43

Please sign in to comment.