From 33faaeac88c4d17d88b9a9141f34546666e8be97 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sun, 29 Oct 2023 17:39:30 +0800 Subject: [PATCH] Add spec tests for Git blob include processor --- spec/fixtures/HEAD-LICENSE | 19 ++++++++ spec/fixtures/v1.0.0-shell.nix | 27 +++++++++++ spec/git_blob_include_processor_spec.rb | 63 +++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 spec/fixtures/HEAD-LICENSE create mode 100644 spec/fixtures/v1.0.0-shell.nix create mode 100644 spec/git_blob_include_processor_spec.rb diff --git a/spec/fixtures/HEAD-LICENSE b/spec/fixtures/HEAD-LICENSE new file mode 100644 index 0000000..a8631a7 --- /dev/null +++ b/spec/fixtures/HEAD-LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2023 Gabriel Arazas <foodogsquared@foodogsquared.one> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/spec/fixtures/v1.0.0-shell.nix b/spec/fixtures/v1.0.0-shell.nix new file mode 100644 index 0000000..ee6c0a4 --- /dev/null +++ b/spec/fixtures/v1.0.0-shell.nix @@ -0,0 +1,27 @@ +{ pkgs ? import <nixpkgs> { }, ruby-nix }: + +with pkgs; + +let + gems = ruby-nix.lib pkgs { + name = "asciidoctor-foodogsquared-extensions"; + ruby = ruby_3_1; + gemset = ./gemset.nix; + }; +in +mkShell { + buildInputs = [ + gems.env + gems.ruby + ]; + + packages = [ + bundix + + # Formatters + nixpkgs-fmt + + # Language servers + rnix-lsp + ]; +} diff --git a/spec/git_blob_include_processor_spec.rb b/spec/git_blob_include_processor_spec.rb new file mode 100644 index 0000000..3f9823b --- /dev/null +++ b/spec/git_blob_include_processor_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require 'open-uri' + +describe GitBlobIncludeProcessor do + it 'should find the LICENSE from the head commit of this Git repo' do + input = <<~INPUT + [source] + ---- + include::git:HEAD[path=LICENSE] + ---- + INPUT + + expected = File.read(fixtures_file('HEAD-LICENSE')) + + actual = (Asciidoctor.convert input).tr_s '\n', '\n' + (expect actual).to include expected.chomp + end + + it 'should find the README from a certain commit' do + input = <<~INPUT + [source] + ---- + include::git:v1.0.0[path=shell.nix] + ---- + INPUT + + expected = File.read(fixtures_file('v1.0.0-shell.nix')) + + actual = (Asciidoctor.convert input).tr_s '\n', '\n' + (expect actual).to include expected.chomp + end + + it 'should not find the non-existent commit from this repo' do + input = <<~INPUT + [source] + ---- + include::git:00000000-0000-0000-0000-000000000000[path=README.adoc] + ---- + INPUT + + expected = <<~RESULT + Unresolved directive for 'git:00000000-0000-0000-0000-000000000000' with the following error: + revspec '00000000-0000-0000-0000-000000000000' not found + RESULT + + actual = (Asciidoctor.convert input).tr_s '\n', '\n' + (expect actual).to include expected.chomp + end + + it 'should not find the non-existent repo' do + input = <<~INPUT + :gitrepo: ../very-homeless + + [source] + ----- + include::git:HEAD[path=README.adoc] + ---- + INPUT + + expect { Asciidoctor.convert input }.to raise_error StandardError + end +end