summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-05-21 17:49:06 -0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-22 12:13:46 +0200
commit5a9ede472150ec78f8410ae15cf782095c8f056c (patch)
tree5cbdbfb971329960011e8b3a3544e583f9551f6c /spec/models
parentdad88568f34bfda5f7fe34672bc5099c80226138 (diff)
downloadgitlab-ce-5a9ede472150ec78f8410ae15cf782095c8f056c.tar.gz
Update mock and stub syntax for specs
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/commit_spec.rb8
-rw-r--r--spec/models/concerns/issuable_spec.rb5
-rw-r--r--spec/models/forked_project_link_spec.rb12
-rw-r--r--spec/models/members/group_member_spec.rb8
-rw-r--r--spec/models/merge_request_spec.rb10
-rw-r--r--spec/models/milestone_spec.rb14
-rw-r--r--spec/models/namespace_spec.rb6
-rw-r--r--spec/models/project_services/asana_service_spec.rb2
-rw-r--r--spec/models/project_services/assembla_service_spec.rb2
-rw-r--r--spec/models/project_services/buildkite_service_spec.rb6
-rw-r--r--spec/models/project_services/flowdock_service_spec.rb2
-rw-r--r--spec/models/project_services/gemnasium_service_spec.rb2
-rw-r--r--spec/models/project_services/gitlab_ci_service_spec.rb19
-rw-r--r--spec/models/project_services/hipchat_service_spec.rb10
-rw-r--r--spec/models/project_services/irker_service_spec.rb6
-rw-r--r--spec/models/project_services/pushover_service_spec.rb2
-rw-r--r--spec/models/project_services/slack_service_spec.rb16
-rw-r--r--spec/models/project_spec.rb2
-rw-r--r--spec/models/service_spec.rb8
-rw-r--r--spec/models/user_spec.rb12
20 files changed, 79 insertions, 73 deletions
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index 27eb02a870b..e303a97e6b5 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -77,13 +77,13 @@ eos
let(:other_issue) { create :issue, project: other_project }
it 'detects issues that this commit is marked as closing' do
- commit.stub(safe_message: "Fixes ##{issue.iid}")
+ allow(commit).to receive(:safe_message).and_return("Fixes ##{issue.iid}")
expect(commit.closes_issues).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}")
+ allow(commit).to receive(:safe_message).and_return("Fixes #{ext_ref}")
expect(commit.closes_issues).to be_empty
end
end
@@ -93,7 +93,9 @@ eos
let(:author) { create(:user, email: commit.author_email) }
let(:backref_text) { "commit #{subject.id}" }
- let(:set_mentionable_text) { ->(txt){ subject.stub(safe_message: txt) } }
+ let(:set_mentionable_text) do
+ ->(txt) { allow(subject).to receive(:safe_message).and_return(txt) }
+ end
# Include the subject in the repository stub.
let(:extra_commits) { [subject] }
diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb
index 86c395a8e8e..b6d80451d2e 100644
--- a/spec/models/concerns/issuable_spec.rb
+++ b/spec/models/concerns/issuable_spec.rb
@@ -11,7 +11,10 @@ describe Issue, "Issuable" do
end
describe "Validation" do
- before { subject.stub(set_iid: false) }
+ before do
+ allow(subject).to receive(:set_iid).and_return(false)
+ end
+
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:iid) }
it { is_expected.to validate_presence_of(:author) }
diff --git a/spec/models/forked_project_link_spec.rb b/spec/models/forked_project_link_spec.rb
index 7d0ad44a92c..d90fbfe1ea5 100644
--- a/spec/models/forked_project_link_spec.rb
+++ b/spec/models/forked_project_link_spec.rb
@@ -58,10 +58,10 @@ describe :forked_from_project do
end
def fork_project(from_project, user)
- context = Projects::ForkService.new(from_project, user)
- shell = double("gitlab_shell")
- shell.stub(fork_repository: true)
- context.stub(gitlab_shell: shell)
- context.execute
-end
+ shell = double('gitlab_shell', fork_repository: true)
+
+ service = Projects::ForkService.new(from_project, user)
+ allow(service).to receive(:gitlab_shell).and_return(shell)
+ service.execute
+end
diff --git a/spec/models/members/group_member_spec.rb b/spec/models/members/group_member_spec.rb
index 7c10c9f0f48..652026729bb 100644
--- a/spec/models/members/group_member_spec.rb
+++ b/spec/models/members/group_member_spec.rb
@@ -24,8 +24,11 @@ describe GroupMember do
describe "#after_create" do
it "should send email to user" do
membership = build(:group_member)
- membership.stub(notification_service: double('NotificationService').as_null_object)
+
+ allow(membership).to receive(:notification_service).
+ and_return(double('NotificationService').as_null_object)
expect(membership).to receive(:notification_service)
+
membership.save
end
end
@@ -33,7 +36,8 @@ describe GroupMember do
describe "#after_update" do
before do
@group_member = create :group_member
- @group_member.stub(notification_service: double('NotificationService').as_null_object)
+ allow(@group_member).to receive(:notification_service).
+ and_return(double('NotificationService').as_null_object)
end
it "should send email to user" do
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 0465aa34843..73536b6ae96 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -111,17 +111,18 @@ describe MergeRequest do
let(:commit2) { double('commit2', closes_issues: [issue1]) }
before do
- subject.stub(commits: [commit0, commit1, commit2])
+ allow(subject).to receive(:commits).and_return([commit0, commit1, commit2])
end
it 'accesses the set of issues that will be closed on acceptance' do
- subject.project.stub(default_branch: subject.target_branch)
+ allow(subject.project).to receive(:default_branch).
+ and_return(subject.target_branch)
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')
+ allow(subject.project).to receive(:default_branch).and_return('master')
subject.target_branch = 'something-else'
expect(subject.closes_issues).to be_empty
@@ -130,7 +131,8 @@ describe MergeRequest do
it 'detects issues mentioned in the description' do
issue2 = create(:issue, project: subject.project)
subject.description = "Closes #{issue2.to_reference}"
- subject.project.stub(default_branch: subject.target_branch)
+ allow(subject.project).to receive(:default_branch).
+ and_return(subject.target_branch)
expect(subject.closes_issues).to include(issue2)
end
diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb
index eb73aa763fc..36352e1ecce 100644
--- a/spec/models/milestone_spec.rb
+++ b/spec/models/milestone_spec.rb
@@ -21,11 +21,11 @@ describe Milestone do
it { is_expected.to have_many(:issues) }
end
- describe "Mass assignment" do
- end
-
describe "Validation" do
- before { subject.stub(set_iid: false) }
+ before do
+ allow(subject).to receive(:set_iid).and_return(false)
+ end
+
it { is_expected.to validate_presence_of(:title) }
it { is_expected.to validate_presence_of(:project) }
end
@@ -66,7 +66,7 @@ describe Milestone do
describe :expired? do
context "expired" do
before do
- milestone.stub(due_date: Date.today.prev_year)
+ allow(milestone).to receive(:due_date).and_return(Date.today.prev_year)
end
it { expect(milestone.expired?).to be_truthy }
@@ -74,7 +74,7 @@ describe Milestone do
context "not expired" do
before do
- milestone.stub(due_date: Date.today.next_year)
+ allow(milestone).to receive(:due_date).and_return(Date.today.next_year)
end
it { expect(milestone.expired?).to be_falsey }
@@ -83,7 +83,7 @@ describe Milestone do
describe :percent_complete do
before do
- milestone.stub(
+ allow(milestone).to receive_messages(
closed_items_count: 3,
total_items_count: 4
)
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb
index e87432fdf62..1d72a9503ae 100644
--- a/spec/models/namespace_spec.rb
+++ b/spec/models/namespace_spec.rb
@@ -53,7 +53,7 @@ describe Namespace do
describe :move_dir do
before do
@namespace = create :namespace
- @namespace.stub(path_changed?: true)
+ allow(@namespace).to receive(:path_changed?).and_return(true)
end
it "should raise error when directory exists" do
@@ -62,8 +62,8 @@ describe Namespace do
it "should move dir if path changed" do
new_path = @namespace.path + "_new"
- @namespace.stub(path_was: @namespace.path)
- @namespace.stub(path: new_path)
+ allow(@namespace).to receive(:path_was).and_return(@namespace.path)
+ allow(@namespace).to receive(:path).and_return(new_path)
expect(@namespace.move_dir).to be_truthy
end
end
diff --git a/spec/models/project_services/asana_service_spec.rb b/spec/models/project_services/asana_service_spec.rb
index cc1f99e0c72..64bb92fba95 100644
--- a/spec/models/project_services/asana_service_spec.rb
+++ b/spec/models/project_services/asana_service_spec.rb
@@ -42,7 +42,7 @@ describe AsanaService, models: true do
before do
@asana = AsanaService.new
- @asana.stub(
+ allow(@asana).to receive_messages(
project: project,
project_id: project.id,
service_hook: true,
diff --git a/spec/models/project_services/assembla_service_spec.rb b/spec/models/project_services/assembla_service_spec.rb
index 9aee754dd63..17e9361dd5c 100644
--- a/spec/models/project_services/assembla_service_spec.rb
+++ b/spec/models/project_services/assembla_service_spec.rb
@@ -32,7 +32,7 @@ describe AssemblaService, models: true do
before do
@assembla_service = AssemblaService.new
- @assembla_service.stub(
+ allow(@assembla_service).to receive_messages(
project_id: project.id,
project: project,
service_hook: true,
diff --git a/spec/models/project_services/buildkite_service_spec.rb b/spec/models/project_services/buildkite_service_spec.rb
index 6db54243eac..9445d96c337 100644
--- a/spec/models/project_services/buildkite_service_spec.rb
+++ b/spec/models/project_services/buildkite_service_spec.rb
@@ -29,12 +29,10 @@ describe BuildkiteService do
describe 'commits methods' do
before do
@project = Project.new
- @project.stub(
- default_branch: 'default-brancho'
- )
+ allow(@project).to receive(:default_branch).and_return('default-brancho')
@service = BuildkiteService.new
- @service.stub(
+ allow(@service).to receive_messages(
project: @project,
service_hook: true,
project_url: 'https://buildkite.com/account-name/example-project',
diff --git a/spec/models/project_services/flowdock_service_spec.rb b/spec/models/project_services/flowdock_service_spec.rb
index e6e8fbba6a7..7e5b15cb09e 100644
--- a/spec/models/project_services/flowdock_service_spec.rb
+++ b/spec/models/project_services/flowdock_service_spec.rb
@@ -32,7 +32,7 @@ describe FlowdockService do
before do
@flowdock_service = FlowdockService.new
- @flowdock_service.stub(
+ allow(@flowdock_service).to receive_messages(
project_id: project.id,
project: project,
service_hook: true,
diff --git a/spec/models/project_services/gemnasium_service_spec.rb b/spec/models/project_services/gemnasium_service_spec.rb
index 1a7765e5c2a..9e156472316 100644
--- a/spec/models/project_services/gemnasium_service_spec.rb
+++ b/spec/models/project_services/gemnasium_service_spec.rb
@@ -32,7 +32,7 @@ describe GemnasiumService do
before do
@gemnasium_service = GemnasiumService.new
- @gemnasium_service.stub(
+ allow(@gemnasium_service).to receive_messages(
project_id: project.id,
project: project,
service_hook: true,
diff --git a/spec/models/project_services/gitlab_ci_service_spec.rb b/spec/models/project_services/gitlab_ci_service_spec.rb
index c92cf3cdae6..fedc37c9b94 100644
--- a/spec/models/project_services/gitlab_ci_service_spec.rb
+++ b/spec/models/project_services/gitlab_ci_service_spec.rb
@@ -21,18 +21,15 @@
require 'spec_helper'
describe GitlabCiService do
- describe "Associations" do
- it { is_expected.to belong_to :project }
- it { is_expected.to have_one :service_hook }
- end
-
- describe "Mass assignment" do
+ describe 'associations' do
+ it { is_expected.to belong_to(:project) }
+ it { is_expected.to have_one(:service_hook) }
end
describe 'commits methods' do
before do
@service = GitlabCiService.new
- @service.stub(
+ allow(@service).to receive_messages(
service_hook: true,
project_url: 'http://ci.gitlab.org/projects/2',
token: 'verySecret'
@@ -56,9 +53,9 @@ describe GitlabCiService do
it "calls ci_yaml_file" do
service_hook = double
- service_hook.should_receive(:execute)
- @service.should_receive(:service_hook).and_return(service_hook)
- @service.should_receive(:ci_yaml_file).with(push_sample_data[:checkout_sha])
+ expect(service_hook).to receive(:execute)
+ expect(@service).to receive(:service_hook).and_return(service_hook)
+ expect(@service).to receive(:ci_yaml_file).with(push_sample_data[:checkout_sha])
@service.execute(push_sample_data)
end
@@ -72,7 +69,7 @@ describe GitlabCiService do
@user = create(:user)
@service = GitlabCiService.new
- @service.stub(
+ allow(@service).to receive_messages(
service_hook: true,
project_url: 'http://ci.gitlab.org/projects/2',
token: 'verySecret',
diff --git a/spec/models/project_services/hipchat_service_spec.rb b/spec/models/project_services/hipchat_service_spec.rb
index e88615e1a2e..8ed03dd1da8 100644
--- a/spec/models/project_services/hipchat_service_spec.rb
+++ b/spec/models/project_services/hipchat_service_spec.rb
@@ -37,7 +37,7 @@ describe HipchatService do
let(:push_sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) }
before(:each) do
- hipchat.stub(
+ allow(hipchat).to receive_messages(
project_id: project.id,
project: project,
room: 123456,
@@ -48,7 +48,7 @@ describe HipchatService do
end
it 'should use v1 if version is provided' do
- hipchat.stub(api_version: 'v1')
+ allow(hipchat).to receive(:api_version).and_return('v1')
expect(HipChat::Client).to receive(:new).
with(token,
api_version: 'v1',
@@ -59,7 +59,7 @@ describe HipchatService do
end
it 'should use v2 as the version when nothing is provided' do
- hipchat.stub(api_version: '')
+ allow(hipchat).to receive(:api_version).and_return('')
expect(HipChat::Client).to receive(:new).
with(token,
api_version: 'v2',
@@ -245,12 +245,12 @@ describe HipchatService do
end
it "should set notfiy to true" do
- hipchat.stub(notify: '1')
+ allow(hipchat).to receive(:notify).and_return('1')
expect(hipchat.send(:message_options)).to eq({notify: true, color: 'yellow'})
end
it "should set the color" do
- hipchat.stub(color: 'red')
+ allow(hipchat).to receive(:color).and_return('red')
expect(hipchat.send(:message_options)).to eq({notify: false, color: 'red'})
end
end
diff --git a/spec/models/project_services/irker_service_spec.rb b/spec/models/project_services/irker_service_spec.rb
index 4c437aab12b..37690434ec8 100644
--- a/spec/models/project_services/irker_service_spec.rb
+++ b/spec/models/project_services/irker_service_spec.rb
@@ -24,8 +24,8 @@ require 'json'
describe IrkerService 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
@@ -66,7 +66,7 @@ describe IrkerService do
let(:colorize_messages) { '1' }
before do
- irker.stub(
+ allow(irker).to receive_messages(
active: true,
project: project,
project_id: project.id,
diff --git a/spec/models/project_services/pushover_service_spec.rb b/spec/models/project_services/pushover_service_spec.rb
index 5f93703b50a..ac10ffbd39b 100644
--- a/spec/models/project_services/pushover_service_spec.rb
+++ b/spec/models/project_services/pushover_service_spec.rb
@@ -52,7 +52,7 @@ describe PushoverService do
let(:api_url) { 'https://api.pushover.net/1/messages.json' }
before do
- pushover.stub(
+ allow(pushover).to receive_messages(
project: project,
project_id: project.id,
service_hook: true,
diff --git a/spec/models/project_services/slack_service_spec.rb b/spec/models/project_services/slack_service_spec.rb
index e9105677d23..69466b11f09 100644
--- a/spec/models/project_services/slack_service_spec.rb
+++ b/spec/models/project_services/slack_service_spec.rb
@@ -46,7 +46,7 @@ describe SlackService do
let(:channel) { 'slack_channel' }
before do
- slack.stub(
+ allow(slack).to receive_messages(
project: project,
project_id: project.id,
service_hook: true,
@@ -96,7 +96,7 @@ describe SlackService do
end
it 'should use the username as an option for slack when configured' do
- slack.stub(username: username)
+ allow(slack).to receive(:username).and_return(username)
expect(Slack::Notifier).to receive(:new).
with(webhook_url, username: username).
and_return(
@@ -106,7 +106,7 @@ describe SlackService do
end
it 'should use the channel as an option when it is configured' do
- slack.stub(channel: channel)
+ allow(slack).to receive(:channel).and_return(channel)
expect(Slack::Notifier).to receive(:new).
with(webhook_url, channel: channel).
and_return(
@@ -130,11 +130,11 @@ describe SlackService do
let(:webhook_url) { 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685' }
before do
- slack.stub(
- project: project,
- project_id: project.id,
- service_hook: true,
- webhook: webhook_url
+ allow(slack).to receive_messages(
+ project: project,
+ project_id: project.id,
+ service_hook: true,
+ webhook: webhook_url
)
WebMock.stub_request(:post, webhook_url)
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 87c67fa32c3..63091e913ff 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -127,7 +127,7 @@ describe Project do
describe 'last_activity' do
it 'should alias last_activity to last_event' do
- project.stub(last_event: last_event)
+ allow(project).to receive(:last_event).and_return(last_event)
expect(project.last_activity).to eq(last_event)
end
end
diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb
index 5d4827ce92a..cb633216d3b 100644
--- a/spec/models/service_spec.rb
+++ b/spec/models/service_spec.rb
@@ -39,9 +39,7 @@ describe Service do
let (:project) { create :project }
before do
- @service.stub(
- project: project
- )
+ allow(@service).to receive(:project).and_return(project)
@testable = @service.can_test?
end
@@ -54,9 +52,7 @@ describe Service do
let (:project) { create :project }
before do
- @service.stub(
- project: project
- )
+ allow(@service).to receive(:project).and_return(project)
@testable = @service.can_test?
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index afdd9f71af2..9f7c83f3476 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -458,21 +458,25 @@ describe User do
it 'is false when LDAP is disabled' do
# Create a condition which would otherwise cause 'true' to be returned
- user.stub(ldap_user?: true)
+ allow(user).to receive(:ldap_user?).and_return(true)
user.last_credential_check_at = nil
expect(user.requires_ldap_check?).to be_falsey
end
context 'when LDAP is enabled' do
- before { Gitlab.config.ldap.stub(enabled: true) }
+ before do
+ allow(Gitlab.config.ldap).to receive(:enabled).and_return(true)
+ end
it 'is false for non-LDAP users' do
- user.stub(ldap_user?: false)
+ allow(user).to receive(:ldap_user?).and_return(false)
expect(user.requires_ldap_check?).to be_falsey
end
context 'and when the user is an LDAP user' do
- before { user.stub(ldap_user?: true) }
+ before do
+ allow(user).to receive(:ldap_user?).and_return(true)
+ end
it 'is true when the user has never had an LDAP check before' do
user.last_credential_check_at = nil