diff options
author | Brandon Labuschagne <blabuschagne@gitlab.com> | 2019-01-10 14:31:07 +0200 |
---|---|---|
committer | Brandon Labuschagne <blabuschagne@gitlab.com> | 2019-01-10 14:31:07 +0200 |
commit | 69bd2a345a07ad2b5ab52533a5df96bbd3cb59f0 (patch) | |
tree | 10ce7f1ad6d74e0ba7f0f3a8fff6f208895e74fa | |
parent | fbe2c1c1043841530831be4ba85d7f5e449bbbb4 (diff) | |
download | gitlab-ce-69bd2a345a07ad2b5ab52533a5df96bbd3cb59f0.tar.gz |
Refactored tests
-rw-r--r-- | spec/lib/gitlab/release_blog_post_spec.rb | 20 | ||||
-rw-r--r-- | spec/lib/gitlab_spec.rb | 66 |
2 files changed, 42 insertions, 44 deletions
diff --git a/spec/lib/gitlab/release_blog_post_spec.rb b/spec/lib/gitlab/release_blog_post_spec.rb index d5fd6418afe..6cedad8d4ab 100644 --- a/spec/lib/gitlab/release_blog_post_spec.rb +++ b/spec/lib/gitlab/release_blog_post_spec.rb @@ -26,50 +26,47 @@ describe Gitlab::ReleaseBlogPost do EOS end - subject { described_class.instance.blog_post_url } + subject { described_class.send(:new).blog_post_url } before do stub_request(:get, 'https://about.gitlab.com/releases.xml') .to_return(status: 200, headers: { 'content-type' => ['text/xml'] }, body: releases_xml) end - around do |example| - release_post_url = described_class.instance.instance_variable_get(:@url) - described_class.instance.instance_variable_set(:@url, nil) - - example.run - - described_class.instance.instance_variable_set(:@url, release_post_url) - end - context 'matches GitLab version to blog post url' do it 'returns the correct url for major pre release' do stub_const('Gitlab::VERSION', '11.0.0-pre') + expect(subject).to eql('https://about.gitlab.com/2018/05/22/gitlab-10-8-released/') end it 'returns the correct url for major release candidate' do stub_const('Gitlab::VERSION', '11.0.0-rc3') + expect(subject).to eql('https://about.gitlab.com/2018/05/22/gitlab-10-8-released/') end it 'returns the correct url for major release' do stub_const('Gitlab::VERSION', '11.0.0') + expect(subject).to eql('https://about.gitlab.com/2018/06/22/gitlab-11-0-released/') end it 'returns the correct url for minor pre release' do stub_const('Gitlab::VERSION', '11.2.0-pre') + expect(subject).to eql('https://about.gitlab.com/2018/07/22/gitlab-11-1-released/') end it 'returns the correct url for minor release candidate' do stub_const('Gitlab::VERSION', '11.2.0-rc3') + expect(subject).to eql('https://about.gitlab.com/2018/07/22/gitlab-11-1-released/') end it 'returns the correct url for minor release' do stub_const('Gitlab::VERSION', '11.2.0') + expect(subject).to eql('https://about.gitlab.com/2018/08/22/gitlab-11-2-released/') end @@ -80,16 +77,19 @@ describe Gitlab::ReleaseBlogPost do it 'returns the correct url for patch release candidate' do stub_const('Gitlab::VERSION', '11.2.1-rc3') + expect(subject).to eql('https://about.gitlab.com/2018/08/22/gitlab-11-2-released/') end it 'returns the correct url for patch release' do stub_const('Gitlab::VERSION', '11.2.1') + expect(subject).to eql('https://about.gitlab.com/2018/08/22/gitlab-11-2-released/') end it 'returns nil when no blog post is matched' do stub_const('Gitlab::VERSION', '9.0.0') + expect(subject).to be(nil) end end diff --git a/spec/lib/gitlab_spec.rb b/spec/lib/gitlab_spec.rb index 1330a24c674..14bbc7e8f43 100644 --- a/spec/lib/gitlab_spec.rb +++ b/spec/lib/gitlab_spec.rb @@ -73,78 +73,76 @@ describe Gitlab do describe '.final_release?' do subject { described_class.final_release? } - context 'pre release' do - before do + context 'returns the corrent boolean value' do + it 'is false for a pre release' do stub_const('Gitlab::VERSION', '11.0.0-pre') - end - it { is_expected.to be false } - end + expect(subject).to be false + end - context 'RC release' do - before do + it 'is false for a release candidate' do stub_const('Gitlab::VERSION', '11.0.0-rc2') - end - it { is_expected.to be false } - end + expect(subject).to be false + end - context 'final release' do - before do + it 'is true for a final release' do stub_const('Gitlab::VERSION', '11.0.2') - end - it { is_expected.to be true } + expect(subject).to be true + end end end describe '.minor_release' do subject { described_class.minor_release } - before do + it 'returns the minor release of the full GitLab version' do stub_const('Gitlab::VERSION', '11.0.1-rc3') - end - it { is_expected.to eql '11.0' } + expect(subject).to eql '11.0' + end end describe '.previous_release' do subject { described_class.previous_release } - context 'major release' do - before do + context 'it should return the previous release' do + it 'returns the previous major version when GitLab major version is not final' do stub_const('Gitlab::VERSION', '11.0.1-pre') - end - it { is_expected.to eql '10' } - end + expect(subject).to eql '10' + end - context 'minor release' do - before do + it 'returns the current minor version when the GitLab patch version is not final, but above zero' do stub_const('Gitlab::VERSION', '11.2.1-rc3') + + expect(subject).to eql '11.2' end - it { is_expected.to eql '11.2' } + it 'returns the previous minor version when the GitLab patch version is not final and is zero' do + stub_const('Gitlab::VERSION', '11.2.0-rc3') + + expect(subject).to eql '11.1' + end end end describe '.new_major_release?' do subject { described_class.new_major_release? } - context 'major release' do - before do + context 'returns the corrent boolean value' do + it 'is true when the minor version is 0 and the patch is a pre release' do stub_const('Gitlab::VERSION', '11.0.1-pre') - end - it { is_expected.to be true } - end + expect(subject).to be true + end - context 'minor release' do - before do + it 'is false when the minor version is above 0' do stub_const('Gitlab::VERSION', '11.2.1-rc3') - end - it { is_expected.to be false } + expect(subject).to be false + end end end |