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:
authorBrian Williams <bwilliams@gitlab.com>2022-06-20 23:02:48 +0300
committerBrian Williams <bwilliams@gitlab.com>2022-06-21 03:38:22 +0300
commit98162b5fe38fdbb8533f32a23e9332ffee53b143 (patch)
tree2fbc8689bc05214bc4fc51a0b8f20d51ec093f37 /spec
parent5a855115294576d3bed356f016b0953d53fec0bd (diff)
Refactor edit_on_gitlab helperbwill/refactor-edit-on-gitlab
Rather than having a bunch of case statements with URLs, this changes the `edit_on_gitlab` helper so that it builds urls from a project path, a branch name, and a docs file path. This is easier to maintain since it's a data-driven approach. The PRODUCT_REPOS data can be edited without changing the program logic.
Diffstat (limited to 'spec')
-rw-r--r--spec/helpers/edit_on_gitlab_spec.rb49
-rw-r--r--spec/spec_helper.rb1
2 files changed, 50 insertions, 0 deletions
diff --git a/spec/helpers/edit_on_gitlab_spec.rb b/spec/helpers/edit_on_gitlab_spec.rb
new file mode 100644
index 00000000..e0cf14fa
--- /dev/null
+++ b/spec/helpers/edit_on_gitlab_spec.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require 'nanoc'
+require 'helpers/edit_on_gitlab'
+
+RSpec.describe Nanoc::Helpers::EditOnGitLab do
+ let(:mock_class) { Class.new { extend Nanoc::Helpers::EditOnGitLab } }
+ let(:identifier) { "/content/404.html" }
+ let(:content_filename) { "content/404.html" }
+
+ let(:mock_item) do
+ item = Struct.new(:identifier, :content_filename)
+ item.new(identifier, content_filename)
+ end
+
+ subject { mock_class.edit_on_gitlab(mock_item, editor: editor) }
+
+ describe '#edit_on_gitlab' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:identifier, :editor, :expected_url) do
+ "/omnibus/index.md" | :simple | "https://gitlab.com/gitlab-org/omnibus-gitlab/-/blob/master/doc/index.md"
+ "/omnibus/index.md" | :webide | "https://gitlab.com/-/ide/project/gitlab-org/omnibus-gitlab/edit/master/-/doc/index.md"
+ "/runner/index.md" | :simple | "https://gitlab.com/gitlab-org/gitlab-runner/-/blob/main/doc/index.md"
+ "/runner/index.md" | :webide | "https://gitlab.com/-/ide/project/gitlab-org/gitlab-runner/edit/main/-/doc/index.md"
+ "/charts/index.md" | :simple | "https://gitlab.com/gitlab-org/charts/gitlab/-/blob/master/doc/index.md"
+ "/charts/index.md" | :webide | "https://gitlab.com/-/ide/project/gitlab-org/charts/gitlab/edit/master/-/doc/index.md"
+ "/operator/index.md" | :simple | "https://gitlab.com/gitlab-org/cloud-native/gitlab-operator/-/blob/master/doc/index.md"
+ "/operator/index.md" | :webide | "https://gitlab.com/-/ide/project/gitlab-org/cloud-native/gitlab-operator/edit/master/-/doc/index.md"
+ "/ee/user/ssh.md" | :simple | "https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/user/ssh.md"
+ "/ee/user/ssh.md" | :webide | "https://gitlab.com/-/ide/project/gitlab-org/gitlab/edit/master/-/doc/user/ssh.md"
+ "/content/404.html" | :simple | "https://gitlab.com/gitlab-org/gitlab-docs/-/blob/main/content/404.html"
+ "/content/404.html" | :webide | "https://gitlab.com/-/ide/project/gitlab-org/gitlab-docs/edit/main/-/content/404.html"
+ end
+
+ with_them do
+ it 'returns correct url for identifier and editor' do
+ expect(subject).to eq(expected_url)
+ end
+ end
+
+ context 'with unknown editor' do
+ let(:editor) { :word }
+
+ it { expect { subject }.to raise_error("Unknown editor: word") }
+ end
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 43596af8..762c465b 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -2,6 +2,7 @@
$LOAD_PATH << 'lib/'
+require 'rspec-parameterized'
require 'gitlab/docs'
RSpec.configure do |config|