Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
Ensure directory is a git root
Browse files Browse the repository at this point in the history
  • Loading branch information
floriandejonckheere committed Mar 31, 2024
1 parent 2ceefaf commit 1b109af
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/mosaik/commands/extract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ def call
# Extract structural coupling information and add to graph
Extractors::Structural
.new(options, graph)
.tap(&:validate)
.call

# Extract evolutionary (logical and contributor) coupling information and add to graph
Extractors::Evolution
.new(options, graph)
.tap(&:validate)
.call
end

Expand Down
2 changes: 2 additions & 0 deletions lib/mosaik/extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def initialize(options, graph)
@graph = graph
end

def validate; end

def call
raise NotImplementedError
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mosaik/extractors/evolution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module Extractors
# Evolutionary (logical and contributor) coupling extraction
#
class Evolution < Extractor
def validate
raise OptionError, "directory is not a git repository" unless File.directory?(File.join(options[:directory], ".git"))
end

def call
return unless options[:logical].positive? || options[:contributor].positive?

Expand Down
24 changes: 24 additions & 0 deletions spec/mosaik/extractors/evolution_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

RSpec.describe MOSAIK::Extractors::Evolution do
subject(:extractor) { described_class.new(options, graph) }

let(:options) { { directory: MOSAIK.root, logical: 1, contributor: 1 } }
let(:graph) { build(:graph) }

let(:configuration) { build(:configuration) }

describe "#validate" do
it "does not raise an error" do
expect { extractor.validate }.not_to raise_error
end

context "when the directory is not a git repository root" do
let(:options) { { directory: "/tmp" } }

it "raises an error" do
expect { extractor.validate }.to raise_error MOSAIK::OptionError, "directory is not a git repository"
end
end
end
end

0 comments on commit 1b109af

Please sign in to comment.