diff options
-rw-r--r-- | spec/models/commit_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/concerns/issuable_spec.rb | 5 | ||||
-rw-r--r-- | spec/models/forked_project_link_spec.rb | 12 | ||||
-rw-r--r-- | spec/models/members/group_member_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 10 | ||||
-rw-r--r-- | spec/models/milestone_spec.rb | 14 | ||||
-rw-r--r-- | spec/models/namespace_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/service_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 12 |
10 files changed, 48 insertions, 37 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_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 f1b8afa5854..fdd4e431efe 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -408,21 +408,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 |