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
diff options
context:
space:
mode:
-rw-r--r--.rspec1
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock15
-rw-r--r--spec/gitlab/docs/page_spec.rb89
-rw-r--r--spec/spec_helper.rb13
5 files changed, 119 insertions, 0 deletions
diff --git a/.rspec b/.rspec
new file mode 100644
index 00000000..c99d2e73
--- /dev/null
+++ b/.rspec
@@ -0,0 +1 @@
+--require spec_helper
diff --git a/Gemfile b/Gemfile
index f1e2e8de..021dc58b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -23,4 +23,5 @@ end
group :test, :development do
gem 'scss_lint', '~> 0.57', require: false
gem 'highline', '~> 2.0'
+ gem 'rspec', '~> 3.5'
end
diff --git a/Gemfile.lock b/Gemfile.lock
index 944f8441..f646a20f 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -22,6 +22,7 @@ GEM
ref (~> 2.0)
ddmetrics (1.0.1)
ddplugin (1.0.2)
+ diff-lcs (1.3)
em-websocket (0.5.1)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
@@ -90,6 +91,19 @@ GEM
ffi (>= 0.5.0, < 2)
ref (2.0.0)
rouge (3.3.0)
+ rspec (3.8.0)
+ rspec-core (~> 3.8.0)
+ rspec-expectations (~> 3.8.0)
+ rspec-mocks (~> 3.8.0)
+ rspec-core (3.8.0)
+ rspec-support (~> 3.8.0)
+ rspec-expectations (3.8.2)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.8.0)
+ rspec-mocks (3.8.0)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.8.0)
+ rspec-support (3.8.0)
ruby_dep (1.5.0)
sass (3.6.0)
sass-listen (~> 4.0.0)
@@ -118,6 +132,7 @@ DEPENDENCIES
nokogiri (~> 1.7.0)
rake (~> 12.3)
rouge (~> 3.2)
+ rspec (~> 3.5)
sass (~> 3.6)
scss_lint (~> 0.57)
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