2016-09-22 19:04:35 +02:00
|
|
|
# frozen_string_literal: true
|
2015-05-25 13:34:37 +03:00
|
|
|
describe GitHubChangelogGenerator::Parser do
|
2015-05-26 14:56:49 +03:00
|
|
|
describe ".user_project_from_remote" do
|
2015-06-11 13:09:04 +03:00
|
|
|
context "when remote is type 1" do
|
2015-05-25 13:34:37 +03:00
|
|
|
subject { GitHubChangelogGenerator::Parser.user_project_from_remote("origin https://github.com/skywinder/ActionSheetPicker-3.0 (fetch)") }
|
|
|
|
it { is_expected.to be_a(Array) }
|
|
|
|
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
|
|
|
|
end
|
2015-06-11 13:09:04 +03:00
|
|
|
context "when remote is type 2" do
|
2015-05-25 13:34:37 +03:00
|
|
|
subject { GitHubChangelogGenerator::Parser.user_project_from_remote("https://github.com/skywinder/ActionSheetPicker-3.0") }
|
|
|
|
it { is_expected.to be_a(Array) }
|
|
|
|
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
|
|
|
|
end
|
2015-06-11 13:09:04 +03:00
|
|
|
context "when remote is type 3" do
|
2015-05-25 13:34:37 +03:00
|
|
|
subject { GitHubChangelogGenerator::Parser.user_project_from_remote("https://github.com/skywinder/ActionSheetPicker-3.0") }
|
|
|
|
it { is_expected.to be_a(Array) }
|
|
|
|
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
|
|
|
|
end
|
2015-06-11 13:09:04 +03:00
|
|
|
context "when remote is type 4" do
|
2015-05-25 13:34:37 +03:00
|
|
|
subject { GitHubChangelogGenerator::Parser.user_project_from_remote("origin git@github.com:skywinder/ActionSheetPicker-3.0.git (fetch)") }
|
|
|
|
it { is_expected.to be_a(Array) }
|
|
|
|
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
|
|
|
|
end
|
|
|
|
context "when remote is invalid" do
|
|
|
|
subject { GitHubChangelogGenerator::Parser.user_project_from_remote("some invalid text") }
|
|
|
|
it { is_expected.to be_a(Array) }
|
|
|
|
it { is_expected.to match_array([nil, nil]) }
|
|
|
|
end
|
|
|
|
end
|
2015-05-26 14:56:49 +03:00
|
|
|
describe ".user_project_from_option" do
|
2015-06-11 13:21:18 +03:00
|
|
|
context "when option is invalid" do
|
2016-01-05 21:38:52 +01:00
|
|
|
it("should return nil") { expect(GitHubChangelogGenerator::Parser.user_project_from_option("blah", nil, nil)).to be_nil }
|
2015-06-11 13:21:18 +03:00
|
|
|
end
|
2015-05-25 14:21:23 +03:00
|
|
|
|
|
|
|
context "when option is valid" do
|
2016-01-05 21:38:52 +01:00
|
|
|
subject { GitHubChangelogGenerator::Parser.user_project_from_option("skywinder/ActionSheetPicker-3.0", nil, nil) }
|
2015-05-25 14:21:23 +03:00
|
|
|
it { is_expected.to be_a(Array) }
|
|
|
|
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
|
|
|
|
end
|
|
|
|
context "when option nil" do
|
2016-01-05 21:38:52 +01:00
|
|
|
subject { GitHubChangelogGenerator::Parser.user_project_from_option(nil, nil, nil) }
|
2015-05-25 14:21:23 +03:00
|
|
|
it { is_expected.to be_a(Array) }
|
|
|
|
it { is_expected.to match_array([nil, nil]) }
|
|
|
|
end
|
2015-05-25 15:43:59 +03:00
|
|
|
context "when site is nil" do
|
|
|
|
subject { GitHubChangelogGenerator::Parser.user_project_from_option("skywinder/ActionSheetPicker-3.0", nil, nil) }
|
|
|
|
it { is_expected.to be_a(Array) }
|
|
|
|
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
|
|
|
|
end
|
|
|
|
context "when site is valid" do
|
|
|
|
subject { GitHubChangelogGenerator::Parser.user_project_from_option("skywinder/ActionSheetPicker-3.0", nil, "https://codeclimate.com") }
|
|
|
|
it { is_expected.to be_a(Array) }
|
|
|
|
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
|
|
|
|
end
|
|
|
|
context "when second arg is not nil" do
|
|
|
|
subject { GitHubChangelogGenerator::Parser.user_project_from_option("skywinder/ActionSheetPicker-3.0", "blah", nil) }
|
|
|
|
it { is_expected.to be_a(Array) }
|
|
|
|
it { is_expected.to match_array([nil, nil]) }
|
|
|
|
end
|
2016-07-21 10:51:14 +03:00
|
|
|
context "when all args is not nil" do
|
|
|
|
subject { GitHubChangelogGenerator::Parser.user_project_from_option("skywinder/ActionSheetPicker-3.0", "blah", "https://codeclimate.com") }
|
|
|
|
it { is_expected.to be_a(Array) }
|
|
|
|
it { is_expected.to match_array([nil, nil]) }
|
|
|
|
end
|
2015-05-25 14:21:23 +03:00
|
|
|
end
|
2016-07-21 17:26:53 +03:00
|
|
|
describe ".fetch_user_and_project" do
|
2016-09-01 20:47:31 +02:00
|
|
|
before do
|
|
|
|
stub_const("ARGV", ["https://github.com/skywinder/github-changelog-generator"])
|
2016-07-21 17:26:53 +03:00
|
|
|
end
|
2016-09-01 20:47:31 +02:00
|
|
|
|
2016-07-21 17:26:53 +03:00
|
|
|
context do
|
|
|
|
let(:valid_user) { "initialized_user" }
|
|
|
|
let(:options) { { user: valid_user } }
|
|
|
|
let(:options_before_change) { options.dup }
|
|
|
|
it "should leave user unchanged" do
|
|
|
|
expect { GitHubChangelogGenerator::Parser.fetch_user_and_project(options) }.to change { options }
|
|
|
|
.from(options_before_change)
|
|
|
|
.to(options_before_change.merge(project: "github-changelog-generator"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-05-25 13:34:37 +03:00
|
|
|
end
|