Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2019-02-06 13:00:01 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2019-02-06 13:00:01 +0300
commitb76bf63f01a24d8f4e3db5ad591e75bba65c2ef4 (patch)
treed1290e90319110d6b2f296e44d4c70e26ef706d3 /spec
parente1632cb8075bd3605b6ba1a074cdf9a5a633b6d5 (diff)
Add tests for a new class representing GitLab Docs page
Diffstat (limited to 'spec')
-rw-r--r--spec/gitlab/docs/page_spec.rb89
-rw-r--r--spec/spec_helper.rb13
2 files changed, 102 insertions, 0 deletions
diff --git a/spec/gitlab/docs/page_spec.rb b/spec/gitlab/docs/page_spec.rb
new file mode 100644
index 00000000..64cc98da
--- /dev/null
+++ b/spec/gitlab/docs/page_spec.rb
@@ -0,0 +1,89 @@
+require 'spec_helper'
+
+require 'nokogiri'
+require 'gitlab/docs/page'
+require 'gitlab/docs/link'
+require 'gitlab/docs/element'
+require 'gitlab/docs/document'
+
+describe Gitlab::Docs::Page do
+ subject do
+ described_class.new('some/file.html')
+ end
+
+ context 'when file exists' do
+ before do
+ allow(File).to receive(:exists?)
+ .with('some/file.html')
+ .and_return(true)
+
+ allow(File).to receive(:read)
+ .with('some/file.html')
+ .and_return <<~HTML
+ <html>
+ <body>
+ <a href="../link.html#my-anchor">See external file</a>
+ <a href="#internal-anchor">See internal section</a>
+ <a href="#internal-anchor-2">See internal section broken</a>
+
+ <h1 id="internal-anchor">Some section</h1>
+ </body
+ </html>
+ HTML
+ end
+
+ describe '#links' do
+ it 'collects links on a page' do
+ expect(subject.links.count).to eq 3
+ end
+ end
+
+ describe '#hrefs' do
+ it 'collects all hrefs' do
+ expect(subject.hrefs).to match_array %w[../link.html#my-anchor
+ #internal-anchor
+ #internal-anchor-2]
+ end
+ end
+
+ describe '#ids' do
+ it 'collects all ids' do
+ expect(subject.ids).to match_array %w[internal-anchor]
+ end
+ end
+
+ describe '#has_anchor?' do
+ it 'returns true when anchor exists on a page' do
+ expect(subject.has_anchor?('internal-anchor')).to be true
+ end
+
+ it 'returns false when anchors does not exist' do
+ expect(subject.has_anchor?('internal-anchor-2')).to be false
+ end
+ end
+ end
+
+ describe '#directory' do
+ it 'returns base directory of a file' do
+ expect(subject.directory).to eq 'some'
+ end
+ end
+
+ describe '.build' do
+ context 'when path does not lead to the HTML file' do
+ it 'builds an index.html page object' do
+ page = described_class.build('some/path')
+
+ expect(page.file).to eq 'some/path/index.html'
+ end
+ end
+
+ context 'when path leads to the HTML file' do
+ it 'builds an object representing that file' do
+ page = described_class.build('some/path/file.html')
+
+ expect(page.file).to eq 'some/path/file.html'
+ end
+ end
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 00000000..768e37cc
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,13 @@
+$LOAD_PATH << 'lib/'
+
+RSpec.configure do |config|
+ config.expect_with :rspec do |expectations|
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
+ end
+
+ config.mock_with :rspec do |mocks|
+ mocks.verify_partial_doubles = true
+ end
+
+ config.shared_context_metadata_behavior = :apply_to_host_groups
+end