summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorJeroen van Baarsen <jeroenvanbaarsen@gmail.com>2015-02-12 19:17:35 +0100
committerJeroen van Baarsen <jeroenvanbaarsen@gmail.com>2015-02-12 19:17:35 +0100
commit0c4a70a306b871899bf87ce4673918abfee4d95f (patch)
treec7a702fb511209ffe0eceba245d1ffea71dce1aa /spec/models
parentde1c450abd6b367390a1295cac402344f500d41d (diff)
downloadgitlab-ce-0c4a70a306b871899bf87ce4673918abfee4d95f.tar.gz
Updated rspec to rspec 3.x syntax
Signed-off-by: Jeroen van Baarsen <jeroenvanbaarsen@gmail.com>
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/application_setting_spec.rb2
-rw-r--r--spec/models/asana_service_spec.rb10
-rw-r--r--spec/models/broadcast_message_spec.rb8
-rw-r--r--spec/models/commit_spec.rb42
-rw-r--r--spec/models/concerns/issuable_spec.rb46
-rw-r--r--spec/models/concerns/mentionable_spec.rb4
-rw-r--r--spec/models/deploy_key_spec.rb4
-rw-r--r--spec/models/deploy_keys_project_spec.rb8
-rw-r--r--spec/models/event_spec.rb24
-rw-r--r--spec/models/forked_project_link_spec.rb10
-rw-r--r--spec/models/group_spec.rb30
-rw-r--r--spec/models/hooks/service_hook_spec.rb2
-rw-r--r--spec/models/hooks/system_hook_spec.rb20
-rw-r--r--spec/models/hooks/web_hook_spec.rb30
-rw-r--r--spec/models/issue_spec.rb10
-rw-r--r--spec/models/key_spec.rb28
-rw-r--r--spec/models/label_link_spec.rb6
-rw-r--r--spec/models/label_spec.rb30
-rw-r--r--spec/models/members/group_member_spec.rb6
-rw-r--r--spec/models/members/project_member_spec.rb26
-rw-r--r--spec/models/members_spec.rb12
-rw-r--r--spec/models/merge_request_spec.rb32
-rw-r--r--spec/models/milestone_spec.rb42
-rw-r--r--spec/models/namespace_spec.rb30
-rw-r--r--spec/models/note_spec.rb291
-rw-r--r--spec/models/project_security_spec.rb18
-rw-r--r--spec/models/project_services/assembla_service_spec.rb6
-rw-r--r--spec/models/project_services/buildbox_service_spec.rb18
-rw-r--r--spec/models/project_services/flowdock_service_spec.rb6
-rw-r--r--spec/models/project_services/gemnasium_service_spec.rb6
-rw-r--r--spec/models/project_services/gitlab_ci_service_spec.rb8
-rw-r--r--spec/models/project_services/jira_service_spec.rb12
-rw-r--r--spec/models/project_services/pushover_service_spec.rb12
-rw-r--r--spec/models/project_services/slack_message_spec.rb17
-rw-r--r--spec/models/project_services/slack_service_spec.rb8
-rw-r--r--spec/models/project_snippet_spec.rb4
-rw-r--r--spec/models/project_spec.rb130
-rw-r--r--spec/models/project_team_spec.rb44
-rw-r--r--spec/models/project_wiki_spec.rb80
-rw-r--r--spec/models/protected_branch_spec.rb6
-rw-r--r--spec/models/repository_spec.rb8
-rw-r--r--spec/models/service_spec.rb8
-rw-r--r--spec/models/snippet_spec.rb16
-rw-r--r--spec/models/user_spec.rb196
-rw-r--r--spec/models/wiki_page_spec.rb30
45 files changed, 758 insertions, 628 deletions
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb
index cd6d03e6c1a..cb43fdb7fc7 100644
--- a/spec/models/application_setting_spec.rb
+++ b/spec/models/application_setting_spec.rb
@@ -17,5 +17,5 @@
require 'spec_helper'
describe ApplicationSetting, models: true do
- it { ApplicationSetting.create_from_defaults.should be_valid }
+ it { expect(ApplicationSetting.create_from_defaults).to be_valid }
end
diff --git a/spec/models/asana_service_spec.rb b/spec/models/asana_service_spec.rb
index 6bebb76f8c7..83e39f87f33 100644
--- a/spec/models/asana_service_spec.rb
+++ b/spec/models/asana_service_spec.rb
@@ -16,8 +16,8 @@ require 'spec_helper'
describe AsanaService, models: true do
describe 'Associations' do
- it { should belong_to :project }
- it { should have_one :service_hook }
+ it { is_expected.to belong_to :project }
+ it { is_expected.to have_one :service_hook }
end
describe 'Validations' do
@@ -26,7 +26,7 @@ describe AsanaService, models: true do
subject.active = true
end
- it { should validate_presence_of :api_key }
+ it { is_expected.to validate_presence_of :api_key }
end
end
@@ -46,13 +46,13 @@ describe AsanaService, models: true do
end
it 'should call Asana service to created a story' do
- Asana::Task.should_receive(:find).with('123456').once
+ expect(Asana::Task).to receive(:find).with('123456').once
@asana.check_commit('related to #123456', 'pushed')
end
it 'should call Asana service to created a story and close a task' do
- Asana::Task.should_receive(:find).with('456789').twice
+ expect(Asana::Task).to receive(:find).with('456789').twice
@asana.check_commit('fix #456789', 'pushed')
end
diff --git a/spec/models/broadcast_message_spec.rb b/spec/models/broadcast_message_spec.rb
index 0f31c407c90..8ab72151a69 100644
--- a/spec/models/broadcast_message_spec.rb
+++ b/spec/models/broadcast_message_spec.rb
@@ -18,22 +18,22 @@ require 'spec_helper'
describe BroadcastMessage do
subject { create(:broadcast_message) }
- it { should be_valid }
+ it { is_expected.to be_valid }
describe :current do
it "should return last message if time match" do
broadcast_message = create(:broadcast_message, starts_at: Time.now.yesterday, ends_at: Time.now.tomorrow)
- BroadcastMessage.current.should == broadcast_message
+ expect(BroadcastMessage.current).to eq(broadcast_message)
end
it "should return nil if time not come" do
broadcast_message = create(:broadcast_message, starts_at: Time.now.tomorrow, ends_at: Time.now + 2.days)
- BroadcastMessage.current.should be_nil
+ expect(BroadcastMessage.current).to be_nil
end
it "should return nil if time has passed" do
broadcast_message = create(:broadcast_message, starts_at: Time.now - 2.days, ends_at: Time.now.yesterday)
- BroadcastMessage.current.should be_nil
+ expect(BroadcastMessage.current).to be_nil
end
end
end
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index 7a2a7a4ce9b..8b3d88640da 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -6,22 +6,22 @@ describe Commit do
describe '#title' do
it "returns no_commit_message when safe_message is blank" do
- commit.stub(:safe_message).and_return('')
- commit.title.should == "--no commit message"
+ allow(commit).to receive(:safe_message).and_return('')
+ expect(commit.title).to eq("--no commit message")
end
it "truncates a message without a newline at 80 characters" do
message = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit. Vivamus egestas lacinia lacus, sed rutrum mauris.'
- commit.stub(:safe_message).and_return(message)
- commit.title.should == "#{message[0..79]}&hellip;"
+ allow(commit).to receive(:safe_message).and_return(message)
+ expect(commit.title).to eq("#{message[0..79]}&hellip;")
end
it "truncates a message with a newline before 80 characters at the newline" do
message = commit.safe_message.split(" ").first
- commit.stub(:safe_message).and_return(message + "\n" + message)
- commit.title.should == message
+ allow(commit).to receive(:safe_message).and_return(message + "\n" + message)
+ expect(commit.title).to eq(message)
end
it "does not truncates a message with a newline after 80 but less 100 characters" do
@@ -30,25 +30,25 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis
Vivamus egestas lacinia lacus, sed rutrum mauris.
eos
- commit.stub(:safe_message).and_return(message)
- commit.title.should == message.split("\n").first
+ allow(commit).to receive(:safe_message).and_return(message)
+ expect(commit.title).to eq(message.split("\n").first)
end
end
describe "delegation" do
subject { commit }
- it { should respond_to(:message) }
- it { should respond_to(:authored_date) }
- it { should respond_to(:committed_date) }
- it { should respond_to(:committer_email) }
- it { should respond_to(:author_email) }
- it { should respond_to(:parents) }
- it { should respond_to(:date) }
- it { should respond_to(:diffs) }
- it { should respond_to(:tree) }
- it { should respond_to(:id) }
- it { should respond_to(:to_patch) }
+ it { is_expected.to respond_to(:message) }
+ it { is_expected.to respond_to(:authored_date) }
+ it { is_expected.to respond_to(:committed_date) }
+ it { is_expected.to respond_to(:committer_email) }
+ it { is_expected.to respond_to(:author_email) }
+ it { is_expected.to respond_to(:parents) }
+ it { is_expected.to respond_to(:date) }
+ it { is_expected.to respond_to(:diffs) }
+ it { is_expected.to respond_to(:tree) }
+ it { is_expected.to respond_to(:id) }
+ it { is_expected.to respond_to(:to_patch) }
end
describe '#closes_issues' do
@@ -58,13 +58,13 @@ eos
it 'detects issues that this commit is marked as closing' do
commit.stub(safe_message: "Fixes ##{issue.iid}")
- commit.closes_issues(project).should == [issue]
+ expect(commit.closes_issues(project)).to eq([issue])
end
it 'does not detect issues from other projects' do
ext_ref = "#{other_project.path_with_namespace}##{other_issue.iid}"
commit.stub(safe_message: "Fixes #{ext_ref}")
- commit.closes_issues(project).should be_empty
+ expect(commit.closes_issues(project)).to be_empty
end
end
diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb
index 9cbc8990676..557c71b4d2c 100644
--- a/spec/models/concerns/issuable_spec.rb
+++ b/spec/models/concerns/issuable_spec.rb
@@ -4,63 +4,63 @@ describe Issue, "Issuable" do
let(:issue) { create(:issue) }
describe "Associations" do
- it { should belong_to(:project) }
- it { should belong_to(:author) }
- it { should belong_to(:assignee) }
- it { should have_many(:notes).dependent(:destroy) }
+ it { is_expected.to belong_to(:project) }
+ it { is_expected.to belong_to(:author) }
+ it { is_expected.to belong_to(:assignee) }
+ it { is_expected.to have_many(:notes).dependent(:destroy) }
end
describe "Validation" do
before { subject.stub(set_iid: false) }
- it { should validate_presence_of(:project) }
- it { should validate_presence_of(:iid) }
- it { should validate_presence_of(:author) }
- it { should validate_presence_of(:title) }
- it { should ensure_length_of(:title).is_at_least(0).is_at_most(255) }
+ it { is_expected.to validate_presence_of(:project) }
+ it { is_expected.to validate_presence_of(:iid) }
+ it { is_expected.to validate_presence_of(:author) }
+ it { is_expected.to validate_presence_of(:title) }
+ it { is_expected.to ensure_length_of(:title).is_at_least(0).is_at_most(255) }
end
describe "Scope" do
- it { described_class.should respond_to(:opened) }
- it { described_class.should respond_to(:closed) }
- it { described_class.should respond_to(:assigned) }
+ it { expect(described_class).to respond_to(:opened) }
+ it { expect(described_class).to respond_to(:closed) }
+ it { expect(described_class).to respond_to(:assigned) }
end
describe ".search" do
let!(:searchable_issue) { create(:issue, title: "Searchable issue") }
it "matches by title" do
- described_class.search('able').should == [searchable_issue]
+ expect(described_class.search('able')).to eq([searchable_issue])
end
end
describe "#today?" do
it "returns true when created today" do
# Avoid timezone differences and just return exactly what we want
- Date.stub(:today).and_return(issue.created_at.to_date)
- issue.today?.should be_true
+ allow(Date).to receive(:today).and_return(issue.created_at.to_date)
+ expect(issue.today?).to be_truthy
end
it "returns false when not created today" do
- Date.stub(:today).and_return(Date.yesterday)
- issue.today?.should be_false
+ allow(Date).to receive(:today).and_return(Date.yesterday)
+ expect(issue.today?).to be_falsey
end
end
describe "#new?" do
it "returns true when created today and record hasn't been updated" do
- issue.stub(:today?).and_return(true)
- issue.new?.should be_true
+ allow(issue).to receive(:today?).and_return(true)
+ expect(issue.new?).to be_truthy
end
it "returns false when not created today" do
- issue.stub(:today?).and_return(false)
- issue.new?.should be_false
+ allow(issue).to receive(:today?).and_return(false)
+ expect(issue.new?).to be_falsey
end
it "returns false when record has been updated" do
- issue.stub(:today?).and_return(true)
+ allow(issue).to receive(:today?).and_return(true)
issue.touch
- issue.new?.should be_false
+ expect(issue.new?).to be_falsey
end
end
end
diff --git a/spec/models/concerns/mentionable_spec.rb b/spec/models/concerns/mentionable_spec.rb
index ca6f11b2a4d..eadb941a3fa 100644
--- a/spec/models/concerns/mentionable_spec.rb
+++ b/spec/models/concerns/mentionable_spec.rb
@@ -8,7 +8,7 @@ describe Issue, "Mentionable" do
subject { issue.mentioned_users }
- it { should include(user) }
- it { should_not include(user2) }
+ it { is_expected.to include(user) }
+ it { is_expected.not_to include(user2) }
end
end
diff --git a/spec/models/deploy_key_spec.rb b/spec/models/deploy_key_spec.rb
index adbbbac875f..b32be8d7a7c 100644
--- a/spec/models/deploy_key_spec.rb
+++ b/spec/models/deploy_key_spec.rb
@@ -19,7 +19,7 @@ describe DeployKey do
let(:deploy_key) { create(:deploy_key, projects: [project]) }
describe "Associations" do
- it { should have_many(:deploy_keys_projects) }
- it { should have_many(:projects) }
+ it { is_expected.to have_many(:deploy_keys_projects) }
+ it { is_expected.to have_many(:projects) }
end
end
diff --git a/spec/models/deploy_keys_project_spec.rb b/spec/models/deploy_keys_project_spec.rb
index 3e0e25ee39a..aacd9bf38bf 100644
--- a/spec/models/deploy_keys_project_spec.rb
+++ b/spec/models/deploy_keys_project_spec.rb
@@ -13,12 +13,12 @@ require 'spec_helper'
describe DeployKeysProject do
describe "Associations" do
- it { should belong_to(:deploy_key) }
- it { should belong_to(:project) }
+ it { is_expected.to belong_to(:deploy_key) }
+ it { is_expected.to belong_to(:project) }
end
describe "Validation" do
- it { should validate_presence_of(:project_id) }
- it { should validate_presence_of(:deploy_key_id) }
+ it { is_expected.to validate_presence_of(:project_id) }
+ it { is_expected.to validate_presence_of(:deploy_key_id) }
end
end
diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb
index 204ae9da704..0f32f162a10 100644
--- a/spec/models/event_spec.rb
+++ b/spec/models/event_spec.rb
@@ -18,16 +18,16 @@ require 'spec_helper'
describe Event do
describe "Associations" do
- it { should belong_to(:project) }
- it { should belong_to(:target) }
+ it { is_expected.to belong_to(:project) }
+ it { is_expected.to belong_to(:target) }
end
describe "Respond to" do
- it { should respond_to(:author_name) }
- it { should respond_to(:author_email) }
- it { should respond_to(:issue_title) }
- it { should respond_to(:merge_request_title) }
- it { should respond_to(:commits) }
+ it { is_expected.to respond_to(:author_name) }
+ it { is_expected.to respond_to(:author_email) }
+ it { is_expected.to respond_to(:issue_title) }
+ it { is_expected.to respond_to(:merge_request_title) }
+ it { is_expected.to respond_to(:commits) }
end
describe "Push event" do
@@ -58,10 +58,10 @@ describe Event do
)
end
- it { @event.push?.should be_true }
- it { @event.proper?.should be_true }
- it { @event.tag?.should be_false }
- it { @event.branch_name.should == "master" }
- it { @event.author.should == @user }
+ it { expect(@event.push?).to be_truthy }
+ it { expect(@event.proper?).to be_truthy }
+ it { expect(@event.tag?).to be_falsey }
+ it { expect(@event.branch_name).to eq("master") }
+ it { expect(@event.author).to eq(@user) }
end
end
diff --git a/spec/models/forked_project_link_spec.rb b/spec/models/forked_project_link_spec.rb
index 1845c6103f5..7d0ad44a92c 100644
--- a/spec/models/forked_project_link_spec.rb
+++ b/spec/models/forked_project_link_spec.rb
@@ -21,11 +21,11 @@ describe ForkedProjectLink, "add link on fork" do
end
it "project_to should know it is forked" do
- @project_to.forked?.should be_true
+ expect(@project_to.forked?).to be_truthy
end
it "project should know who it is forked from" do
- @project_to.forked_from_project.should == project_from
+ expect(@project_to.forked_from_project).to eq(project_from)
end
end
@@ -43,15 +43,15 @@ describe :forked_from_project do
it "project_to should know it is forked" do
- project_to.forked?.should be_true
+ expect(project_to.forked?).to be_truthy
end
it "project_from should not be forked" do
- project_from.forked?.should be_false
+ expect(project_from.forked?).to be_falsey
end
it "project_to.destroy should destroy fork_link" do
- forked_project_link.should_receive(:destroy)
+ expect(forked_project_link).to receive(:destroy)
project_to.destroy
end
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb
index 1d4ba8a2b85..9428224a64f 100644
--- a/spec/models/group_spec.rb
+++ b/spec/models/group_spec.rb
@@ -19,29 +19,29 @@ describe Group do
let!(:group) { create(:group) }
describe "Associations" do
- it { should have_many :projects }
- it { should have_many :group_members }
+ it { is_expected.to have_many :projects }
+ it { is_expected.to have_many :group_members }
end
- it { should validate_presence_of :name }
- it { should validate_uniqueness_of(:name) }
- it { should validate_presence_of :path }
- it { should validate_uniqueness_of(:path) }
- it { should_not validate_presence_of :owner }
+ it { is_expected.to validate_presence_of :name }
+ it { is_expected.to validate_uniqueness_of(:name) }
+ it { is_expected.to validate_presence_of :path }
+ it { is_expected.to validate_uniqueness_of(:path) }
+ it { is_expected.not_to validate_presence_of :owner }
describe :users do
- it { group.users.should == group.owners }
+ it { expect(group.users).to eq(group.owners) }
end
describe :human_name do
- it { group.human_name.should == group.name }
+ it { expect(group.human_name).to eq(group.name) }
end
describe :add_users do
let(:user) { create(:user) }
before { group.add_user(user, GroupMember::MASTER) }
- it { group.group_members.masters.map(&:user).should include(user) }
+ it { expect(group.group_members.masters.map(&:user)).to include(user) }
end
describe :add_users do
@@ -49,10 +49,10 @@ describe Group do
before { group.add_users([user.id], GroupMember::GUEST) }
it "should update the group permission" do
- group.group_members.guests.map(&:user).should include(user)
+ expect(group.group_members.guests.map(&:user)).to include(user)
group.add_users([user.id], GroupMember::DEVELOPER)
- group.group_members.developers.map(&:user).should include(user)
- group.group_members.guests.map(&:user).should_not include(user)
+ expect(group.group_members.developers.map(&:user)).to include(user)
+ expect(group.group_members.guests.map(&:user)).not_to include(user)
end
end
@@ -62,12 +62,12 @@ describe Group do
it "should be true if avatar is image" do
group.update_attribute(:avatar, 'uploads/avatar.png')
- group.avatar_type.should be_true
+ expect(group.avatar_type).to be_truthy
end
it "should be false if avatar is html page" do
group.update_attribute(:avatar, 'uploads/avatar.html')
- group.avatar_type.should == ["only images allowed"]
+ expect(group.avatar_type).to eq(["only images allowed"])
end
end
end
diff --git a/spec/models/hooks/service_hook_spec.rb b/spec/models/hooks/service_hook_spec.rb
index 6ec82438dfe..96bf74d45da 100644
--- a/spec/models/hooks/service_hook_spec.rb
+++ b/spec/models/hooks/service_hook_spec.rb
@@ -19,6 +19,6 @@ require "spec_helper"
describe ServiceHook do
describe "Associations" do
- it { should belong_to :service }
+ it { is_expected.to belong_to :service }
end
end
diff --git a/spec/models/hooks/system_hook_spec.rb b/spec/models/hooks/system_hook_spec.rb
index 8deb732de9c..810b311a40b 100644
--- a/spec/models/hooks/system_hook_spec.rb
+++ b/spec/models/hooks/system_hook_spec.rb
@@ -26,32 +26,32 @@ describe SystemHook do
it "project_create hook" do
Projects::CreateService.new(create(:user), name: 'empty').execute
- WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /project_create/).once
end
it "project_destroy hook" do
user = create(:user)
project = create(:empty_project, namespace: user.namespace)
Projects::DestroyService.new(project, user, {}).execute
- WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /project_destroy/).once
end
it "user_create hook" do
create(:user)
- WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_create/).once
end
it "user_destroy hook" do
user = create(:user)
user.destroy
- WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_destroy/).once
end
it "project_create hook" do
user = create(:user)
project = create(:project)
project.team << [user, :master]
- WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
end
it "project_destroy hook" do
@@ -59,12 +59,12 @@ describe SystemHook do
project = create(:project)
project.team << [user, :master]
project.project_members.destroy_all
- WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once
end
it 'group create hook' do
create(:group)
- WebMock.should have_requested(:post, @system_hook.url).with(
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(
body: /group_create/
).once
end
@@ -72,7 +72,7 @@ describe SystemHook do
it 'group destroy hook' do
group = create(:group)
group.destroy
- WebMock.should have_requested(:post, @system_hook.url).with(
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(
body: /group_destroy/
).once
end
@@ -81,7 +81,7 @@ describe SystemHook do
group = create(:group)
user = create(:user)
group.add_user(user, Gitlab::Access::MASTER)
- WebMock.should have_requested(:post, @system_hook.url).with(
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(
body: /user_add_to_group/
).once
end
@@ -91,7 +91,7 @@ describe SystemHook do
user = create(:user)
group.add_user(user, Gitlab::Access::MASTER)
group.group_members.destroy_all
- WebMock.should have_requested(:post, @system_hook.url).with(
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(
body: /user_remove_from_group/
).once
end
diff --git a/spec/models/hooks/web_hook_spec.rb b/spec/models/hooks/web_hook_spec.rb
index e9c04ee89cb..67ec9193ad7 100644
--- a/spec/models/hooks/web_hook_spec.rb
+++ b/spec/models/hooks/web_hook_spec.rb
@@ -19,25 +19,25 @@ require 'spec_helper'
describe ProjectHook do
describe "Associations" do
- it { should belong_to :project }
+ it { is_expected.to belong_to :project }
end
describe "Mass assignment" do
end
describe "Validations" do
- it { should validate_presence_of(:url) }
+ it { is_expected.to validate_presence_of(:url) }
context "url format" do
- it { should allow_value("http://example.com").for(:url) }
- it { should allow_value("https://excample.com").for(:url) }
- it { should allow_value("http://test.com/api").for(:url) }
- it { should allow_value("http://test.com/api?key=abc").for(:url) }
- it { should allow_value("http://test.com/api?key=abc&type=def").for(:url) }
+ it { is_expected.to allow_value("http://example.com").for(:url) }
+ it { is_expected.to allow_value("https://excample.com").for(:url) }
+ it { is_expected.to allow_value("http://test.com/api").for(:url) }
+ it { is_expected.to allow_value("http://test.com/api?key=abc").for(:url) }
+ it { is_expected.to allow_value("http://test.com/api?key=abc&type=def").for(:url) }
- it { should_not allow_value("example.com").for(:url) }
- it { should_not allow_value("ftp://example.com").for(:url) }
- it { should_not allow_value("herp-and-derp").for(:url) }
+ it { is_expected.not_to allow_value("example.com").for(:url) }
+ it { is_expected.not_to allow_value("ftp://example.com").for(:url) }
+ it { is_expected.not_to allow_value("herp-and-derp").for(:url) }
end
end
@@ -53,22 +53,22 @@ describe ProjectHook do
it "POSTs to the web hook URL" do
@project_hook.execute(@data)
- WebMock.should have_requested(:post, @project_hook.url).once
+ expect(WebMock).to have_requested(:post, @project_hook.url).once
end
it "POSTs the data as JSON" do
json = @data.to_json
@project_hook.execute(@data)
- WebMock.should have_requested(:post, @project_hook.url).with(body: json).once
+ expect(WebMock).to have_requested(:post, @project_hook.url).with(body: json).once
end
it "catches exceptions" do
- WebHook.should_receive(:post).and_raise("Some HTTP Post error")
+ expect(WebHook).to receive(:post).and_raise("Some HTTP Post error")
- lambda {
+ expect {
@project_hook.execute(@data)
- }.should raise_error
+ }.to raise_error
end
end
end
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index 6b6efe832e5..087e40c3d84 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -21,14 +21,14 @@ require 'spec_helper'
describe Issue do
describe "Associations" do
- it { should belong_to(:milestone) }
+ it { is_expected.to belong_to(:milestone) }
end
describe "Mass assignment" do
end
describe 'modules' do
- it { should include_module(Issuable) }
+ it { is_expected.to include_module(Issuable) }
end
subject { create(:issue) }
@@ -36,10 +36,10 @@ describe Issue do
describe '#is_being_reassigned?' do
it 'returns true if the issue assignee has changed' do
subject.assignee = create(:user)
- subject.is_being_reassigned?.should be_true
+ expect(subject.is_being_reassigned?).to be_truthy
end
it 'returns false if the issue assignee has not changed' do
- subject.is_being_reassigned?.should be_false
+ expect(subject.is_being_reassigned?).to be_falsey
end
end
@@ -51,7 +51,7 @@ describe Issue do
issue = create :issue, assignee: user
end
- Issue.open_for(user).count.should eq 2
+ expect(Issue.open_for(user).count).to eq 2
end
end
diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb
index 95c0aed0ffe..a212b95a7d6 100644
--- a/spec/models/key_spec.rb
+++ b/spec/models/key_spec.rb
@@ -16,67 +16,67 @@ require 'spec_helper'
describe Key do
describe "Associations" do
- it { should belong_to(:user) }
+ it { is_expected.to belong_to(:user) }
end
describe "Mass assignment" do
end
describe "Validation" do
- it { should validate_presence_of(:title) }
- it { should validate_presence_of(:key) }
- it { should ensure_length_of(:title).is_within(0..255) }
- it { should ensure_length_of(:key).is_within(0..5000) }
+ it { is_expected.to validate_presence_of(:title) }
+ it { is_expected.to validate_presence_of(:key) }
+ it { is_expected.to ensure_length_of(:title).is_within(0..255) }
+ it { is_expected.to ensure_length_of(:key).is_within(0..5000) }
end
describe "Methods" do
- it { should respond_to :projects }
+ it { is_expected.to respond_to :projects }
end
context "validation of uniqueness" do
let(:user) { create(:user) }
it "accepts the key once" do
- build(:key, user: user).should be_valid
+ expect(build(:key, user: user)).to be_valid
end
it "does not accept the exact same key twice" do
create(:key, user: user)
- build(:key, user: user).should_not be_valid
+ expect(build(:key, user: user)).not_to be_valid
end
it "does not accept a duplicate key with a different comment" do
create(:key, user: user)
duplicate = build(:key, user: user)
duplicate.key << ' extra comment'
- duplicate.should_not be_valid
+ expect(duplicate).not_to be_valid
end
end
context "validate it is a fingerprintable key" do
it "accepts the fingerprintable key" do
- build(:key).should be_valid
+ expect(build(:key)).to be_valid
end
it "rejects the unfingerprintable key (contains space in middle)" do
- build(:key_with_a_space_in_the_middle).should_not be_valid
+ expect(build(:key_with_a_space_in_the_middle)).not_to be_valid
end
it "rejects the unfingerprintable key (not a key)" do
- build(:invalid_key).should_not be_valid
+ expect(build(:invalid_key)).not_to be_valid
end
end
context 'callbacks' do
it 'should add new key to authorized_file' do
@key = build(:personal_key, id: 7)
- GitlabShellWorker.should_receive(:perform_async).with(:add_key, @key.shell_id, @key.key)
+ expect(GitlabShellWorker).to receive(:perform_async).with(:add_key, @key.shell_id, @key.key)
@key.save
end
it 'should remove key from authorized_file' do
@key = create(:personal_key)
- GitlabShellWorker.should_receive(:perform_async).with(:remove_key, @key.shell_id, @key.key)
+ expect(GitlabShellWorker).to receive(:perform_async).with(:remove_key, @key.shell_id, @key.key)
@key.destroy
end
end
diff --git a/spec/models/label_link_spec.rb b/spec/models/label_link_spec.rb
index 0db60432ad3..8c240826582 100644
--- a/spec/models/label_link_spec.rb
+++ b/spec/models/label_link_spec.rb
@@ -14,8 +14,8 @@ require 'spec_helper'
describe LabelLink do
let(:label) { create(:label_link) }
- it { label.should be_valid }
+ it { expect(label).to be_valid }
- it { should belong_to(:label) }
- it { should belong_to(:target) }
+ it { is_expected.to belong_to(:label) }
+ it { is_expected.to belong_to(:target) }
end
diff --git a/spec/models/label_spec.rb b/spec/models/label_spec.rb
index 31634648f04..8644ac46605 100644
--- a/spec/models/label_spec.rb
+++ b/spec/models/label_spec.rb
@@ -14,30 +14,30 @@ require 'spec_helper'
describe Label do
let(:label) { create(:label) }
- it { label.should be_valid }
+ it { expect(label).to be_valid }
- it { should belong_to(:project) }
+ it { is_expected.to belong_to(:project) }
describe 'Validation' do
it 'should validate color code' do
- build(:label, color: 'G-ITLAB').should_not be_valid
- build(:label, color: 'AABBCC').should_not be_valid
- build(:label, color: '#AABBCCEE').should_not be_valid
- build(:label, color: '#GGHHII').should_not be_valid
- build(:label, color: '#').should_not be_valid
- build(:label, color: '').should_not be_valid
+ expect(build(:label, color: 'G-ITLAB')).not_to be_valid
+ expect(build(:label, color: 'AABBCC')).not_to be_valid
+ expect(build(:label, color: '#AABBCCEE')).not_to be_valid
+ expect(build(:label, color: '#GGHHII')).not_to be_valid
+ expect(build(:label, color: '#')).not_to be_valid
+ expect(build(:label, color: '')).not_to be_valid
- build(:label, color: '#AABBCC').should be_valid
+ expect(build(:label, color: '#AABBCC')).to be_valid
end
it 'should validate title' do
- build(:label, title: 'G,ITLAB').should_not be_valid
- build(:label, title: 'G?ITLAB').should_not be_valid
- build(:label, title: 'G&ITLAB').should_not be_valid
- build(:label, title: '').should_not be_valid
+ expect(build(:label, title: 'G,ITLAB')).not_to be_valid
+ expect(build(:label, title: 'G?ITLAB')).not_to be_valid
+ expect(build(:label, title: 'G&ITLAB')).not_to be_valid
+ expect(build(:label, title: '')).not_to be_valid
- build(:label, title: 'GITLAB').should be_valid
- build(:label, title: 'gitlab').should be_valid
+ expect(build(:label, title: 'GITLAB')).to be_valid
+ expect(build(:label, title: 'gitlab')).to be_valid
end
end
end
diff --git a/spec/models/members/group_member_spec.rb b/spec/models/members/group_member_spec.rb
index 38657de6793..e04f1741b24 100644
--- a/spec/models/members/group_member_spec.rb
+++ b/spec/models/members/group_member_spec.rb
@@ -21,7 +21,7 @@ describe GroupMember do
it "should send email to user" do
membership = build(:group_member)
membership.stub(notification_service: double('NotificationService').as_null_object)
- membership.should_receive(:notification_service)
+ expect(membership).to receive(:notification_service)
membership.save
end
end
@@ -33,12 +33,12 @@ describe GroupMember do
end
it "should send email to user" do
- @membership.should_receive(:notification_service)
+ expect(@membership).to receive(:notification_service)
@membership.update_attribute(:access_level, GroupMember::MASTER)
end
it "does not send an email when the access level has not changed" do
- @membership.should_not_receive(:notification_service)
+ expect(@membership).not_to receive(:notification_service)
@membership.update_attribute(:access_level, GroupMember::OWNER)
end
end
diff --git a/spec/models/members/project_member_spec.rb b/spec/models/members/project_member_spec.rb
index 9b5f89b6d7d..521721f3577 100644
--- a/spec/models/members/project_member_spec.rb
+++ b/spec/models/members/project_member_spec.rb
@@ -33,19 +33,19 @@ describe ProjectMember do
@status = @project_2.team.import(@project_1)
end
- it { @status.should be_true }
+ it { expect(@status).to be_truthy }
describe 'project 2 should get user 1 as developer. user_2 should not be changed' do
- it { @project_2.users.should include(@user_1) }
- it { @project_2.users.should include(@user_2) }
+ it { expect(@project_2.users).to include(@user_1) }
+ it { expect(@project_2.users).to include(@user_2) }
- it { @abilities.allowed?(@user_1, :write_project, @project_2).should be_true }
- it { @abilities.allowed?(@user_2, :read_project, @project_2).should be_true }
+ it { expect(@abilities.allowed?(@user_1, :write_project, @project_2)).to be_truthy }
+ it { expect(@abilities.allowed?(@user_2, :read_project, @project_2)).to be_truthy }
end
describe 'project 1 should not be changed' do
- it { @project_1.users.should include(@user_1) }
- it { @project_1.users.should_not include(@user_2) }
+ it { expect(@project_1.users).to include(@user_1) }
+ it { expect(@project_1.users).not_to include(@user_2) }
end
end
@@ -64,12 +64,12 @@ describe ProjectMember do
)
end
- it { @project_1.users.should include(@user_1) }
- it { @project_1.users.should include(@user_2) }
+ it { expect(@project_1.users).to include(@user_1) }
+ it { expect(@project_1.users).to include(@user_2) }
- it { @project_2.users.should include(@user_1) }
- it { @project_2.users.should include(@user_2) }
+ it { expect(@project_2.users).to include(@user_1) }
+ it { expect(@project_2.users).to include(@user_2) }
end
describe :truncate_teams do
@@ -86,7 +86,7 @@ describe ProjectMember do
ProjectMember.truncate_teams([@project_1.id, @project_2.id])
end
- it { @project_1.users.should be_empty }
- it { @project_2.users.should be_empty }
+ it { expect(@project_1.users).to be_empty }
+ it { expect(@project_2.users).to be_empty }
end
end
diff --git a/spec/models/members_spec.rb b/spec/models/members_spec.rb
index cea653ec285..dfd3f7feb6b 100644
--- a/spec/models/members_spec.rb
+++ b/spec/models/members_spec.rb
@@ -2,19 +2,19 @@ require 'spec_helper'
describe Member do
describe "Associations" do
- it { should belong_to(:user) }
+ it { is_expected.to belong_to(:user) }
end
describe "Validation" do
subject { Member.new(access_level: Member::GUEST) }
- it { should validate_presence_of(:user) }
- it { should validate_presence_of(:source) }
- it { should validate_inclusion_of(:access_level).in_array(Gitlab::Access.values) }
+ it { is_expected.to validate_presence_of(:user) }
+ it { is_expected.to validate_presence_of(:source) }
+ it { is_expected.to validate_inclusion_of(:access_level).in_array(Gitlab::Access.values) }
end
describe "Delegate methods" do
- it { should respond_to(:user_name) }
- it { should respond_to(:user_email) }
+ it { is_expected.to respond_to(:user_name) }
+ it { is_expected.to respond_to(:user_email) }
end
end
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 9585cf09768..d40503d791c 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -25,35 +25,35 @@ require 'spec_helper'
describe MergeRequest do
describe "Validation" do
- it { should validate_presence_of(:target_branch) }
- it { should validate_presence_of(:source_branch) }
+ it { is_expected.to validate_presence_of(:target_branch) }
+ it { is_expected.to validate_presence_of(:source_branch) }
end
describe "Mass assignment" do
end
describe "Respond to" do
- it { should respond_to(:unchecked?) }
- it { should respond_to(:can_be_merged?) }
- it { should respond_to(:cannot_be_merged?) }
+ it { is_expected.to respond_to(:unchecked?) }
+ it { is_expected.to respond_to(:can_be_merged?) }
+ it { is_expected.to respond_to(:cannot_be_merged?) }
end
describe 'modules' do
- it { should include_module(Issuable) }
+ it { is_expected.to include_module(Issuable) }
end
describe "#mr_and_commit_notes" do
let!(:merge_request) { create(:merge_request) }
before do
- merge_request.stub(:commits) { [merge_request.source_project.repository.commit] }
+ allow(merge_request).to receive(:commits) { [merge_request.source_project.repository.commit] }
create(:note, commit_id: merge_request.commits.first.id, noteable_type: 'Commit', project: merge_request.project)
create(:note, noteable: merge_request, project: merge_request.project)
end
it "should include notes for commits" do
- merge_request.commits.should_not be_empty
- merge_request.mr_and_commit_notes.count.should == 2
+ expect(merge_request.commits).not_to be_empty
+ expect(merge_request.mr_and_commit_notes.count).to eq(2)
end
end
@@ -62,10 +62,10 @@ describe MergeRequest do
describe '#is_being_reassigned?' do
it 'returns true if the merge_request assignee has changed' do
subject.assignee = create(:user)
- subject.is_being_reassigned?.should be_true
+ expect(subject.is_being_reassigned?).to be_truthy
end
it 'returns false if the merge request assignee has not changed' do
- subject.is_being_reassigned?.should be_false
+ expect(subject.is_being_reassigned?).to be_falsey
end
end
@@ -74,11 +74,11 @@ describe MergeRequest do
subject.source_project = create(:project, namespace: create(:group))
subject.target_project = create(:project, namespace: create(:group))
- subject.for_fork?.should be_true
+ expect(subject.for_fork?).to be_truthy
end
it 'returns false if is not for a fork' do
- subject.for_fork?.should be_false
+ expect(subject.for_fork?).to be_falsey
end
end
@@ -96,14 +96,14 @@ describe MergeRequest do
it 'accesses the set of issues that will be closed on acceptance' do
subject.project.stub(default_branch: subject.target_branch)
- subject.closes_issues.should == [issue0, issue1].sort_by(&:id)
+ expect(subject.closes_issues).to eq([issue0, issue1].sort_by(&:id))
end
it 'only lists issues as to be closed if it targets the default branch' do
subject.project.stub(default_branch: 'master')
subject.target_branch = 'something-else'
- subject.closes_issues.should be_empty
+ expect(subject.closes_issues).to be_empty
end
it 'detects issues mentioned in the description' do
@@ -111,7 +111,7 @@ describe MergeRequest do
subject.description = "Closes ##{issue2.iid}"
subject.project.stub(default_branch: subject.target_branch)
- subject.closes_issues.should include(issue2)
+ expect(subject.closes_issues).to include(issue2)
end
end
diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb
index a3071c3251a..45171e1bf64 100644
--- a/spec/models/milestone_spec.rb
+++ b/spec/models/milestone_spec.rb
@@ -17,8 +17,8 @@ require 'spec_helper'
describe Milestone do
describe "Associations" do
- it { should belong_to(:project) }
- it { should have_many(:issues) }
+ it { is_expected.to belong_to(:project) }
+ it { is_expected.to have_many(:issues) }
end
describe "Mass assignment" do
@@ -26,8 +26,8 @@ describe Milestone do
describe "Validation" do
before { subject.stub(set_iid: false) }
- it { should validate_presence_of(:title) }
- it { should validate_presence_of(:project) }
+ it { is_expected.to validate_presence_of(:title) }
+ it { is_expected.to validate_presence_of(:project) }
end
let(:milestone) { create(:milestone) }
@@ -36,30 +36,30 @@ describe Milestone do
describe "#percent_complete" do
it "should not count open issues" do
milestone.issues << issue
- milestone.percent_complete.should == 0
+ expect(milestone.percent_complete).to eq(0)
end
it "should count closed issues" do
issue.close
milestone.issues << issue
- milestone.percent_complete.should == 100
+ expect(milestone.percent_complete).to eq(100)
end
it "should recover from dividing by zero" do
- milestone.issues.should_receive(:count).and_return(0)
- milestone.percent_complete.should == 100
+ expect(milestone.issues).to receive(:count).and_return(0)
+ expect(milestone.percent_complete).to eq(100)
end
end
describe "#expires_at" do
it "should be nil when due_date is unset" do
milestone.update_attributes(due_date: nil)
- milestone.expires_at.should be_nil
+ expect(milestone.expires_at).to be_nil
end
it "should not be nil when due_date is set" do
milestone.update_attributes(due_date: Date.tomorrow)
- milestone.expires_at.should be_present
+ expect(milestone.expires_at).to be_present
end
end
@@ -69,7 +69,7 @@ describe Milestone do
milestone.stub(due_date: Date.today.prev_year)
end
- it { milestone.expired?.should be_true }
+ it { expect(milestone.expired?).to be_truthy }
end
context "not expired" do
@@ -77,7 +77,7 @@ describe Milestone do
milestone.stub(due_date: Date.today.next_year)
end
- it { milestone.expired?.should be_false }
+ it { expect(milestone.expired?).to be_falsey }
end
end
@@ -89,7 +89,7 @@ describe Milestone do
)
end
- it { milestone.percent_complete.should == 75 }
+ it { expect(milestone.percent_complete).to eq(75) }
end
describe :items_count do
@@ -99,14 +99,14 @@ describe Milestone do
milestone.merge_requests << create(:merge_request)
end
- it { milestone.closed_items_count.should == 1 }
- it { milestone.open_items_count.should == 2 }
- it { milestone.total_items_count.should == 3 }
- it { milestone.is_empty?.should be_false }
+ it { expect(milestone.closed_items_count).to eq(1) }
+ it { expect(milestone.open_items_count).to eq(2) }
+ it { expect(milestone.total_items_count).to eq(3) }
+ it { expect(milestone.is_empty?).to be_falsey }
end
describe :can_be_closed? do
- it { milestone.can_be_closed?.should be_true }
+ it { expect(milestone.can_be_closed?).to be_truthy }
end
describe :is_empty? do
@@ -116,7 +116,7 @@ describe Milestone do
end
it 'Should return total count of issues and merge requests assigned to milestone' do
- milestone.total_items_count.should eq 2
+ expect(milestone.total_items_count).to eq 2
end
end
@@ -129,14 +129,14 @@ describe Milestone do
end
it 'should be true if milestone active and all nested issues closed' do
- milestone.can_be_closed?.should be_true
+ expect(milestone.can_be_closed?).to be_truthy
end
it 'should be false if milestone active and not all nested issues closed' do
issue.milestone = milestone
issue.save
- milestone.can_be_closed?.should be_false
+ expect(milestone.can_be_closed?).to be_falsey
end
end
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb
index 3562ebed1ff..4e268f8d8fa 100644
--- a/spec/models/namespace_spec.rb
+++ b/spec/models/namespace_spec.rb
@@ -18,29 +18,29 @@ require 'spec_helper'
describe Namespace do
let!(:namespace) { create(:namespace) }
- it { should have_many :projects }
- it { should validate_presence_of :name }
- it { should validate_uniqueness_of(:name) }
- it { should validate_presence_of :path }
- it { should validate_uniqueness_of(:path) }
- it { should validate_presence_of :owner }
+ it { is_expected.to have_many :projects }
+ it { is_expected.to validate_presence_of :name }
+ it { is_expected.to validate_uniqueness_of(:name) }
+ it { is_expected.to validate_presence_of :path }
+ it { is_expected.to validate_uniqueness_of(:path) }
+ it { is_expected.to validate_presence_of :owner }
describe "Mass assignment" do
end
describe "Respond to" do
- it { should respond_to(:human_name) }
- it { should respond_to(:to_param) }
+ it { is_expected.to respond_to(:human_name) }
+ it { is_expected.to respond_to(:to_param) }
end
- it { Namespace.global_id.should == 'GLN' }
+ it { expect(Namespace.global_id).to eq('GLN') }
describe :to_param do
- it { namespace.to_param.should == namespace.path }
+ it { expect(namespace.to_param).to eq(namespace.path) }
end
describe :human_name do
- it { namespace.human_name.should == namespace.owner_name }
+ it { expect(namespace.human_name).to eq(namespace.owner_name) }
end
describe :search do
@@ -48,8 +48,8 @@ describe Namespace do
@namespace = create :namespace
end
- it { Namespace.search(@namespace.path).should == [@namespace] }
- it { Namespace.search('unknown').should == [] }
+ it { expect(Namespace.search(@namespace.path)).to eq([@namespace]) }
+ it { expect(Namespace.search('unknown')).to eq([]) }
end
describe :move_dir do
@@ -66,13 +66,13 @@ describe Namespace do
new_path = @namespace.path + "_new"
@namespace.stub(path_was: @namespace.path)
@namespace.stub(path: new_path)
- @namespace.move_dir.should be_true
+ expect(@namespace.move_dir).to be_truthy
end
end
describe :rm_dir do
it "should remove dir" do
- namespace.rm_dir.should be_true
+ expect(namespace.rm_dir).to be_truthy
end
end
end
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 6ab7162c15c..17cb439c90e 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -21,17 +21,17 @@ require 'spec_helper'
describe Note do
describe "Associations" do
- it { should belong_to(:project) }
- it { should belong_to(:noteable) }
- it { should belong_to(:author).class_name('User') }
+ it { is_expected.to belong_to(:project) }
+ it { is_expected.to belong_to(:noteable) }
+ it { is_expected.to belong_to(:author).class_name('User') }
end
describe "Mass assignment" do
end
describe "Validation" do
- it { should validate_presence_of(:note) }
- it { should validate_presence_of(:project) }
+ it { is_expected.to validate_presence_of(:note) }
+ it { is_expected.to validate_presence_of(:project) }
end
describe "Voting score" do
@@ -39,44 +39,44 @@ describe Note do
it "recognizes a neutral note" do
note = create(:votable_note, note: "This is not a +1 note")
- note.should_not be_upvote
- note.should_not be_downvote
+ expect(note).not_to be_upvote
+ expect(note).not_to be_downvote
end
it "recognizes a neutral emoji note" do
note = build(:votable_note, note: "I would :+1: this, but I don't want to")
- note.should_not be_upvote
- note.should_not be_downvote
+ expect(note).not_to be_upvote
+ expect(note).not_to be_downvote
end
it "recognizes a +1 note" do
note = create(:votable_note, note: "+1 for this")
- note.should be_upvote
+ expect(note).to be_upvote
end
it "recognizes a +1 emoji as a vote" do
note = build(:votable_note, note: ":+1: for this")
- note.should be_upvote
+ expect(note).to be_upvote
end
it "recognizes a thumbsup emoji as a vote" do
note = build(:votable_note, note: ":thumbsup: for this")
- note.should be_upvote
+ expect(note).to be_upvote
end
it "recognizes a -1 note" do
note = create(:votable_note, note: "-1 for this")
- note.should be_downvote
+ expect(note).to be_downvote
end
it "recognizes a -1 emoji as a vote" do
note = build(:votable_note, note: ":-1: for this")
- note.should be_downvote
+ expect(note).to be_downvote
end
it "recognizes a thumbsdown emoji as a vote" do
note = build(:votable_note, note: ":thumbsdown: for this")
- note.should be_downvote
+ expect(note).to be_downvote
end
end
@@ -87,22 +87,22 @@ describe Note do
let!(:commit) { note.noteable }
it "should be accessible through #noteable" do
- note.commit_id.should == commit.id
- note.noteable.should be_a(Commit)
- note.noteable.should == commit
+ expect(note.commit_id).to eq(commit.id)
+ expect(note.noteable).to be_a(Commit)
+ expect(note.noteable).to eq(commit)
end
it "should save a valid note" do
- note.commit_id.should == commit.id
+ expect(note.commit_id).to eq(commit.id)
note.noteable == commit
end
it "should be recognized by #for_commit?" do
- note.should be_for_commit
+ expect(note).to be_for_commit
end
it "should not be votable" do
- note.should_not be_votable
+ expect(note).not_to be_votable
end
end
@@ -111,20 +111,20 @@ describe Note do
let!(:commit) { note.noteable }
it "should save a valid note" do
- note.commit_id.should == commit.id
- note.noteable.id.should == commit.id
+ expect(note.commit_id).to eq(commit.id)
+ expect(note.noteable.id).to eq(commit.id)
end
it "should be recognized by #for_diff_line?" do
- note.should be_for_diff_line
+ expect(note).to be_for_diff_line
end
it "should be recognized by #for_commit_diff_line?" do
- note.should be_for_commit_diff_line
+ expect(note).to be_for_commit_diff_line
end
it "should not be votable" do
- note.should_not be_votable
+ expect(note).not_to be_votable
end
end
@@ -132,7 +132,7 @@ describe Note do
let!(:note) { create(:note_on_issue, note: "+1 from me") }
it "should not be votable" do
- note.should be_votable
+ expect(note).to be_votable
end
end
@@ -140,7 +140,7 @@ describe Note do
let!(:note) { create(:note_on_merge_request, note: "+1 from me") }
it "should be votable" do
- note.should be_votable
+ expect(note).to be_votable
end
end
@@ -148,7 +148,7 @@ describe Note do
let!(:note) { create(:note_on_merge_request_diff, note: "+1 from me") }
it "should not be votable" do
- note.should_not be_votable
+ expect(note).not_to be_votable
end
end
@@ -161,20 +161,35 @@ describe Note do
subject { Note.create_status_change_note(thing, project, author, status, nil) }
it 'creates and saves a Note' do
- should be_a Note
- subject.id.should_not be_nil
+ is_expected.to be_a Note
+ expect(subject.id).not_to be_nil
end
- its(:noteable) { should == thing }
- its(:project) { should == thing.project }
- its(:author) { should == author }
- its(:note) { should =~ /Status changed to #{status}/ }
+ describe '#noteable' do
+ subject { super().noteable }
+ it { is_expected.to eq(thing) }
+ end
+
+ describe '#project' do
+ subject { super().project }
+ it { is_expected.to eq(thing.project) }
+ end
+
+ describe '#author' do
+ subject { super().author }
+ it { is_expected.to eq(author) }
+ end
+
+ describe '#note' do
+ subject { super().note }
+ it { is_expected.to match(/Status changed to #{status}/) }
+ end
it 'appends a back-reference if a closing mentionable is supplied' do
commit = double('commit', gfm_reference: 'commit 123456')
n = Note.create_status_change_note(thing, project, author, status, commit)
- n.note.should =~ /Status changed to #{status} by commit 123456/
+ expect(n.note).to match(/Status changed to #{status} by commit 123456/)
end
end
@@ -187,19 +202,41 @@ describe Note do
subject { Note.create_assignee_change_note(thing, project, author, assignee) }
context 'creates and saves a Note' do
- it { should be_a Note }
- its(:id) { should_not be_nil }
+ it { is_expected.to be_a Note }
+
+ describe '#id' do
+ subject { super().id }
+ it { is_expected.not_to be_nil }
+ end
+ end
+
+ describe '#noteable' do
+ subject { super().noteable }
+ it { is_expected.to eq(thing) }
end
- its(:noteable) { should == thing }
- its(:project) { should == thing.project }
- its(:author) { should == author }
- its(:note) { should =~ /Reassigned to @#{assignee.username}/ }
+ describe '#project' do
+ subject { super().project }
+ it { is_expected.to eq(thing.project) }
+ end
+
+ describe '#author' do
+ subject { super().author }
+ it { is_expected.to eq(author) }
+ end
+
+ describe '#note' do
+ subject { super().note }
+ it { is_expected.to match(/Reassigned to @#{assignee.username}/) }
+ end
context 'assignee is removed' do
let(:assignee) { nil }
- its(:note) { should =~ /Assignee removed/ }
+ describe '#note' do
+ subject { super().note }
+ it { is_expected.to match(/Assignee removed/) }
+ end
end
end
@@ -216,64 +253,144 @@ describe Note do
context 'issue from a merge request' do
subject { Note.create_cross_reference_note(issue, mergereq, author, project) }
- it { should be_valid }
- its(:noteable) { should == issue }
- its(:project) { should == issue.project }
- its(:author) { should == author }
- its(:note) { should == "_mentioned in merge request !#{mergereq.iid}_" }
+ it { is_expected.to be_valid }
+
+ describe '#noteable' do
+ subject { super().noteable }
+ it { is_expected.to eq(issue) }
+ end
+
+ describe '#project' do
+ subject { super().project }
+ it { is_expected.to eq(issue.project) }
+ end
+
+ describe '#author' do
+ subject { super().author }
+ it { is_expected.to eq(author) }
+ end
+
+ describe '#note' do
+ subject { super().note }
+ it { is_expected.to eq("_mentioned in merge request !#{mergereq.iid}_") }
+ end
end
context 'issue from a commit' do
subject { Note.create_cross_reference_note(issue, commit, author, project) }
- it { should be_valid }
- its(:noteable) { should == issue }
- its(:note) { should == "_mentioned in commit #{commit.sha}_" }
+ it { is_expected.to be_valid }
+
+ describe '#noteable' do
+ subject { super().noteable }
+ it { is_expected.to eq(issue) }
+ end
+
+ describe '#note' do
+ subject { super().note }
+ it { is_expected.to eq("_mentioned in commit #{commit.sha}_") }
+ end
end
context 'merge request from an issue' do
subject { Note.create_cross_reference_note(mergereq, issue, author, project) }
- it { should be_valid }
- its(:noteable) { should == mergereq }
- its(:project) { should == mergereq.project }
- its(:note) { should == "_mentioned in issue ##{issue.iid}_" }
+ it { is_expected.to be_valid }
+
+ describe '#noteable' do
+ subject { super().noteable }
+ it { is_expected.to eq(mergereq) }
+ end
+
+ describe '#project' do
+ subject { super().project }
+ it { is_expected.to eq(mergereq.project) }
+ end
+
+ describe '#note' do
+ subject { super().note }
+ it { is_expected.to eq("_mentioned in issue ##{issue.iid}_") }
+ end
end
context 'commit from a merge request' do
subject { Note.create_cross_reference_note(commit, mergereq, author, project) }
- it { should be_valid }
- its(:noteable) { should == commit }
- its(:project) { should == project }
- its(:note) { should == "_mentioned in merge request !#{mergereq.iid}_" }
+ it { is_expected.to be_valid }
+
+ describe '#noteable' do
+ subject { super().noteable }
+ it { is_expected.to eq(commit) }
+ end
+
+ describe '#project' do
+ subject { super().project }
+ it { is_expected.to eq(project) }
+ end
+
+ describe '#note' do
+ subject { super().note }
+ it { is_expected.to eq("_mentioned in merge request !#{mergereq.iid}_") }
+ end
end
context 'commit contained in a merge request' do
subject { Note.create_cross_reference_note(mergereq.commits.first, mergereq, author, project) }
- it { should be_nil }
+ it { is_expected.to be_nil }
end
context 'commit from issue' do
subject { Note.create_cross_reference_note(commit, issue, author, project) }
- it { should be_valid }
- its(:noteable_type) { should == "Commit" }
- its(:noteable_id) { should be_nil }
- its(:commit_id) { should == commit.id }
- its(:note) { should == "_mentioned in issue ##{issue.iid}_" }
+ it { is_expected.to be_valid }
+
+ describe '#noteable_type' do
+ subject { super().noteable_type }
+ it { is_expected.to eq("Commit") }
+ end
+
+ describe '#noteable_id' do
+ subject { super().noteable_id }
+ it { is_expected.to be_nil }
+ end
+
+ describe '#commit_id' do
+ subject { super().commit_id }
+ it { is_expected.to eq(commit.id) }
+ end
+
+ describe '#note' do
+ subject { super().note }
+ it { is_expected.to eq("_mentioned in issue ##{issue.iid}_") }
+ end
end
context 'commit from commit' do
let(:parent_commit) { commit.parents.first }
subject { Note.create_cross_reference_note(commit, parent_commit, author, project) }
- it { should be_valid }
- its(:noteable_type) { should == "Commit" }
- its(:noteable_id) { should be_nil }
- its(:commit_id) { should == commit.id }
- its(:note) { should == "_mentioned in commit #{parent_commit.id}_" }
+ it { is_expected.to be_valid }
+
+ describe '#noteable_type' do
+ subject { super().noteable_type }
+ it { is_expected.to eq("Commit") }
+ end
+
+ describe '#noteable_id' do
+ subject { super().noteable_id }
+ it { is_expected.to be_nil }
+ end
+
+ describe '#commit_id' do
+ subject { super().commit_id }
+ it { is_expected.to eq(commit.id) }
+ end
+
+ describe '#note' do
+ subject { super().note }
+ it { is_expected.to eq("_mentioned in commit #{parent_commit.id}_") }
+ end
end
end
@@ -289,11 +406,11 @@ describe Note do
end
it 'detects if a mentionable has already been mentioned' do
- Note.cross_reference_exists?(issue, commit0).should be_true
+ expect(Note.cross_reference_exists?(issue, commit0)).to be_truthy
end
it 'detects if a mentionable has not already been mentioned' do
- Note.cross_reference_exists?(issue, commit1).should be_false
+ expect(Note.cross_reference_exists?(issue, commit1)).to be_falsey
end
context 'commit on commit' do
@@ -301,8 +418,8 @@ describe Note do
Note.create_cross_reference_note(commit0, commit1, author, project)
end
- it { Note.cross_reference_exists?(commit0, commit1).should be_true }
- it { Note.cross_reference_exists?(commit1, commit0).should be_false }
+ it { expect(Note.cross_reference_exists?(commit0, commit1)).to be_truthy }
+ it { expect(Note.cross_reference_exists?(commit1, commit0)).to be_falsey }
end
end
@@ -315,22 +432,22 @@ describe Note do
it 'should recognize user-supplied notes as non-system' do
@note = create(:note_on_issue)
- @note.should_not be_system
+ expect(@note).not_to be_system
end
it 'should identify status-change notes as system notes' do
@note = Note.create_status_change_note(issue, project, author, 'closed', nil)
- @note.should be_system
+ expect(@note).to be_system
end
it 'should identify cross-reference notes as system notes' do
@note = Note.create_cross_reference_note(issue, other, author, project)
- @note.should be_system
+ expect(@note).to be_system
end
it 'should identify assignee-change notes as system notes' do
@note = Note.create_assignee_change_note(issue, project, author, assignee)
- @note.should be_system
+ expect(@note).to be_system
end
end
@@ -351,9 +468,9 @@ describe Note do
@p2.project_members.create(user: @u3, access_level: ProjectMember::GUEST)
end
- it { @abilities.allowed?(@u1, :read_note, @p1).should be_false }
- it { @abilities.allowed?(@u2, :read_note, @p1).should be_true }
- it { @abilities.allowed?(@u3, :read_note, @p1).should be_false }
+ it { expect(@abilities.allowed?(@u1, :read_note, @p1)).to be_falsey }
+ it { expect(@abilities.allowed?(@u2, :read_note, @p1)).to be_truthy }
+ it { expect(@abilities.allowed?(@u3, :read_note, @p1)).to be_falsey }
end
describe :write do
@@ -362,9 +479,9 @@ describe Note do
@p2.project_members.create(user: @u3, access_level: ProjectMember::DEVELOPER)
end
- it { @abilities.allowed?(@u1, :write_note, @p1).should be_false }
- it { @abilities.allowed?(@u2, :write_note, @p1).should be_true }
- it { @abilities.allowed?(@u3, :write_note, @p1).should be_false }
+ it { expect(@abilities.allowed?(@u1, :write_note, @p1)).to be_falsey }
+ it { expect(@abilities.allowed?(@u2, :write_note, @p1)).to be_truthy }
+ it { expect(@abilities.allowed?(@u3, :write_note, @p1)).to be_falsey }
end
describe :admin do
@@ -374,9 +491,9 @@ describe Note do
@p2.project_members.create(user: @u3, access_level: ProjectMember::MASTER)
end
- it { @abilities.allowed?(@u1, :admin_note, @p1).should be_false }
- it { @abilities.allowed?(@u2, :admin_note, @p1).should be_true }
- it { @abilities.allowed?(@u3, :admin_note, @p1).should be_false }
+ it { expect(@abilities.allowed?(@u1, :admin_note, @p1)).to be_falsey }
+ it { expect(@abilities.allowed?(@u2, :admin_note, @p1)).to be_truthy }
+ it { expect(@abilities.allowed?(@u3, :admin_note, @p1)).to be_falsey }
end
end
diff --git a/spec/models/project_security_spec.rb b/spec/models/project_security_spec.rb
index 5c8d1e7438b..1ee19003543 100644
--- a/spec/models/project_security_spec.rb
+++ b/spec/models/project_security_spec.rb
@@ -23,7 +23,7 @@ describe Project do
describe "Non member rules" do
it "should deny for non-project users any actions" do
admin_actions.each do |action|
- @abilities.allowed?(@u1, action, @p1).should be_false
+ expect(@abilities.allowed?(@u1, action, @p1)).to be_falsey
end
end
end
@@ -35,7 +35,7 @@ describe Project do
it "should allow for project user any guest actions" do
guest_actions.each do |action|
- @abilities.allowed?(@u2, action, @p1).should be_true
+ expect(@abilities.allowed?(@u2, action, @p1)).to be_truthy
end
end
end
@@ -47,7 +47,7 @@ describe Project do
it "should allow for project user any report actions" do
report_actions.each do |action|
- @abilities.allowed?(@u2, action, @p1).should be_true
+ expect(@abilities.allowed?(@u2, action, @p1)).to be_truthy
end
end
end
@@ -60,13 +60,13 @@ describe Project do
it "should deny for developer master-specific actions" do
[dev_actions - report_actions].each do |action|
- @abilities.allowed?(@u2, action, @p1).should be_false
+ expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey
end
end
it "should allow for project user any dev actions" do
dev_actions.each do |action|
- @abilities.allowed?(@u3, action, @p1).should be_true
+ expect(@abilities.allowed?(@u3, action, @p1)).to be_truthy
end
end
end
@@ -79,13 +79,13 @@ describe Project do
it "should deny for developer master-specific actions" do
[master_actions - dev_actions].each do |action|
- @abilities.allowed?(@u2, action, @p1).should be_false
+ expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey
end
end
it "should allow for project user any master actions" do
master_actions.each do |action|
- @abilities.allowed?(@u3, action, @p1).should be_true
+ expect(@abilities.allowed?(@u3, action, @p1)).to be_truthy
end
end
end
@@ -98,13 +98,13 @@ describe Project do
it "should deny for masters admin-specific actions" do
[admin_actions - master_actions].each do |action|
- @abilities.allowed?(@u2, action, @p1).should be_false
+ expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey
end
end
it "should allow for project owner any admin actions" do
admin_actions.each do |action|
- @abilities.allowed?(@u4, action, @p1).should be_true
+ expect(@abilities.allowed?(@u4, action, @p1)).to be_truthy
end
end
end
diff --git a/spec/models/project_services/assembla_service_spec.rb b/spec/models/project_services/assembla_service_spec.rb
index 005dd41fea9..ee7f780c8f6 100644
--- a/spec/models/project_services/assembla_service_spec.rb
+++ b/spec/models/project_services/assembla_service_spec.rb
@@ -16,8 +16,8 @@ require 'spec_helper'
describe AssemblaService, models: true do
describe "Associations" do
- it { should belong_to :project }
- it { should have_one :service_hook }
+ it { is_expected.to belong_to :project }
+ it { is_expected.to have_one :service_hook }
end
describe "Execute" do
@@ -40,7 +40,7 @@ describe AssemblaService, models: true do
it "should call Assembla API" do
@assembla_service.execute(@sample_data)
- WebMock.should have_requested(:post, @api_url).with(
+ expect(WebMock).to have_requested(:post, @api_url).with(
body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/
).once
end
diff --git a/spec/models/project_services/buildbox_service_spec.rb b/spec/models/project_services/buildbox_service_spec.rb
index 1d9ca51be16..050363e14c7 100644
--- a/spec/models/project_services/buildbox_service_spec.rb
+++ b/spec/models/project_services/buildbox_service_spec.rb
@@ -16,8 +16,8 @@ require 'spec_helper'
describe BuildboxService do
describe 'Associations' do
- it { should belong_to :project }
- it { should have_one :service_hook }
+ it { is_expected.to belong_to :project }
+ it { is_expected.to have_one :service_hook }
end
describe 'commits methods' do
@@ -38,35 +38,39 @@ describe BuildboxService do
describe :webhook_url do
it 'returns the webhook url' do
- @service.webhook_url.should ==
+ expect(@service.webhook_url).to eq(
'https://webhook.buildbox.io/deliver/secret-sauce-webhook-token'
+ )
end
end
describe :commit_status_path do
it 'returns the correct status page' do
- @service.commit_status_path('2ab7834c').should ==
+ expect(@service.commit_status_path('2ab7834c')).to eq(
'https://gitlab.buildbox.io/status/secret-sauce-status-token.json?commit=2ab7834c'
+ )
end
end
describe :build_page do
it 'returns the correct build page' do
- @service.build_page('2ab7834c').should ==
+ expect(@service.build_page('2ab7834c')).to eq(
'https://buildbox.io/account-name/example-project/builds?commit=2ab7834c'
+ )
end
end
describe :builds_page do
it 'returns the correct path to the builds page' do
- @service.builds_path.should ==
+ expect(@service.builds_path).to eq(
'https://buildbox.io/account-name/example-project/builds?branch=default-brancho'
+ )
end
end
describe :status_img_path do
it 'returns the correct path to the status image' do
- @service.status_img_path.should == 'https://badge.buildbox.io/secret-sauce-status-token.svg'
+ expect(@service.status_img_path).to eq('https://badge.buildbox.io/secret-sauce-status-token.svg')
end
end
end
diff --git a/spec/models/project_services/flowdock_service_spec.rb b/spec/models/project_services/flowdock_service_spec.rb
index ac156719b43..b34e36bc940 100644
--- a/spec/models/project_services/flowdock_service_spec.rb
+++ b/spec/models/project_services/flowdock_service_spec.rb
@@ -16,8 +16,8 @@ require 'spec_helper'
describe FlowdockService do
describe "Associations" do
- it { should belong_to :project }
- it { should have_one :service_hook }
+ it { is_expected.to belong_to :project }
+ it { is_expected.to have_one :service_hook }
end
describe "Execute" do
@@ -39,7 +39,7 @@ describe FlowdockService do
it "should call FlowDock API" do
@flowdock_service.execute(@sample_data)
- WebMock.should have_requested(:post, @api_url).with(
+ expect(WebMock).to have_requested(:post, @api_url).with(
body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/
).once
end
diff --git a/spec/models/project_services/gemnasium_service_spec.rb b/spec/models/project_services/gemnasium_service_spec.rb
index 2c560c11dac..fe5d62b2f53 100644
--- a/spec/models/project_services/gemnasium_service_spec.rb
+++ b/spec/models/project_services/gemnasium_service_spec.rb
@@ -16,8 +16,8 @@ require 'spec_helper'
describe GemnasiumService do
describe "Associations" do
- it { should belong_to :project }
- it { should have_one :service_hook }
+ it { is_expected.to belong_to :project }
+ it { is_expected.to have_one :service_hook }
end
describe "Execute" do
@@ -36,7 +36,7 @@ describe GemnasiumService do
@sample_data = Gitlab::PushDataBuilder.build_sample(project, user)
end
it "should call Gemnasium service" do
- Gemnasium::GitlabService.should_receive(:execute).with(an_instance_of(Hash)).once
+ expect(Gemnasium::GitlabService).to receive(:execute).with(an_instance_of(Hash)).once
@gemnasium_service.execute(@sample_data)
end
end
diff --git a/spec/models/project_services/gitlab_ci_service_spec.rb b/spec/models/project_services/gitlab_ci_service_spec.rb
index 83277058fbb..0cd255f08ea 100644
--- a/spec/models/project_services/gitlab_ci_service_spec.rb
+++ b/spec/models/project_services/gitlab_ci_service_spec.rb
@@ -16,8 +16,8 @@ require 'spec_helper'
describe GitlabCiService do
describe "Associations" do
- it { should belong_to :project }
- it { should have_one :service_hook }
+ it { is_expected.to belong_to :project }
+ it { is_expected.to have_one :service_hook }
end
describe "Mass assignment" do
@@ -34,11 +34,11 @@ describe GitlabCiService do
end
describe :commit_status_path do
- it { @service.commit_status_path("2ab7834c").should == "http://ci.gitlab.org/projects/2/commits/2ab7834c/status.json?token=verySecret"}
+ it { expect(@service.commit_status_path("2ab7834c")).to eq("http://ci.gitlab.org/projects/2/commits/2ab7834c/status.json?token=verySecret")}
end
describe :build_page do
- it { @service.build_page("2ab7834c").should == "http://ci.gitlab.org/projects/2/commits/2ab7834c"}
+ it { expect(@service.build_page("2ab7834c")).to eq("http://ci.gitlab.org/projects/2/commits/2ab7834c")}
end
end
end
diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb
index 99ca04eff6e..6ef4d036c3f 100644
--- a/spec/models/project_services/jira_service_spec.rb
+++ b/spec/models/project_services/jira_service_spec.rb
@@ -16,8 +16,8 @@ require 'spec_helper'
describe JiraService do
describe "Associations" do
- it { should belong_to :project }
- it { should have_one :service_hook }
+ it { is_expected.to belong_to :project }
+ it { is_expected.to have_one :service_hook }
end
describe "Validations" do
@@ -26,9 +26,9 @@ describe JiraService do
subject.active = true
end
- it { should validate_presence_of :project_url }
- it { should validate_presence_of :issues_url }
- it { should validate_presence_of :new_issue_url }
+ it { is_expected.to validate_presence_of :project_url }
+ it { is_expected.to validate_presence_of :issues_url }
+ it { is_expected.to validate_presence_of :new_issue_url }
end
end
@@ -79,7 +79,7 @@ describe JiraService do
"new_issue_url" => "http://jira.sample/projects/project_a/issues/new"
}
}
- Gitlab.config.stub(:issues_tracker).and_return(settings)
+ allow(Gitlab.config).to receive(:issues_tracker).and_return(settings)
@service = project.create_jira_service(active: true)
end
diff --git a/spec/models/project_services/pushover_service_spec.rb b/spec/models/project_services/pushover_service_spec.rb
index f2813d66c7d..188626a7a27 100644
--- a/spec/models/project_services/pushover_service_spec.rb
+++ b/spec/models/project_services/pushover_service_spec.rb
@@ -16,8 +16,8 @@ require 'spec_helper'
describe PushoverService do
describe 'Associations' do
- it { should belong_to :project }
- it { should have_one :service_hook }
+ it { is_expected.to belong_to :project }
+ it { is_expected.to have_one :service_hook }
end
describe 'Validations' do
@@ -26,9 +26,9 @@ describe PushoverService do
subject.active = true
end
- it { should validate_presence_of :api_key }
- it { should validate_presence_of :user_key }
- it { should validate_presence_of :priority }
+ it { is_expected.to validate_presence_of :api_key }
+ it { is_expected.to validate_presence_of :user_key }
+ it { is_expected.to validate_presence_of :priority }
end
end
@@ -63,7 +63,7 @@ describe PushoverService do
it 'should call Pushover API' do
pushover.execute(sample_data)
- WebMock.should have_requested(:post, api_url).once
+ expect(WebMock).to have_requested(:post, api_url).once
end
end
end
diff --git a/spec/models/project_services/slack_message_spec.rb b/spec/models/project_services/slack_message_spec.rb
index c530fad619b..7197a94e53f 100644
--- a/spec/models/project_services/slack_message_spec.rb
+++ b/spec/models/project_services/slack_message_spec.rb
@@ -25,16 +25,17 @@ describe SlackMessage do
end
it 'returns a message regarding pushes' do
- subject.pretext.should ==
+ expect(subject.pretext).to eq(
'user_name pushed to branch <url/commits/master|master> of '\
'<url|project_name> (<url/compare/before...after|Compare changes>)'
- subject.attachments.should == [
+ )
+ expect(subject.attachments).to eq([
{
text: "<url1|abcdefghi>: message1 - author1\n"\
"<url2|123456789>: message2 - author2",
color: color,
}
- ]
+ ])
end
end
@@ -44,10 +45,11 @@ describe SlackMessage do
end
it 'returns a message regarding a new branch' do
- subject.pretext.should ==
+ expect(subject.pretext).to eq(
'user_name pushed new branch <url/commits/master|master> to '\
'<url|project_name>'
- subject.attachments.should be_empty
+ )
+ expect(subject.attachments).to be_empty
end
end
@@ -57,9 +59,10 @@ describe SlackMessage do
end
it 'returns a message regarding a removed branch' do
- subject.pretext.should ==
+ expect(subject.pretext).to eq(
'user_name removed branch master from <url|project_name>'
- subject.attachments.should be_empty
+ )
+ expect(subject.attachments).to be_empty
end
end
end
diff --git a/spec/models/project_services/slack_service_spec.rb b/spec/models/project_services/slack_service_spec.rb
index 34594072409..90b385423f1 100644
--- a/spec/models/project_services/slack_service_spec.rb
+++ b/spec/models/project_services/slack_service_spec.rb
@@ -16,8 +16,8 @@ require 'spec_helper'
describe SlackService do
describe "Associations" do
- it { should belong_to :project }
- it { should have_one :service_hook }
+ it { is_expected.to belong_to :project }
+ it { is_expected.to have_one :service_hook }
end
describe "Validations" do
@@ -26,7 +26,7 @@ describe SlackService do
subject.active = true
end
- it { should validate_presence_of :webhook }
+ it { is_expected.to validate_presence_of :webhook }
end
end
@@ -51,7 +51,7 @@ describe SlackService do
it "should call Slack API" do
slack.execute(sample_data)
- WebMock.should have_requested(:post, webhook_url).once
+ expect(WebMock).to have_requested(:post, webhook_url).once
end
end
end
diff --git a/spec/models/project_snippet_spec.rb b/spec/models/project_snippet_spec.rb
index a6e1d9eef50..3e8f106d27f 100644
--- a/spec/models/project_snippet_spec.rb
+++ b/spec/models/project_snippet_spec.rb
@@ -19,13 +19,13 @@ require 'spec_helper'
describe ProjectSnippet do
describe "Associations" do
- it { should belong_to(:project) }
+ it { is_expected.to belong_to(:project) }
end
describe "Mass assignment" do
end
describe "Validation" do
- it { should validate_presence_of(:project) }
+ it { is_expected.to validate_presence_of(:project) }
end
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index e2197420018..ad7a0f0a1e3 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -33,25 +33,25 @@ require 'spec_helper'
describe Project do
describe 'Associations' do
- it { should belong_to(:group) }
- it { should belong_to(:namespace) }
- it { should belong_to(:creator).class_name('User') }
- it { should have_many(:users) }
- it { should have_many(:events).dependent(:destroy) }
- it { should have_many(:merge_requests).dependent(:destroy) }
- it { should have_many(:issues).dependent(:destroy) }
- it { should have_many(:milestones).dependent(:destroy) }
- it { should have_many(:project_members).dependent(:destroy) }
- it { should have_many(:notes).dependent(:destroy) }
- it { should have_many(:snippets).class_name('ProjectSnippet').dependent(:destroy) }
- it { should have_many(:deploy_keys_projects).dependent(:destroy) }
- it { should have_many(:deploy_keys) }
- it { should have_many(:hooks).dependent(:destroy) }
- it { should have_many(:protected_branches).dependent(:destroy) }
- it { should have_one(:forked_project_link).dependent(:destroy) }
- it { should have_one(:slack_service).dependent(:destroy) }
- it { should have_one(:pushover_service).dependent(:destroy) }
- it { should have_one(:asana_service).dependent(:destroy) }
+ it { is_expected.to belong_to(:group) }
+ it { is_expected.to belong_to(:namespace) }
+ it { is_expected.to belong_to(:creator).class_name('User') }
+ it { is_expected.to have_many(:users) }
+ it { is_expected.to have_many(:events).dependent(:destroy) }
+ it { is_expected.to have_many(:merge_requests).dependent(:destroy) }
+ it { is_expected.to have_many(:issues).dependent(:destroy) }
+ it { is_expected.to have_many(:milestones).dependent(:destroy) }
+ it { is_expected.to have_many(:project_members).dependent(:destroy) }
+ it { is_expected.to have_many(:notes).dependent(:destroy) }
+ it { is_expected.to have_many(:snippets).class_name('ProjectSnippet').dependent(:destroy) }
+ it { is_expected.to have_many(:deploy_keys_projects).dependent(:destroy) }
+ it { is_expected.to have_many(:deploy_keys) }
+ it { is_expected.to have_many(:hooks).dependent(:destroy) }
+ it { is_expected.to have_many(:protected_branches).dependent(:destroy) }
+ it { is_expected.to have_one(:forked_project_link).dependent(:destroy) }
+ it { is_expected.to have_one(:slack_service).dependent(:destroy) }
+ it { is_expected.to have_one(:pushover_service).dependent(:destroy) }
+ it { is_expected.to have_one(:asana_service).dependent(:destroy) }
end
describe 'Mass assignment' do
@@ -60,50 +60,50 @@ describe Project do
describe 'Validation' do
let!(:project) { create(:project) }
- it { should validate_presence_of(:name) }
- it { should validate_uniqueness_of(:name).scoped_to(:namespace_id) }
- it { should ensure_length_of(:name).is_within(0..255) }
+ it { is_expected.to validate_presence_of(:name) }
+ it { is_expected.to validate_uniqueness_of(:name).scoped_to(:namespace_id) }
+ it { is_expected.to ensure_length_of(:name).is_within(0..255) }
- it { should validate_presence_of(:path) }
- it { should validate_uniqueness_of(:path).scoped_to(:namespace_id) }
- it { should ensure_length_of(:path).is_within(0..255) }
- it { should ensure_length_of(:description).is_within(0..2000) }
- it { should validate_presence_of(:creator) }
- it { should ensure_length_of(:issues_tracker_id).is_within(0..255) }
- it { should validate_presence_of(:namespace) }
+ it { is_expected.to validate_presence_of(:path) }
+ it { is_expected.to validate_uniqueness_of(:path).scoped_to(:namespace_id) }
+ it { is_expected.to ensure_length_of(:path).is_within(0..255) }
+ it { is_expected.to ensure_length_of(:description).is_within(0..2000) }
+ it { is_expected.to validate_presence_of(:creator) }
+ it { is_expected.to ensure_length_of(:issues_tracker_id).is_within(0..255) }
+ it { is_expected.to validate_presence_of(:namespace) }
it 'should not allow new projects beyond user limits' do
project2 = build(:project)
- project2.stub(:creator).and_return(double(can_create_project?: false, projects_limit: 0).as_null_object)
- project2.should_not be_valid
- project2.errors[:limit_reached].first.should match(/Your project limit is 0/)
+ allow(project2).to receive(:creator).and_return(double(can_create_project?: false, projects_limit: 0).as_null_object)
+ expect(project2).not_to be_valid
+ expect(project2.errors[:limit_reached].first).to match(/Your project limit is 0/)
end
end
describe 'Respond to' do
- it { should respond_to(:url_to_repo) }
- it { should respond_to(:repo_exists?) }
- it { should respond_to(:satellite) }
- it { should respond_to(:update_merge_requests) }
- it { should respond_to(:execute_hooks) }
- it { should respond_to(:name_with_namespace) }
- it { should respond_to(:owner) }
- it { should respond_to(:path_with_namespace) }
+ it { is_expected.to respond_to(:url_to_repo) }
+ it { is_expected.to respond_to(:repo_exists?) }
+ it { is_expected.to respond_to(:satellite) }
+ it { is_expected.to respond_to(:update_merge_requests) }
+ it { is_expected.to respond_to(:execute_hooks) }
+ it { is_expected.to respond_to(:name_with_namespace) }
+ it { is_expected.to respond_to(:owner) }
+ it { is_expected.to respond_to(:path_with_namespace) }
end
it 'should return valid url to repo' do
project = Project.new(path: 'somewhere')
- project.url_to_repo.should == Gitlab.config.gitlab_shell.ssh_path_prefix + 'somewhere.git'
+ expect(project.url_to_repo).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + 'somewhere.git')
end
it 'returns the full web URL for this repo' do
project = Project.new(path: 'somewhere')
- project.web_url.should == "#{Gitlab.config.gitlab.url}/somewhere"
+ expect(project.web_url).to eq("#{Gitlab.config.gitlab.url}/somewhere")
end
it 'returns the web URL without the protocol for this repo' do
project = Project.new(path: 'somewhere')
- project.web_url_without_protocol.should == "#{Gitlab.config.gitlab.url.split('://')[1]}/somewhere"
+ expect(project.web_url_without_protocol).to eq("#{Gitlab.config.gitlab.url.split('://')[1]}/somewhere")
end
describe 'last_activity methods' do
@@ -113,18 +113,18 @@ describe Project do
describe 'last_activity' do
it 'should alias last_activity to last_event' do
project.stub(last_event: last_event)
- project.last_activity.should == last_event
+ expect(project.last_activity).to eq(last_event)
end
end
describe 'last_activity_date' do
it 'returns the creation date of the project\'s last event if present' do
last_activity_event = create(:event, project: project)
- project.last_activity_at.to_i.should == last_event.created_at.to_i
+ expect(project.last_activity_at.to_i).to eq(last_event.created_at.to_i)
end
it 'returns the project\'s last update date if it has no events' do
- project.last_activity_date.should == project.updated_at
+ expect(project.last_activity_date).to eq(project.updated_at)
end
end
end
@@ -139,13 +139,13 @@ describe Project do
it 'should close merge request if last commit from source branch was pushed to target branch' do
project.update_merge_requests(prev_commit_id, commit_id, "refs/heads/#{merge_request.target_branch}", key.user)
merge_request.reload
- merge_request.merged?.should be_true
+ expect(merge_request.merged?).to be_truthy
end
it 'should update merge request commits with new one if pushed to source branch' do
project.update_merge_requests(prev_commit_id, commit_id, "refs/heads/#{merge_request.source_branch}", key.user)
merge_request.reload
- merge_request.last_commit.id.should == commit_id
+ expect(merge_request.last_commit.id).to eq(commit_id)
end
end
@@ -156,8 +156,8 @@ describe Project do
@project = create(:project, name: 'gitlabhq', namespace: @group)
end
- it { Project.find_with_namespace('gitlab/gitlabhq').should == @project }
- it { Project.find_with_namespace('gitlab-ci').should be_nil }
+ it { expect(Project.find_with_namespace('gitlab/gitlabhq')).to eq(@project) }
+ it { expect(Project.find_with_namespace('gitlab-ci')).to be_nil }
end
end
@@ -168,7 +168,7 @@ describe Project do
@project = create(:project, name: 'gitlabhq', namespace: @group)
end
- it { @project.to_param.should == 'gitlab/gitlabhq' }
+ it { expect(@project.to_param).to eq('gitlab/gitlabhq') }
end
end
@@ -176,7 +176,7 @@ describe Project do
let(:project) { create(:project) }
it 'should return valid repo' do
- project.repository.should be_kind_of(Repository)
+ expect(project.repository).to be_kind_of(Repository)
end
end
@@ -187,15 +187,15 @@ describe Project do
let(:ext_project) { create(:redmine_project) }
it 'should be true or if used internal tracker and issue exists' do
- project.issue_exists?(existed_issue.iid).should be_true
+ expect(project.issue_exists?(existed_issue.iid)).to be_truthy
end
it 'should be false or if used internal tracker and issue not exists' do
- project.issue_exists?(not_existed_issue.iid).should be_false
+ expect(project.issue_exists?(not_existed_issue.iid)).to be_falsey
end
it 'should always be true if used other tracker' do
- ext_project.issue_exists?(rand(100)).should be_true
+ expect(ext_project.issue_exists?(rand(100))).to be_truthy
end
end
@@ -204,11 +204,11 @@ describe Project do
let(:ext_project) { create(:redmine_project) }
it "should be true if used internal tracker" do
- project.default_issues_tracker?.should be_true
+ expect(project.default_issues_tracker?).to be_truthy
end
it "should be false if used other tracker" do
- ext_project.default_issues_tracker?.should be_false
+ expect(ext_project.default_issues_tracker?).to be_falsey
end
end
@@ -217,19 +217,19 @@ describe Project do
let(:ext_project) { create(:redmine_project) }
it 'should be true for projects with external issues tracker if issues enabled' do
- ext_project.can_have_issues_tracker_id?.should be_true
+ expect(ext_project.can_have_issues_tracker_id?).to be_truthy
end
it 'should be false for projects with internal issue tracker if issues enabled' do
- project.can_have_issues_tracker_id?.should be_false
+ expect(project.can_have_issues_tracker_id?).to be_falsey
end
it 'should be always false if issues disabled' do
project.issues_enabled = false
ext_project.issues_enabled = false
- project.can_have_issues_tracker_id?.should be_false
- ext_project.can_have_issues_tracker_id?.should be_false
+ expect(project.can_have_issues_tracker_id?).to be_falsey
+ expect(ext_project.can_have_issues_tracker_id?).to be_falsey
end
end
@@ -240,8 +240,8 @@ describe Project do
project.protected_branches.create(name: 'master')
end
- it { project.open_branches.map(&:name).should include('feature') }
- it { project.open_branches.map(&:name).should_not include('master') }
+ it { expect(project.open_branches.map(&:name)).to include('feature') }
+ it { expect(project.open_branches.map(&:name)).not_to include('master') }
end
describe '#star_count' do
@@ -318,12 +318,12 @@ describe Project do
it 'should be true if avatar is image' do
project.update_attribute(:avatar, 'uploads/avatar.png')
- project.avatar_type.should be_true
+ expect(project.avatar_type).to be_truthy
end
it 'should be false if avatar is html page' do
project.update_attribute(:avatar, 'uploads/avatar.html')
- project.avatar_type.should == ['only images allowed']
+ expect(project.avatar_type).to eq(['only images allowed'])
end
end
end
diff --git a/spec/models/project_team_spec.rb b/spec/models/project_team_spec.rb
index bbf50b654f4..19201cc15a7 100644
--- a/spec/models/project_team_spec.rb
+++ b/spec/models/project_team_spec.rb
@@ -16,19 +16,19 @@ describe ProjectTeam do
end
describe 'members collection' do
- it { project.team.masters.should include(master) }
- it { project.team.masters.should_not include(guest) }
- it { project.team.masters.should_not include(reporter) }
- it { project.team.masters.should_not include(nonmember) }
+ it { expect(project.team.masters).to include(master) }
+ it { expect(project.team.masters).not_to include(guest) }
+ it { expect(project.team.masters).not_to include(reporter) }
+ it { expect(project.team.masters).not_to include(nonmember) }
end
describe 'access methods' do
- it { project.team.master?(master).should be_true }
- it { project.team.master?(guest).should be_false }
- it { project.team.master?(reporter).should be_false }
- it { project.team.master?(nonmember).should be_false }
- it { project.team.member?(nonmember).should be_false }
- it { project.team.member?(guest).should be_true }
+ it { expect(project.team.master?(master)).to be_truthy }
+ it { expect(project.team.master?(guest)).to be_falsey }
+ it { expect(project.team.master?(reporter)).to be_falsey }
+ it { expect(project.team.master?(nonmember)).to be_falsey }
+ it { expect(project.team.member?(nonmember)).to be_falsey }
+ it { expect(project.team.member?(guest)).to be_truthy }
end
end
@@ -49,21 +49,21 @@ describe ProjectTeam do
end
describe 'members collection' do
- it { project.team.reporters.should include(reporter) }
- it { project.team.masters.should include(master) }
- it { project.team.masters.should include(guest) }
- it { project.team.masters.should_not include(reporter) }
- it { project.team.masters.should_not include(nonmember) }
+ it { expect(project.team.reporters).to include(reporter) }
+ it { expect(project.team.masters).to include(master) }
+ it { expect(project.team.masters).to include(guest) }
+ it { expect(project.team.masters).not_to include(reporter) }
+ it { expect(project.team.masters).not_to include(nonmember) }
end
describe 'access methods' do
- it { project.team.reporter?(reporter).should be_true }
- it { project.team.master?(master).should be_true }
- it { project.team.master?(guest).should be_true }
- it { project.team.master?(reporter).should be_false }
- it { project.team.master?(nonmember).should be_false }
- it { project.team.member?(nonmember).should be_false }
- it { project.team.member?(guest).should be_true }
+ it { expect(project.team.reporter?(reporter)).to be_truthy }
+ it { expect(project.team.master?(master)).to be_truthy }
+ it { expect(project.team.master?(guest)).to be_truthy }
+ it { expect(project.team.master?(reporter)).to be_falsey }
+ it { expect(project.team.master?(nonmember)).to be_falsey }
+ it { expect(project.team.member?(nonmember)).to be_falsey }
+ it { expect(project.team.member?(guest)).to be_truthy }
end
end
end
diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb
index e4ee2fc5b13..2acdb7dfddc 100644
--- a/spec/models/project_wiki_spec.rb
+++ b/spec/models/project_wiki_spec.rb
@@ -12,19 +12,19 @@ describe ProjectWiki do
describe "#path_with_namespace" do
it "returns the project path with namespace with the .wiki extension" do
- subject.path_with_namespace.should == project.path_with_namespace + ".wiki"
+ expect(subject.path_with_namespace).to eq(project.path_with_namespace + ".wiki")
end
end
describe "#url_to_repo" do
it "returns the correct ssh url to the repo" do
- subject.url_to_repo.should == gitlab_shell.url_to_repo(subject.path_with_namespace)
+ expect(subject.url_to_repo).to eq(gitlab_shell.url_to_repo(subject.path_with_namespace))
end
end
describe "#ssh_url_to_repo" do
it "equals #url_to_repo" do
- subject.ssh_url_to_repo.should == subject.url_to_repo
+ expect(subject.ssh_url_to_repo).to eq(subject.url_to_repo)
end
end
@@ -32,21 +32,21 @@ describe ProjectWiki do
it "provides the full http url to the repo" do
gitlab_url = Gitlab.config.gitlab.url
repo_http_url = "#{gitlab_url}/#{subject.path_with_namespace}.git"
- subject.http_url_to_repo.should == repo_http_url
+ expect(subject.http_url_to_repo).to eq(repo_http_url)
end
end
describe "#wiki" do
it "contains a Gollum::Wiki instance" do
- subject.wiki.should be_a Gollum::Wiki
+ expect(subject.wiki).to be_a Gollum::Wiki
end
it "creates a new wiki repo if one does not yet exist" do
- project_wiki.create_page("index", "test content").should be_true
+ expect(project_wiki.create_page("index", "test content")).to be_truthy
end
it "raises CouldNotCreateWikiError if it can't create the wiki repository" do
- project_wiki.stub(:init_repo).and_return(false)
+ allow(project_wiki).to receive(:init_repo).and_return(false)
expect { project_wiki.send(:create_repo!) }.to raise_exception(ProjectWiki::CouldNotCreateWikiError)
end
end
@@ -54,21 +54,27 @@ describe ProjectWiki do
describe "#empty?" do
context "when the wiki repository is empty" do
before do
- Gitlab::Shell.any_instance.stub(:add_repository) do
+ allow_any_instance_of(Gitlab::Shell).to receive(:add_repository) do
create_temp_repo("#{Rails.root}/tmp/test-git-base-path/non-existant.wiki.git")
end
- project.stub(:path_with_namespace).and_return("non-existant")
+ allow(project).to receive(:path_with_namespace).and_return("non-existant")
end
- its(:empty?) { should be_true }
+ describe '#empty?' do
+ subject { super().empty? }
+ it { is_expected.to be_truthy }
+ end
end
context "when the wiki has pages" do
before do
- create_page("index", "This is an awesome new Gollum Wiki")
+ project_wiki.create_page("index", "This is an awesome new Gollum Wiki")
end
- its(:empty?) { should be_false }
+ describe '#empty?' do
+ subject { super().empty? }
+ it { is_expected.to be_falsey }
+ end
end
end
@@ -83,11 +89,11 @@ describe ProjectWiki do
end
it "returns an array of WikiPage instances" do
- @pages.first.should be_a WikiPage
+ expect(@pages.first).to be_a WikiPage
end
it "returns the correct number of pages" do
- @pages.count.should == 1
+ expect(@pages.count).to eq(1)
end
end
@@ -102,55 +108,55 @@ describe ProjectWiki do
it "returns the latest version of the page if it exists" do
page = subject.find_page("index page")
- page.title.should == "index page"
+ expect(page.title).to eq("index page")
end
it "returns nil if the page does not exist" do
- subject.find_page("non-existant").should == nil
+ expect(subject.find_page("non-existant")).to eq(nil)
end
it "can find a page by slug" do
page = subject.find_page("index-page")
- page.title.should == "index page"
+ expect(page.title).to eq("index page")
end
it "returns a WikiPage instance" do
page = subject.find_page("index page")
- page.should be_a WikiPage
+ expect(page).to be_a WikiPage
end
end
describe '#find_file' do
before do
file = Gollum::File.new(subject.wiki)
- Gollum::Wiki.any_instance.
- stub(:file).with('image.jpg', 'master', true).
+ allow_any_instance_of(Gollum::Wiki).
+ to receive(:file).with('image.jpg', 'master', true).
and_return(file)
- Gollum::File.any_instance.
- stub(:mime_type).
+ allow_any_instance_of(Gollum::File).
+ to receive(:mime_type).
and_return('image/jpeg')
- Gollum::Wiki.any_instance.
- stub(:file).with('non-existant', 'master', true).
+ allow_any_instance_of(Gollum::Wiki).
+ to receive(:file).with('non-existant', 'master', true).
and_return(nil)
end
after do
- Gollum::Wiki.any_instance.unstub(:file)
- Gollum::File.any_instance.unstub(:mime_type)
+ allow_any_instance_of(Gollum::Wiki).to receive(:file).and_call_original
+ allow_any_instance_of(Gollum::File).to receive(:mime_type).and_call_original
end
it 'returns the latest version of the file if it exists' do
file = subject.find_file('image.jpg')
- file.mime_type.should == 'image/jpeg'
+ expect(file.mime_type).to eq('image/jpeg')
end
it 'returns nil if the page does not exist' do
- subject.find_file('non-existant').should == nil
+ expect(subject.find_file('non-existant')).to eq(nil)
end
it 'returns a Gollum::File instance' do
file = subject.find_file('image.jpg')
- file.should be_a Gollum::File
+ expect(file).to be_a Gollum::File
end
end
@@ -160,23 +166,23 @@ describe ProjectWiki do
end
it "creates a new wiki page" do
- subject.create_page("test page", "this is content").should_not == false
- subject.pages.count.should == 1
+ expect(subject.create_page("test page", "this is content")).not_to eq(false)
+ expect(subject.pages.count).to eq(1)
end
it "returns false when a duplicate page exists" do
subject.create_page("test page", "content")
- subject.create_page("test page", "content").should == false
+ expect(subject.create_page("test page", "content")).to eq(false)
end
it "stores an error message when a duplicate page exists" do
2.times { subject.create_page("test page", "content") }
- subject.error_message.should =~ /Duplicate page:/
+ expect(subject.error_message).to match(/Duplicate page:/)
end
it "sets the correct commit message" do
subject.create_page("test page", "some content", :markdown, "commit message")
- subject.pages.first.page.version.message.should == "commit message"
+ expect(subject.pages.first.page.version.message).to eq("commit message")
end
end
@@ -193,11 +199,11 @@ describe ProjectWiki do
end
it "updates the content of the page" do
- @page.raw_data.should == "some other content"
+ expect(@page.raw_data).to eq("some other content")
end
it "sets the correct commit message" do
- @page.version.message.should == "updated page"
+ expect(@page.version.message).to eq("updated page")
end
end
@@ -209,7 +215,7 @@ describe ProjectWiki do
it "deletes the page" do
subject.delete_page(@page)
- subject.pages.count.should == 0
+ expect(subject.pages.count).to eq(0)
end
end
diff --git a/spec/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb
index b0f57e8a206..1e6937b536c 100644
--- a/spec/models/protected_branch_spec.rb
+++ b/spec/models/protected_branch_spec.rb
@@ -14,14 +14,14 @@ require 'spec_helper'
describe ProtectedBranch do
describe 'Associations' do
- it { should belong_to(:project) }
+ it { is_expected.to belong_to(:project) }
end
describe "Mass assignment" do
end
describe 'Validation' do
- it { should validate_presence_of(:project) }
- it { should validate_presence_of(:name) }
+ it { is_expected.to validate_presence_of(:project) }
+ it { is_expected.to validate_presence_of(:name) }
end
end
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 6c3e221f343..eeb0f3d9ee0 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -8,14 +8,14 @@ describe Repository do
describe :branch_names_contains do
subject { repository.branch_names_contains(sample_commit.id) }
- it { should include('master') }
- it { should_not include('feature') }
- it { should_not include('fix') }
+ it { is_expected.to include('master') }
+ it { is_expected.not_to include('feature') }
+ it { is_expected.not_to include('fix') }
end
describe :last_commit_for_path do
subject { repository.last_commit_for_path(sample_commit.id, '.gitignore').id }
- it { should eq('c1acaa58bbcbc3eafe538cb8274ba387047b69f8') }
+ it { is_expected.to eq('c1acaa58bbcbc3eafe538cb8274ba387047b69f8') }
end
end
diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb
index c96f2b20529..1129bd1c76d 100644
--- a/spec/models/service_spec.rb
+++ b/spec/models/service_spec.rb
@@ -17,8 +17,8 @@ require 'spec_helper'
describe Service do
describe "Associations" do
- it { should belong_to :project }
- it { should have_one :service_hook }
+ it { is_expected.to belong_to :project }
+ it { is_expected.to have_one :service_hook }
end
describe "Mass assignment" do
@@ -40,7 +40,7 @@ describe Service do
end
describe :can_test do
- it { @testable.should == true }
+ it { expect(@testable).to eq(true) }
end
end
@@ -55,7 +55,7 @@ describe Service do
end
describe :can_test do
- it { @testable.should == true }
+ it { expect(@testable).to eq(true) }
end
end
end
diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb
index 1ef2c512c1f..e37dcc75230 100644
--- a/spec/models/snippet_spec.rb
+++ b/spec/models/snippet_spec.rb
@@ -19,22 +19,22 @@ require 'spec_helper'
describe Snippet do
describe "Associations" do
- it { should belong_to(:author).class_name('User') }
- it { should have_many(:notes).dependent(:destroy) }
+ it { is_expected.to belong_to(:author).class_name('User') }
+ it { is_expected.to have_many(:notes).dependent(:destroy) }
end
describe "Mass assignment" do
end
describe "Validation" do
- it { should validate_presence_of(:author) }
+ it { is_expected.to validate_presence_of(:author) }
- it { should validate_presence_of(:title) }
- it { should ensure_length_of(:title).is_within(0..255) }
+ it { is_expected.to validate_presence_of(:title) }
+ it { is_expected.to ensure_length_of(:title).is_within(0..255) }
- it { should validate_presence_of(:file_name) }
- it { should ensure_length_of(:title).is_within(0..255) }
+ it { is_expected.to validate_presence_of(:file_name) }
+ it { is_expected.to ensure_length_of(:title).is_within(0..255) }
- it { should validate_presence_of(:content) }
+ it { is_expected.to validate_presence_of(:content) }
end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 629d51b960d..e853262e00f 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -49,32 +49,32 @@ require 'spec_helper'
describe User do
describe "Associations" do
- it { should have_one(:namespace) }
- it { should have_many(:snippets).class_name('Snippet').dependent(:destroy) }
- it { should have_many(:project_members).dependent(:destroy) }
- it { should have_many(:groups) }
- it { should have_many(:keys).dependent(:destroy) }
- it { should have_many(:events).class_name('Event').dependent(:destroy) }
- it { should have_many(:recent_events).class_name('Event') }
- it { should have_many(:issues).dependent(:destroy) }
- it { should have_many(:notes).dependent(:destroy) }
- it { should have_many(:assigned_issues).dependent(:destroy) }
- it { should have_many(:merge_requests).dependent(:destroy) }
- it { should have_many(:assigned_merge_requests).dependent(:destroy) }
- it { should have_many(:identities).dependent(:destroy) }
+ it { is_expected.to have_one(:namespace) }
+ it { is_expected.to have_many(:snippets).class_name('Snippet').dependent(:destroy) }
+ it { is_expected.to have_many(:project_members).dependent(:destroy) }
+ it { is_expected.to have_many(:groups) }
+ it { is_expected.to have_many(:keys).dependent(:destroy) }
+ it { is_expected.to have_many(:events).class_name('Event').dependent(:destroy) }
+ it { is_expected.to have_many(:recent_events).class_name('Event') }
+ it { is_expected.to have_many(:issues).dependent(:destroy) }
+ it { is_expected.to have_many(:notes).dependent(:destroy) }
+ it { is_expected.to have_many(:assigned_issues).dependent(:destroy) }
+ it { is_expected.to have_many(:merge_requests).dependent(:destroy) }
+ it { is_expected.to have_many(:assigned_merge_requests).dependent(:destroy) }
+ it { is_expected.to have_many(:identities).dependent(:destroy) }
end
describe "Mass assignment" do
end
describe 'validations' do
- it { should validate_presence_of(:username) }
- it { should validate_presence_of(:projects_limit) }
- it { should validate_numericality_of(:projects_limit) }
- it { should allow_value(0).for(:projects_limit) }
- it { should_not allow_value(-1).for(:projects_limit) }
+ it { is_expected.to validate_presence_of(:username) }
+ it { is_expected.to validate_presence_of(:projects_limit) }
+ it { is_expected.to validate_numericality_of(:projects_limit) }
+ it { is_expected.to allow_value(0).for(:projects_limit) }
+ it { is_expected.not_to allow_value(-1).for(:projects_limit) }
- it { should ensure_length_of(:bio).is_within(0..255) }
+ it { is_expected.to ensure_length_of(:bio).is_within(0..255) }
describe 'email' do
it 'accepts info@example.com' do
@@ -110,34 +110,34 @@ describe User do
end
describe "Respond to" do
- it { should respond_to(:is_admin?) }
- it { should respond_to(:name) }
- it { should respond_to(:private_token) }
+ it { is_expected.to respond_to(:is_admin?) }
+ it { is_expected.to respond_to(:name) }
+ it { is_expected.to respond_to(:private_token) }
end
describe '#generate_password' do
it "should execute callback when force_random_password specified" do
user = build(:user, force_random_password: true)
- user.should_receive(:generate_password)
+ expect(user).to receive(:generate_password)
user.save
end
it "should not generate password by default" do
user = create(:user, password: 'abcdefghe')
- user.password.should == 'abcdefghe'
+ expect(user.password).to eq('abcdefghe')
end
it "should generate password when forcing random password" do
- Devise.stub(:friendly_token).and_return('123456789')
+ allow(Devise).to receive(:friendly_token).and_return('123456789')
user = create(:user, password: 'abcdefg', force_random_password: true)
- user.password.should == '12345678'
+ expect(user.password).to eq('12345678')
end
end
describe 'authentication token' do
it "should have authentication token" do
user = create(:user)
- user.authentication_token.should_not be_blank
+ expect(user.authentication_token).not_to be_blank
end
end
@@ -152,15 +152,15 @@ describe User do
@project_3.team << [@user, :developer]
end
- it { @user.authorized_projects.should include(@project) }
- it { @user.authorized_projects.should include(@project_2) }
- it { @user.authorized_projects.should include(@project_3) }
- it { @user.owned_projects.should include(@project) }
- it { @user.owned_projects.should_not include(@project_2) }
- it { @user.owned_projects.should_not include(@project_3) }
- it { @user.personal_projects.should include(@project) }
- it { @user.personal_projects.should_not include(@project_2) }
- it { @user.personal_projects.should_not include(@project_3) }
+ it { expect(@user.authorized_projects).to include(@project) }
+ it { expect(@user.authorized_projects).to include(@project_2) }
+ it { expect(@user.authorized_projects).to include(@project_3) }
+ it { expect(@user.owned_projects).to include(@project) }
+ it { expect(@user.owned_projects).not_to include(@project_2) }
+ it { expect(@user.owned_projects).not_to include(@project_3) }
+ it { expect(@user.personal_projects).to include(@project) }
+ it { expect(@user.personal_projects).not_to include(@project_2) }
+ it { expect(@user.personal_projects).not_to include(@project_3) }
end
describe 'groups' do
@@ -170,9 +170,9 @@ describe User do
@group.add_owner(@user)
end
- it { @user.several_namespaces?.should be_true }
- it { @user.authorized_groups.should == [@group] }
- it { @user.owned_groups.should == [@group] }
+ it { expect(@user.several_namespaces?).to be_truthy }
+ it { expect(@user.authorized_groups).to eq([@group]) }
+ it { expect(@user.owned_groups).to eq([@group]) }
end
describe 'group multiple owners' do
@@ -185,7 +185,7 @@ describe User do
@group.add_user(@user2, GroupMember::OWNER)
end
- it { @user2.several_namespaces?.should be_true }
+ it { expect(@user2.several_namespaces?).to be_truthy }
end
describe 'namespaced' do
@@ -194,7 +194,7 @@ describe User do
@project = create :project, namespace: @user.namespace
end
- it { @user.several_namespaces?.should be_false }
+ it { expect(@user.several_namespaces?).to be_falsey }
end
describe 'blocking user' do
@@ -202,7 +202,7 @@ describe User do
it "should block user" do
user.block
- user.blocked?.should be_true
+ expect(user.blocked?).to be_truthy
end
end
@@ -214,10 +214,10 @@ describe User do
@blocked = create :user, state: :blocked
end
- it { User.filter("admins").should == [@admin] }
- it { User.filter("blocked").should == [@blocked] }
- it { User.filter("wop").should include(@user, @admin, @blocked) }
- it { User.filter(nil).should include(@user, @admin) }
+ it { expect(User.filter("admins")).to eq([@admin]) }
+ it { expect(User.filter("blocked")).to eq([@blocked]) }
+ it { expect(User.filter("wop")).to include(@user, @admin, @blocked) }
+ it { expect(User.filter(nil)).to include(@user, @admin) }
end
describe :not_in_project do
@@ -227,27 +227,27 @@ describe User do
@project = create :project
end
- it { User.not_in_project(@project).should include(@user, @project.owner) }
+ it { expect(User.not_in_project(@project)).to include(@user, @project.owner) }
end
describe 'user creation' do
describe 'normal user' do
let(:user) { create(:user, name: 'John Smith') }
- it { user.is_admin?.should be_false }
- it { user.require_ssh_key?.should be_true }
- it { user.can_create_group?.should be_true }
- it { user.can_create_project?.should be_true }
- it { user.first_name.should == 'John' }
+ it { expect(user.is_admin?).to be_falsey }
+ it { expect(user.require_ssh_key?).to be_truthy }
+ it { expect(user.can_create_group?).to be_truthy }
+ it { expect(user.can_create_project?).to be_truthy }
+ it { expect(user.first_name).to eq('John') }
end
describe 'with defaults' do
let(:user) { User.new }
it "should apply defaults to user" do
- user.projects_limit.should == Gitlab.config.gitlab.default_projects_limit
- user.can_create_group.should == Gitlab.config.gitlab.default_can_create_group
- user.theme_id.should == Gitlab.config.gitlab.default_theme
+ expect(user.projects_limit).to eq(Gitlab.config.gitlab.default_projects_limit)
+ expect(user.can_create_group).to eq(Gitlab.config.gitlab.default_can_create_group)
+ expect(user.theme_id).to eq(Gitlab.config.gitlab.default_theme)
end
end
@@ -255,9 +255,9 @@ describe User do
let(:user) { User.new(projects_limit: 123, can_create_group: false, can_create_team: true, theme_id: Gitlab::Theme::BASIC) }
it "should apply defaults to user" do
- user.projects_limit.should == 123
- user.can_create_group.should be_false
- user.theme_id.should == Gitlab::Theme::BASIC
+ expect(user.projects_limit).to eq(123)
+ expect(user.can_create_group).to be_falsey
+ expect(user.theme_id).to eq(Gitlab::Theme::BASIC)
end
end
end
@@ -267,12 +267,12 @@ describe User do
let(:user2) { create(:user, username: 'jameson', email: 'jameson@example.com') }
it "should be case insensitive" do
- User.search(user1.username.upcase).to_a.should == [user1]
- User.search(user1.username.downcase).to_a.should == [user1]
- User.search(user2.username.upcase).to_a.should == [user2]
- User.search(user2.username.downcase).to_a.should == [user2]
- User.search(user1.username.downcase).to_a.count.should == 2
- User.search(user2.username.downcase).to_a.count.should == 1
+ expect(User.search(user1.username.upcase).to_a).to eq([user1])
+ expect(User.search(user1.username.downcase).to_a).to eq([user1])
+ expect(User.search(user2.username.upcase).to_a).to eq([user2])
+ expect(User.search(user2.username.downcase).to_a).to eq([user2])
+ expect(User.search(user1.username.downcase).to_a.count).to eq(2)
+ expect(User.search(user2.username.downcase).to_a.count).to eq(1)
end
end
@@ -280,10 +280,10 @@ describe User do
let(:user1) { create(:user, username: 'foo') }
it "should get the correct user" do
- User.by_username_or_id(user1.id).should == user1
- User.by_username_or_id('foo').should == user1
- User.by_username_or_id(-1).should be_nil
- User.by_username_or_id('bar').should be_nil
+ expect(User.by_username_or_id(user1.id)).to eq(user1)
+ expect(User.by_username_or_id('foo')).to eq(user1)
+ expect(User.by_username_or_id(-1)).to be_nil
+ expect(User.by_username_or_id('bar')).to be_nil
end
end
@@ -302,13 +302,13 @@ describe User do
end
describe 'all_ssh_keys' do
- it { should have_many(:keys).dependent(:destroy) }
+ it { is_expected.to have_many(:keys).dependent(:destroy) }
it "should have all ssh keys" do
user = create :user
key = create :key, key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD33bWLBxu48Sev9Fert1yzEO4WGcWglWF7K/AwblIUFselOt/QdOL9DSjpQGxLagO1s9wl53STIO8qGS4Ms0EJZyIXOEFMjFJ5xmjSy+S37By4sG7SsltQEHMxtbtFOaW5LV2wCrX+rUsRNqLMamZjgjcPO0/EgGCXIGMAYW4O7cwGZdXWYIhQ1Vwy+CsVMDdPkPgBXqK7nR/ey8KMs8ho5fMNgB5hBw/AL9fNGhRw3QTD6Q12Nkhl4VZES2EsZqlpNnJttnPdp847DUsT6yuLRlfiQfz5Cn9ysHFdXObMN5VYIiPFwHeYCZp1X2S4fDZooRE8uOLTfxWHPXwrhqSH", user_id: user.id
- user.all_ssh_keys.should include(key.key)
+ expect(user.all_ssh_keys).to include(key.key)
end
end
@@ -317,12 +317,12 @@ describe User do
it "should be true if avatar is image" do
user.update_attribute(:avatar, 'uploads/avatar.png')
- user.avatar_type.should be_true
+ expect(user.avatar_type).to be_truthy
end
it "should be false if avatar is html page" do
user.update_attribute(:avatar, 'uploads/avatar.html')
- user.avatar_type.should == ["only images allowed"]
+ expect(user.avatar_type).to eq(["only images allowed"])
end
end
@@ -333,7 +333,7 @@ describe User do
# Create a condition which would otherwise cause 'true' to be returned
user.stub(ldap_user?: true)
user.last_credential_check_at = nil
- expect(user.requires_ldap_check?).to be_false
+ expect(user.requires_ldap_check?).to be_falsey
end
context 'when LDAP is enabled' do
@@ -341,7 +341,7 @@ describe User do
it 'is false for non-LDAP users' do
user.stub(ldap_user?: false)
- expect(user.requires_ldap_check?).to be_false
+ expect(user.requires_ldap_check?).to be_falsey
end
context 'and when the user is an LDAP user' do
@@ -349,12 +349,12 @@ describe User do
it 'is true when the user has never had an LDAP check before' do
user.last_credential_check_at = nil
- expect(user.requires_ldap_check?).to be_true
+ expect(user.requires_ldap_check?).to be_truthy
end
it 'is true when the last LDAP check happened over 1 hour ago' do
user.last_credential_check_at = 2.hours.ago
- expect(user.requires_ldap_check?).to be_true
+ expect(user.requires_ldap_check?).to be_truthy
end
end
end
@@ -363,24 +363,24 @@ describe User do
describe :ldap_user? do
it "is true if provider name starts with ldap" do
user = create(:omniauth_user, provider: 'ldapmain')
- expect( user.ldap_user? ).to be_true
+ expect( user.ldap_user? ).to be_truthy
end
it "is false for other providers" do
user = create(:omniauth_user, provider: 'other-provider')
- expect( user.ldap_user? ).to be_false
+ expect( user.ldap_user? ).to be_falsey
end
it "is false if no extern_uid is provided" do
user = create(:omniauth_user, extern_uid: nil)
- expect( user.ldap_user? ).to be_false
+ expect( user.ldap_user? ).to be_falsey
end
end
describe :ldap_identity do
it "returns ldap identity" do
user = create :omniauth_user
- user.ldap_identity.provider.should_not be_empty
+ expect(user.ldap_identity.provider).not_to be_empty
end
end
@@ -434,24 +434,24 @@ describe User do
project1 = create :project, :public
project2 = create :project, :public
- expect(user.starred?(project1)).to be_false
- expect(user.starred?(project2)).to be_false
+ expect(user.starred?(project1)).to be_falsey
+ expect(user.starred?(project2)).to be_falsey
star1 = UsersStarProject.create!(project: project1, user: user)
- expect(user.starred?(project1)).to be_true
- expect(user.starred?(project2)).to be_false
+ expect(user.starred?(project1)).to be_truthy
+ expect(user.starred?(project2)).to be_falsey
star2 = UsersStarProject.create!(project: project2, user: user)
- expect(user.starred?(project1)).to be_true
- expect(user.starred?(project2)).to be_true
+ expect(user.starred?(project1)).to be_truthy
+ expect(user.starred?(project2)).to be_truthy
star1.destroy
- expect(user.starred?(project1)).to be_false
- expect(user.starred?(project2)).to be_true
+ expect(user.starred?(project1)).to be_falsey
+ expect(user.starred?(project2)).to be_truthy
star2.destroy
- expect(user.starred?(project1)).to be_false
- expect(user.starred?(project2)).to be_false
+ expect(user.starred?(project1)).to be_falsey
+ expect(user.starred?(project2)).to be_falsey
end
end
@@ -460,11 +460,11 @@ describe User do
user = create :user
project = create :project, :public
- expect(user.starred?(project)).to be_false
+ expect(user.starred?(project)).to be_falsey
user.toggle_star(project)
- expect(user.starred?(project)).to be_true
+ expect(user.starred?(project)).to be_truthy
user.toggle_star(project)
- expect(user.starred?(project)).to be_false
+ expect(user.starred?(project)).to be_falsey
end
end
@@ -476,23 +476,23 @@ describe User do
end
it "sorts users as recently_signed_in" do
- User.sort('recent_sign_in').first.should == @user
+ expect(User.sort('recent_sign_in').first).to eq(@user)
end
it "sorts users as late_signed_in" do
- User.sort('oldest_sign_in').first.should == @user1
+ expect(User.sort('oldest_sign_in').first).to eq(@user1)
end
it "sorts users as recently_created" do
- User.sort('created_desc').first.should == @user
+ expect(User.sort('created_desc').first).to eq(@user)
end
it "sorts users as late_created" do
- User.sort('created_asc').first.should == @user1
+ expect(User.sort('created_asc').first).to eq(@user1)
end
it "sorts users by name when nil is passed" do
- User.sort(nil).first.should == @user
+ expect(User.sort(nil).first).to eq(@user)
end
end
end
diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb
index 78877db61b7..f3fd805783f 100644
--- a/spec/models/wiki_page_spec.rb
+++ b/spec/models/wiki_page_spec.rb
@@ -16,27 +16,27 @@ describe WikiPage do
end
it "sets the slug attribute" do
- @wiki_page.slug.should == "test-page"
+ expect(@wiki_page.slug).to eq("test-page")
end
it "sets the title attribute" do
- @wiki_page.title.should == "test page"
+ expect(@wiki_page.title).to eq("test page")
end
it "sets the formatted content attribute" do
- @wiki_page.content.should == "test content"
+ expect(@wiki_page.content).to eq("test content")
end
it "sets the format attribute" do
- @wiki_page.format.should == :markdown
+ expect(@wiki_page.format).to eq(:markdown)
end
it "sets the message attribute" do
- @wiki_page.message.should == "test commit"
+ expect(@wiki_page.message).to eq("test commit")
end
it "sets the version attribute" do
- @wiki_page.version.should be_a Gollum::Git::Commit
+ expect(@wiki_page.version).to be_a Gollum::Git::Commit
end
end
end
@@ -48,12 +48,12 @@ describe WikiPage do
it "validates presence of title" do
subject.attributes.delete(:title)
- subject.valid?.should be_false
+ expect(subject.valid?).to be_falsey
end
it "validates presence of content" do
subject.attributes.delete(:content)
- subject.valid?.should be_false
+ expect(subject.valid?).to be_falsey
end
end
@@ -69,11 +69,11 @@ describe WikiPage do
context "with valid attributes" do
it "saves the wiki page" do
subject.create(@wiki_attr)
- wiki.find_page("Index").should_not be_nil
+ expect(wiki.find_page("Index")).not_to be_nil
end
it "returns true" do
- subject.create(@wiki_attr).should == true
+ expect(subject.create(@wiki_attr)).to eq(true)
end
end
end
@@ -95,7 +95,7 @@ describe WikiPage do
end
it "returns true" do
- @page.update("more content").should be_true
+ expect(@page.update("more content")).to be_truthy
end
end
end
@@ -108,11 +108,11 @@ describe WikiPage do
it "should delete the page" do
@page.delete
- wiki.pages.should be_empty
+ expect(wiki.pages).to be_empty
end
it "should return true" do
- @page.delete.should == true
+ expect(@page.delete).to eq(true)
end
end
@@ -128,7 +128,7 @@ describe WikiPage do
it "returns an array of all commits for the page" do
3.times { |i| @page.update("content #{i}") }
- @page.versions.count.should == 4
+ expect(@page.versions.count).to eq(4)
end
end
@@ -144,7 +144,7 @@ describe WikiPage do
it "should be replace a hyphen to a space" do
@page.title = "Import-existing-repositories-into-GitLab"
- @page.title.should == "Import existing repositories into GitLab"
+ expect(@page.title).to eq("Import existing repositories into GitLab")
end
end