Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-05-22 00:49:06 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-22 13:13:46 +0300
commit5a9ede472150ec78f8410ae15cf782095c8f056c (patch)
tree5cbdbfb971329960011e8b3a3544e583f9551f6c /spec/requests
parentdad88568f34bfda5f7fe34672bc5099c80226138 (diff)
Update mock and stub syntax for specs
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/api_helpers_spec.rb2
-rw-r--r--spec/requests/api/branches_spec.rb4
-rw-r--r--spec/requests/api/files_spec.rb9
-rw-r--r--spec/requests/api/groups_spec.rb3
-rw-r--r--spec/requests/api/merge_requests_spec.rb10
-rw-r--r--spec/requests/api/projects_spec.rb19
6 files changed, 25 insertions, 22 deletions
diff --git a/spec/requests/api/api_helpers_spec.rb b/spec/requests/api/api_helpers_spec.rb
index 20cb30a39bb..9a4102c752d 100644
--- a/spec/requests/api/api_helpers_spec.rb
+++ b/spec/requests/api/api_helpers_spec.rb
@@ -47,7 +47,7 @@ describe API, api: true do
it "should return nil for a user without access" do
env[API::APIHelpers::PRIVATE_TOKEN_HEADER] = user.private_token
- Gitlab::UserAccess.stub(allowed?: false)
+ allow(Gitlab::UserAccess).to receive(:allowed?).and_return(false)
expect(current_user).to be_nil
end
diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb
index f40d68b75a4..cb6e5e89625 100644
--- a/spec/requests/api/branches_spec.rb
+++ b/spec/requests/api/branches_spec.rb
@@ -141,7 +141,9 @@ describe API::API, api: true do
end
describe "DELETE /projects/:id/repository/branches/:branch" do
- before { Repository.any_instance.stub(rm_branch: true) }
+ before do
+ allow_any_instance_of(Repository).to receive(:rm_branch).and_return(true)
+ end
it "should remove branch" do
delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user)
diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb
index 15f547e128d..8a6b4b8a170 100644
--- a/spec/requests/api/files_spec.rb
+++ b/spec/requests/api/files_spec.rb
@@ -60,9 +60,8 @@ describe API::API, api: true do
end
it "should return a 400 if editor fails to create file" do
- Repository.any_instance.stub(
- commit_file: false,
- )
+ allow_any_instance_of(Repository).to receive(:commit_file).
+ and_return(false)
post api("/projects/#{project.id}/repository/files", user), valid_params
expect(response.status).to eq(400)
@@ -112,9 +111,7 @@ describe API::API, api: true do
end
it "should return a 400 if satellite fails to create file" do
- Repository.any_instance.stub(
- remove_file: false,
- )
+ allow_any_instance_of(Repository).to receive(:remove_file).and_return(false)
delete api("/projects/#{project.id}/repository/files", user), valid_params
expect(response.status).to eq(400)
diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb
index 62b42d63fc2..56aa97adcc3 100644
--- a/spec/requests/api/groups_spec.rb
+++ b/spec/requests/api/groups_spec.rb
@@ -167,7 +167,8 @@ describe API::API, api: true do
describe "POST /groups/:id/projects/:project_id" do
let(:project) { create(:project) }
before(:each) do
- Projects::TransferService.any_instance.stub(execute: true)
+ allow_any_instance_of(Projects::TransferService).
+ to receive(:execute).and_return(true)
allow(Project).to receive(:find).and_return(project)
end
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index 38c67bc9971..70dd8049b12 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -301,14 +301,20 @@ describe API::API, api: true do
describe "PUT /projects/:id/merge_request/:merge_request_id/merge" do
it "should return merge_request in case of success" do
- MergeRequest.any_instance.stub(can_be_merged?: true, automerge!: true)
+ allow_any_instance_of(MergeRequest).
+ to receive_messages(can_be_merged?: true, automerge!: true)
+
put api("/projects/#{project.id}/merge_request/#{merge_request.id}/merge", user)
+
expect(response.status).to eq(200)
end
it "should return 405 if branch can't be merged" do
- MergeRequest.any_instance.stub(can_be_merged?: false)
+ allow_any_instance_of(MergeRequest).
+ to receive(:can_be_merged?).and_return(false)
+
put api("/projects/#{project.id}/merge_request/#{merge_request.id}/merge", user)
+
expect(response.status).to eq(405)
expect(json_response['message']).to eq('Branch cannot be merged')
end
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 8fb1509c8b2..401b176486d 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -121,15 +121,13 @@ describe API::API, api: true do
get api('/projects/all', admin)
expect(response.status).to eq(200)
expect(json_response).to be_an Array
- project_name = project.name
- expect(json_response.detect {
- |project| project['name'] == project_name
- }['name']).to eq(project_name)
-
- expect(json_response.detect {
- |project| project['owner']['username'] == user.username
- }['owner']['username']).to eq(user.username)
+ expect(json_response).to satisfy do |response|
+ response.one? do |entry|
+ entry['name'] == project.name &&
+ entry['owner']['username'] == user.username
+ end
+ end
end
end
end
@@ -138,9 +136,8 @@ describe API::API, api: true do
context 'maximum number of projects reached' do
it 'should not create new project and respond with 403' do
allow_any_instance_of(User).to receive(:projects_limit_left).and_return(0)
- expect {
- post api('/projects', user2), name: 'foo'
- }.to change {Project.count}.by(0)
+ expect { post api('/projects', user2), name: 'foo' }.
+ to change {Project.count}.by(0)
expect(response.status).to eq(403)
end
end