diff --git a/.rspec b/.rspec index 1b9d7f3..83e16f8 100644 --- a/.rspec +++ b/.rspec @@ -1,3 +1,2 @@ --color --require spec_helper ---tag ~repository diff --git a/README.md b/README.md index 1303e78..c8becf8 100644 --- a/README.md +++ b/README.md @@ -68,15 +68,6 @@ The `evaluate` command analyzes the given microservices architecture, and evalua ```bash $ mosaik evaluate --help ``` -## Development and Testing - -Some test make use of a simulated git repository. If you want to use this repository for development, run the following command: - -```bash -$ rspec spec/mosaik/repository_spec.rb --tag repository -``` - -The simulated git repository will be copied to `tmp/repository` and can be used for development. ## Releasing diff --git a/spec/mosaik/extractors/evolution_spec.rb b/spec/mosaik/extractors/evolution_spec.rb index 8e599ca..95b6478 100644 --- a/spec/mosaik/extractors/evolution_spec.rb +++ b/spec/mosaik/extractors/evolution_spec.rb @@ -29,9 +29,7 @@ end describe "logical coupling" do - let(:options) { { directory:, limit: 100, logical: 1, contributor: 0 } } - - include_context "with a git repository" + let(:options) { { directory: "tmp/repository", limit: 100, logical: 1, contributor: 0 } } it "constructs a logical coupling graph" do extractor.call @@ -48,9 +46,7 @@ end describe "contributor coupling" do - let(:options) { { directory:, limit: 100, logical: 0, contributor: 1 } } - - include_context "with a git repository" + let(:options) { { directory: "tmp/repository", limit: 100, logical: 0, contributor: 1 } } it "constructs a contributor coupling graph" do extractor.call diff --git a/spec/mosaik/extractors/structural_spec.rb b/spec/mosaik/extractors/structural_spec.rb index d7245e0..9812fc4 100644 --- a/spec/mosaik/extractors/structural_spec.rb +++ b/spec/mosaik/extractors/structural_spec.rb @@ -23,8 +23,6 @@ describe "structural coupling" do let(:options) { { structural: 1 } } - include_context "with a git repository" - it "constructs a logical coupling graph" do extractor.call diff --git a/spec/mosaik/repository_spec.rb b/spec/mosaik/repository_spec.rb deleted file mode 100644 index 30f2925..0000000 --- a/spec/mosaik/repository_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe "Repository", :repository do - include_context "with a git repository" - - it "copies the simulated git repository" do - FileUtils.mkdir_p MOSAIK.root.join("tmp/repository") - - expect { FileUtils.cp_r File.join(directory, "."), MOSAIK.root.join("tmp/repository") }.not_to raise_error - end -end diff --git a/spec/support/setup_repository.rb b/spec/support/setup_repository.rb new file mode 100644 index 0000000..0b60b33 --- /dev/null +++ b/spec/support/setup_repository.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +# Relative path to the repository +DIRECTORY = "tmp/repository" + +# Committers +john = "John Doe " +jane = "Jane Doe " +joey = "Joey Doe " + +# Cleanup the temporary repository directory +FileUtils.remove_entry(DIRECTORY) + +# Initialize the repository +GIT = Git.init(DIRECTORY) + +# Set up committer configuration +GIT.config("user.name", "John Doe") +GIT.config("user.email", "john@example.com") + +def commit(author, **files_with_content) + # Write the files with content + files_with_content.each do |file, content| + FileUtils.mkdir_p(File.join(DIRECTORY, File.dirname(file))) + File.write(File.join(DIRECTORY, file), content) + end + + # Add and commit the files + GIT.add + GIT.commit("Add #{files_with_content.keys.join(', ')}", author:) +end + +# Setup the repository with initial commit +commit john, + "README.md" => "# Test Repository" + +# Add MOSAIK configuration +commit john, + "mosaik.yml" => File.read(MOSAIK.root.join("config/mosaik.yml")) + +# Add application structure +commit john, + "lib/app.rb" => "class App; end" + +# Add classes +commit john, + "lib/app/foo.rb" => "class App::Foo; end", + "lib/app/bar.rb" => "class App::Bar; end" + +commit jane, + "lib/app/foo.rb" => "class App::Foo; def initialize; end; end", + "lib/app/bat.rb" => "class App::Bat; end" + +commit john, + "lib/app/foo.rb" => "class App::Foo; end", + "lib/app/bak.rb" => "class App::Bak; end" + +commit jane, + "lib/app/bat.rb" => "class App::Bat; def initialize; end; end", + "lib/app/baz.rb" => "class App::Baz; end" + +commit john, + "lib/app/bat.rb" => "class App::Bat; end", + "lib/app/baz.rb" => "class App::Baz; def initialize; end; end" + +commit joey, + "lib/app/bat.rb" => "class App::Bat; def initialize; end; end", + "lib/app/baz.rb" => "class App::Baz; end" + +RSpec.configure do |config| + config.before do + configuration = MOSAIK::Configuration.from(File.join(DIRECTORY, "mosaik.yml")) + + # Mock the configuration + allow(MOSAIK) + .to receive(:configuration) + .and_return configuration + end +end diff --git a/spec/support/shared_contexts/repository.rb b/spec/support/shared_contexts/repository.rb deleted file mode 100644 index 82f197d..0000000 --- a/spec/support/shared_contexts/repository.rb +++ /dev/null @@ -1,77 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_context "with a git repository" do - let(:directory) { Dir.mktmpdir } - let(:git) { Git.init(directory) } - - let(:configuration) { MOSAIK::Configuration.from(File.join(directory, "mosaik.yml")) } - - let(:john) { "John Doe " } - let(:jane) { "Jane Doe " } - let(:joey) { "Joey Doe " } - - def commit(author, **files_with_content) - # Write the files with content - files_with_content.each do |file, content| - FileUtils.mkdir_p(File.join(directory, File.dirname(file))) - File.write(File.join(directory, file), content) - end - - # Add and commit the files - git.add - git.commit("Add #{files_with_content.keys.join(', ')}", author:) - end - - before do - # Set up committer configuration - git.config("user.name", "Author 1") - git.config("user.email", "john@example.com") - - # Setup the repository with initial commit - commit john, - "README.md" => "# Test Repository" - - # Add MOSAIK configuration - commit john, - "mosaik.yml" => File.read(MOSAIK.root.join("config/mosaik.yml")) - - # Add application structure - commit john, - "lib/app.rb" => "class App; end" - - # Add classes - commit john, - "lib/app/foo.rb" => "class App::Foo; end", - "lib/app/bar.rb" => "class App::Bar; end" - - commit jane, - "lib/app/foo.rb" => "class App::Foo; def initialize; end; end", - "lib/app/bat.rb" => "class App::Bat; end" - - commit john, - "lib/app/foo.rb" => "class App::Foo; end", - "lib/app/bak.rb" => "class App::Bak; end" - - commit jane, - "lib/app/bat.rb" => "class App::Bat; def initialize; end; end", - "lib/app/baz.rb" => "class App::Baz; end" - - commit john, - "lib/app/bat.rb" => "class App::Bat; end", - "lib/app/baz.rb" => "class App::Baz; def initialize; end; end" - - commit joey, - "lib/app/bat.rb" => "class App::Bat; def initialize; end; end", - "lib/app/baz.rb" => "class App::Baz; end" - - # Mock the configuration - allow(MOSAIK) - .to receive(:configuration) - .and_return configuration - end - - after do - # Cleanup the temporary directory - FileUtils.remove_entry(directory) - end -end