mirror of
https://github.com/foo-dogsquared/asciidoctor-foodogsquared-extensions.git
synced 2025-01-30 22:57:56 +00:00
Add spec tests for Git blob include processor
This commit is contained in:
parent
74bb141a79
commit
33faaeac88
19
spec/fixtures/HEAD-LICENSE
vendored
Normal file
19
spec/fixtures/HEAD-LICENSE
vendored
Normal file
@ -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.
|
27
spec/fixtures/v1.0.0-shell.nix
vendored
Normal file
27
spec/fixtures/v1.0.0-shell.nix
vendored
Normal file
@ -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
|
||||
];
|
||||
}
|
63
spec/git_blob_include_processor_spec.rb
Normal file
63
spec/git_blob_include_processor_spec.rb
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user