diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-12-11 18:06:31 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-12-11 18:06:31 +0300 |
commit | 50f8366a8934db48d10d97de407296c026218c16 (patch) | |
tree | 3a307da7be573b5e364a15bc992bafff741d1cb7 /spec | |
parent | eaecd39726701594c7b4f77ff2eec203b68c947c (diff) | |
parent | cbeb06eb420f294b3a406f869f11de554048e93d (diff) |
Merge branch 'complexity/rubocop-metrics' into 'master'
Enable rubocop metrics
This enables rubocop metrics like CyclomaticComplexity and ABCSize.
Initial threshold values are high, should be probably decreased.
See merge request !1802
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/email/message/repository_push_spec.rb | 122 | ||||
-rw-r--r-- | spec/support/mentionable_shared_examples.rb | 6 |
3 files changed, 128 insertions, 6 deletions
diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index ce4a5244bd0..c90133fbf03 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -532,21 +532,21 @@ module Ci end it "returns errors if job stage is not a string" do - config = YAML.dump({ rspec: { script: "test", type: 1, allow_failure: "string" } }) + config = YAML.dump({ rspec: { script: "test", type: 1 } }) expect do GitlabCiYamlProcessor.new(config, path) end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy") end it "returns errors if job stage is not a pre-defined stage" do - config = YAML.dump({ rspec: { script: "test", type: "acceptance", allow_failure: "string" } }) + config = YAML.dump({ rspec: { script: "test", type: "acceptance" } }) expect do GitlabCiYamlProcessor.new(config, path) end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy") end it "returns errors if job stage is not a defined stage" do - config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", type: "acceptance", allow_failure: "string" } }) + config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", type: "acceptance" } }) expect do GitlabCiYamlProcessor.new(config, path) end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test") diff --git a/spec/lib/gitlab/email/message/repository_push_spec.rb b/spec/lib/gitlab/email/message/repository_push_spec.rb new file mode 100644 index 00000000000..56ae2a8d121 --- /dev/null +++ b/spec/lib/gitlab/email/message/repository_push_spec.rb @@ -0,0 +1,122 @@ +require 'spec_helper' + +describe Gitlab::Email::Message::RepositoryPush do + include RepoHelpers + + let!(:group) { create(:group, name: 'my_group') } + let!(:project) { create(:project, name: 'my_project', namespace: group) } + let!(:author) { create(:author, name: 'Author') } + + let(:message) do + described_class.new(Notify, project.id, 'recipient@example.com', opts) + end + + context 'new commits have been pushed to repository' do + let(:opts) do + { author_id: author.id, ref: 'master', action: :push, compare: compare, + send_from_committer_email: true } + end + let(:compare) do + Gitlab::Git::Compare.new(project.repository.raw_repository, + sample_image_commit.id, sample_commit.id) + end + + describe '#project' do + subject { message.project } + it { is_expected.to eq project } + it { is_expected.to be_an_instance_of Project } + end + + describe '#project_namespace' do + subject { message.project_namespace } + it { is_expected.to eq group } + it { is_expected.to be_kind_of Namespace } + end + + describe '#project_name_with_namespace' do + subject { message.project_name_with_namespace } + it { is_expected.to eq 'my_group / my_project' } + end + + describe '#author' do + subject { message.author } + it { is_expected.to eq author } + it { is_expected.to be_an_instance_of User } + end + + describe '#author_name' do + subject { message.author_name } + it { is_expected.to eq 'Author' } + end + + describe '#commits' do + subject { message.commits } + it { is_expected.to be_kind_of Array } + it { is_expected.to all(be_instance_of Commit) } + end + + describe '#diffs' do + subject { message.diffs } + it { is_expected.to all(be_an_instance_of Gitlab::Git::Diff) } + end + + describe '#diffs_count' do + subject { message.diffs_count } + it { is_expected.to eq compare.diffs.count } + end + + describe '#compare' do + subject { message.compare } + it { is_expected.to be_an_instance_of Gitlab::Git::Compare } + end + + describe '#compare_timeout' do + subject { message.compare_timeout } + it { is_expected.to eq compare.timeout } + end + + describe '#reverse_compare?' do + subject { message.reverse_compare? } + it { is_expected.to eq false } + end + + describe '#disable_diffs?' do + subject { message.disable_diffs? } + it { is_expected.to eq false } + end + + describe '#send_from_committer_email?' do + subject { message.send_from_committer_email? } + it { is_expected.to eq true } + end + + describe '#action_name' do + subject { message.action_name } + it { is_expected.to eq 'pushed to' } + end + + describe '#ref_name' do + subject { message.ref_name } + it { is_expected.to eq 'master' } + end + + describe '#ref_type' do + subject { message.ref_type } + it { is_expected.to eq 'branch' } + end + + describe '#target_url' do + subject { message.target_url } + it { is_expected.to include 'compare' } + it { is_expected.to include compare.commits.first.parents.first.id } + it { is_expected.to include compare.commits.last.id } + end + + describe '#subject' do + subject { message.subject } + it { is_expected.to include "[Git][#{project.path_with_namespace}]" } + it { is_expected.to include "#{compare.commits.length} commits" } + it { is_expected.to include compare.commits.first.message.split("\n").first } + end + end +end diff --git a/spec/support/mentionable_shared_examples.rb b/spec/support/mentionable_shared_examples.rb index 33d2b14583c..fce91015fd4 100644 --- a/spec/support/mentionable_shared_examples.rb +++ b/spec/support/mentionable_shared_examples.rb @@ -4,7 +4,7 @@ # - let(:backref_text) { "the way that +subject+ should refer to itself in backreferences " } # - let(:set_mentionable_text) { lambda { |txt| "block that assigns txt to the subject's mentionable_text" } } -def common_mentionable_setup +shared_context 'mentionable context' do let(:project) { subject.project } let(:author) { subject.author } @@ -56,7 +56,7 @@ def common_mentionable_setup end shared_examples 'a mentionable' do - common_mentionable_setup + include_context 'mentionable context' it 'generates a descriptive back-reference' do expect(subject.gfm_reference).to eq(backref_text) @@ -88,7 +88,7 @@ shared_examples 'a mentionable' do end shared_examples 'an editable mentionable' do - common_mentionable_setup + include_context 'mentionable context' it_behaves_like 'a mentionable' |