Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
exterm authored Mar 19, 2024
1 parent f5fdbd3 commit 24e6991
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/unit/packwerk/references_from_file_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# typed: true
# frozen_string_literal: true

require "test_helper"

module Packwerk
class ReferencesFromFileTest < Minitest::Test
setup do
config = Configuration.new
config.stubs(:load_paths).returns({})
@run_context = RunContext.from_configuration(config)
RunContext.stubs(:from_configuration).with(config).returns(@run_context)
@referencer = ReferencesFromFile.new(config)
end

test "raises on parser error" do
offense = Offense.new(file: "something.rb", message: "yo")
@run_context.stubs(:references_from_file).returns(
RunContext::FileReferencesResult.new(file_offenses: [offense], references: [])
)

assert_raises ReferencesFromFile::FileParserError do
@referencer.list("lib/something.rb")
end
end

test "fetches violations for all files from run context" do
references = {
"lib/something.rb" => [
Reference.new
],
"components/ice_cream_sales/app/models/scoop.rb" => [
Reference.new
]
}
@referencer.stubs(:files).returns(references.keys)

references.each do |file, references|
@run_context.stubs(:references_from_file).with(relative_file: file).returns(
RunContext::FileReferencesResult.new(file_offenses: [], references: references)
)
end

assert_equal Set.new(references.values.flatten), Set.new(@referencer.list_all)
end
end
end

0 comments on commit 24e6991

Please sign in to comment.