diff --git a/spec/fixtures/asciidoctor-v2.0.0-Rakefile b/spec/fixtures/asciidoctor-v2.0.0-Rakefile new file mode 100644 index 0000000..655e5c4 --- /dev/null +++ b/spec/fixtures/asciidoctor-v2.0.0-Rakefile @@ -0,0 +1,4 @@ +# frozen_string_literal: true +Dir.glob('tasks/*.rake').each {|file| load file } + +task default: %w(test:all) diff --git a/spec/fixtures/nixpkgs-a46b89df91f56c8aca7de32d270422353d855483-COPYING b/spec/fixtures/nixpkgs-a46b89df91f56c8aca7de32d270422353d855483-COPYING new file mode 100644 index 0000000..9a73903 --- /dev/null +++ b/spec/fixtures/nixpkgs-a46b89df91f56c8aca7de32d270422353d855483-COPYING @@ -0,0 +1,20 @@ +Copyright (c) 2003-2019 Eelco Dolstra and the Nixpkgs/NixOS contributors + +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/github_raw_content_include_processor_spec.rb b/spec/github_raw_content_include_processor_spec.rb new file mode 100644 index 0000000..9599151 --- /dev/null +++ b/spec/github_raw_content_include_processor_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +describe GitHubRawIncludeProcessor do + it 'should include the raw content of a GitHub file successfully' do + input = <<~INPUT + [literal] + .... + include::github:asciidoctor/asciidoctor[path=Rakefile, rev=v2.0.0] + .... + INPUT + + expected = File.read(fixtures_file('asciidoctor-v2.0.0-Rakefile')) + + actual = Asciidoctor.convert input.tr_s '\n', '\n' + (expect actual).to include expected.chomp + end + + it 'should get the raw content of COPYING from nixpkgs at a specific commit' do + commit = 'a46b89df91f56c8aca7de32d270422353d855483' + input = <<~INPUT + [literal] + .... + include::github:NixOS/nixpkgs[rev=#{commit}, path=COPYING] + .... + INPUT + + expected = File.read(fixtures_file("nixpkgs-#{commit}-COPYING")) + + actual = (Asciidoctor.convert input).tr_s '\n', '\n' + (expect actual).to include expected.chomp + end + + it 'should not process since it points to the root directory of the repo' do + input = 'include::github:asciidoctor/asciidoctor[]' + + expect { Asciidoctor.convert input }.to raise_error StandardError + end + + it 'should fail to point to non-existent repo' do + input = 'include::github:nonexistentrepoyay/OKOKOKOKOKOKOK[path=README.adoc, rev=v2.0.0]' + + expect { Asciidoctor.convert input }.to raise_error StandardError + end +end