Skip to content
Snippets Groups Projects
Commit fd6be573 authored by Valery Sizov's avatar Valery Sizov
Browse files

Merge branch 'rs-rspec3' into 'master'

RSpec 3

Updates CI's specs to be a bit more like CE's to make that transition a little easier.

See merge request !246
parents 305d9e20 77053a6c
No related branches found
No related tags found
No related merge requests found
Showing
with 238 additions and 240 deletions
Loading
Loading
@@ -14,7 +14,7 @@
require 'spec_helper'
 
describe Variable do
subject { Variable.new }
subject { described_class.new }
 
let(:secret_value) { 'secret' }
 
Loading
Loading
@@ -22,23 +22,24 @@ describe Variable do
subject.value = secret_value
end
 
describe :value do
describe '#value' do
it 'stores the encrypted value' do
subject.encrypted_value.should_not be_nil
expect(subject.encrypted_value).not_to be_nil
end
 
it 'stores an iv for value' do
subject.encrypted_value_iv.should_not be_nil
expect(subject.encrypted_value_iv).not_to be_nil
end
 
it 'stores a salt for value' do
subject.encrypted_value_salt.should_not be_nil
expect(subject.encrypted_value_salt).not_to be_nil
end
 
it 'fails to decrypt if iv is incorrect' do
subject.encrypted_value_iv = nil
subject.instance_variable_set(:@value, nil)
expect { subject.value }.to raise_error
expect { subject.value }.
to raise_error(OpenSSL::Cipher::CipherError, 'bad decrypt')
end
end
end
Loading
Loading
@@ -13,22 +13,22 @@ require 'spec_helper'
 
describe WebHook do
describe "Associations" do
it { should belong_to :project }
it { is_expected.to belong_to :project }
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 { 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.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 { 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
 
Loading
Loading
@@ -43,22 +43,21 @@ describe WebHook do
 
it "POSTs to the web hook URL" do
@web_hook.execute(@data)
WebMock.should have_requested(:post, @web_hook.url).once
expect(WebMock).to have_requested(:post, @web_hook.url).once
end
 
it "POSTs the data as JSON" do
json = @data.to_json
 
@web_hook.execute(@data)
WebMock.should have_requested(:post, @web_hook.url).with(body: json).once
expect(WebMock).to have_requested(:post, @web_hook.url).with(body: json).once
end
 
it "catches exceptions" do
WebHook.should_receive(:post).and_raise("Some HTTP Post error")
expect(described_class).to receive(:post).and_raise("Some HTTP Post error")
 
lambda {
@web_hook.execute(@data)
}.should raise_error
expect { @web_hook.execute(@data) }.
to raise_error(RuntimeError, 'Some HTTP Post error')
end
end
end
Loading
Loading
@@ -22,15 +22,15 @@ describe API::API do
 
post api("/builds/register"), token: runner.token, info: {platform: :darwin}
 
response.status.should == 201
json_response['sha'].should == build.sha
runner.reload.platform.should == "darwin"
expect(response.status).to eq 201
expect(json_response['sha']).to eq build.sha
expect(runner.reload.platform).to eq "darwin"
end
 
it "should return 404 error if no pending build found" do
post api("/builds/register"), token: runner.token
 
response.status.should == 404
expect(response.status).to eq 404
end
 
it "should return 404 error if no builds for specific runner" do
Loading
Loading
@@ -39,7 +39,7 @@ describe API::API do
 
post api("/builds/register"), token: runner.token
 
response.status.should == 404
expect(response.status).to eq 404
end
 
it "should return 404 error if no builds for shared runner" do
Loading
Loading
@@ -48,7 +48,7 @@ describe API::API do
 
post api("/builds/register"), token: shared_runner.token
 
response.status.should == 404
expect(response.status).to eq 404
end
 
it "returns options" do
Loading
Loading
@@ -57,8 +57,8 @@ describe API::API do
 
post api("/builds/register"), token: runner.token, info: {platform: :darwin}
 
response.status.should == 201
json_response["options"].should == {"image" => "ruby:2.1", "services" => ["postgres"]}
expect(response.status).to eq 201
expect(json_response["options"]).to eq({"image" => "ruby:2.1", "services" => ["postgres"]})
end
 
it "returns variables" do
Loading
Loading
@@ -68,8 +68,8 @@ describe API::API do
 
post api("/builds/register"), token: runner.token, info: {platform: :darwin}
 
response.status.should == 201
json_response["variables"].should == [
expect(response.status).to eq 201
expect(json_response["variables"]).to eq [
{"key" => "DB_NAME", "value" => "postgres", "public" => true},
{"key" => "SECRET_KEY", "value" => "secret_value", "public" => false},
]
Loading
Loading
@@ -85,8 +85,8 @@ describe API::API do
 
post api("/builds/register"), token: runner.token, info: {platform: :darwin}
 
response.status.should == 201
json_response["variables"].should == [
expect(response.status).to eq 201
expect(json_response["variables"]).to eq [
{"key" => "DB_NAME", "value" => "postgres", "public" => true},
{"key" => "SECRET_KEY", "value" => "secret_value", "public" => false},
{"key" => "TRIGGER_KEY", "value" => "TRIGGER_VALUE", "public" => false},
Loading
Loading
@@ -101,7 +101,7 @@ describe API::API do
it "should update a running build" do
build.run!
put api("/builds/#{build.id}"), token: runner.token
response.status.should == 200
expect(response.status).to eq 200
end
 
it 'Should not override trace information when no trace is given' do
Loading
Loading
Loading
Loading
@@ -19,10 +19,10 @@ describe API::API, 'Commits' do
it "should return commits per project" do
get api("/commits"), options
 
response.status.should == 200
json_response.count.should == 1
json_response.first["project_id"].should == project.id
json_response.first["sha"].should == commit.sha
expect(response.status).to eq 200
expect(json_response.count).to eq 1
expect(json_response.first["project_id"]).to eq project.id
expect(json_response.first["sha"]).to eq commit.sha
end
end
 
Loading
Loading
@@ -51,15 +51,15 @@ describe API::API, 'Commits' do
it "should create a build" do
post api("/commits"), options.merge(data: data)
 
response.status.should == 201
json_response['sha'].should == "da1560886d4f094c3e6c9ef40349f7d38b5d27d7"
expect(response.status).to eq 201
expect(json_response['sha']).to eq "da1560886d4f094c3e6c9ef40349f7d38b5d27d7"
end
 
it "should return 400 error if no data passed" do
post api("/commits"), options
 
response.status.should == 400
json_response['message'].should == "400 (Bad request) \"data\" not given"
expect(response.status).to eq 400
expect(json_response['message']).to eq "400 (Bad request) \"data\" not given"
end
end
end
Loading
Loading
@@ -41,8 +41,8 @@ describe API::API do
 
it "should create a project with valid data" do
post api("/forks"), options
response.status.should == 201
json_response['name'].should == "Gitlab.org / Underscore"
expect(response.status).to eq 201
expect(json_response['name']).to eq "Gitlab.org / Underscore"
end
end
 
Loading
Loading
@@ -53,7 +53,7 @@ describe API::API do
 
it "should error with invalid data" do
post api("/forks"), options
response.status.should == 400
expect(response.status).to eq 400
end
end
end
Loading
Loading
Loading
Loading
@@ -25,10 +25,10 @@ describe API::API do
 
it "should return all projects on the CI instance" do
get api("/projects"), options
response.status.should == 200
json_response.count.should == 2
json_response.first["id"].should == project1.id
json_response.last["id"].should == project2.id
expect(response.status).to eq 200
expect(json_response.count).to eq 2
expect(json_response.first["id"]).to eq project1.id
expect(json_response.last["id"]).to eq project2.id
end
end
 
Loading
Loading
@@ -40,8 +40,8 @@ describe API::API do
it "should return all projects on the CI instance" do
get api("/projects/owned"), options
 
response.status.should == 200
json_response.count.should == 0
expect(response.status).to eq 200
expect(json_response.count).to eq 0
end
end
end
Loading
Loading
@@ -58,19 +58,19 @@ describe API::API do
 
it "should create webhook for specified project" do
post api("/projects/#{project.id}/webhooks"), options
response.status.should == 201
json_response["url"].should == webhook[:web_hook]
expect(response.status).to eq 201
expect(json_response["url"]).to eq webhook[:web_hook]
end
 
it "fails to create webhook for non existsing project" do
post api("/projects/non-existant-id/webhooks"), options
response.status.should == 404
expect(response.status).to eq 404
end
 
it "non-manager is not authorized" do
User.any_instance.stub(:can_manage_project?).and_return(false)
allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
post api("/projects/#{project.id}/webhooks"), options
response.status.should == 401
expect(response.status).to eq 401
end
end
 
Loading
Loading
@@ -83,14 +83,14 @@ describe API::API do
 
it "fails to create webhook for not valid url" do
post api("/projects/#{project.id}/webhooks"), options
response.status.should == 400
expect(response.status).to eq 400
end
end
 
context "Missed web_hook parameter" do
it "fails to create webhook for not provided url" do
post api("/projects/#{project.id}/webhooks"), options
response.status.should == 400
expect(response.status).to eq 400
end
end
end
Loading
Loading
@@ -101,15 +101,15 @@ describe API::API do
context "with an existing project" do
it "should retrieve the project info" do
get api("/projects/#{project.id}"), options
response.status.should == 200
json_response['id'].should == project.id
expect(response.status).to eq 200
expect(json_response['id']).to eq project.id
end
end
 
context "with a non-existing project" do
it "should return 404 error if project not found" do
get api("/projects/non_existent_id"), options
response.status.should == 404
expect(response.status).to eq 404
end
end
end
Loading
Loading
@@ -124,19 +124,19 @@ describe API::API do
 
it "should update a specific project's information" do
put api("/projects/#{project.id}"), options
response.status.should == 200
json_response["name"].should == project_info[:name]
expect(response.status).to eq 200
expect(json_response["name"]).to eq project_info[:name]
end
 
it "fails to update a non-existing project" do
put api("/projects/non-existant-id"), options
response.status.should == 404
expect(response.status).to eq 404
end
 
it "non-manager is not authorized" do
User.any_instance.stub(:can_manage_project?).and_return(false)
allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
put api("/projects/#{project.id}"), options
response.status.should == 401
expect(response.status).to eq 401
end
end
 
Loading
Loading
@@ -145,20 +145,20 @@ describe API::API do
 
it "should delete a specific project" do
delete api("/projects/#{project.id}"), options
response.status.should == 200
expect(response.status).to eq 200
 
expect { project.reload }.to raise_error
expect { project.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
 
it "non-manager is not authorized" do
User.any_instance.stub(:can_manage_project?).and_return(false)
allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
delete api("/projects/#{project.id}"), options
response.status.should == 401
expect(response.status).to eq 401
end
 
it "is getting not found error" do
delete api("/projects/not-existing_id"), options
response.status.should == 404
expect(response.status).to eq 404
end
end
 
Loading
Loading
@@ -181,8 +181,8 @@ describe API::API do
 
it "should create a project with valid data" do
post api("/projects"), options
response.status.should == 201
json_response['name'].should == project_info[:name]
expect(response.status).to eq 201
expect(json_response['name']).to eq project_info[:name]
end
end
 
Loading
Loading
@@ -193,7 +193,7 @@ describe API::API do
 
it "should error with invalid data" do
post api("/projects"), options
response.status.should == 400
expect(response.status).to eq 400
end
end
 
Loading
Loading
@@ -203,24 +203,24 @@ describe API::API do
 
it "should add the project to the runner" do
post api("/projects/#{project.id}/runners/#{runner.id}"), options
response.status.should == 201
expect(response.status).to eq 201
 
project.reload
project.runners.first.id.should == runner.id
expect(project.runners.first.id).to eq runner.id
end
 
it "should fail if it tries to link a non-existing project or runner" do
post api("/projects/#{project.id}/runners/non-existing"), options
response.status.should == 404
expect(response.status).to eq 404
 
post api("/projects/non-existing/runners/#{runner.id}"), options
response.status.should == 404
expect(response.status).to eq 404
end
 
it "non-manager is not authorized" do
User.any_instance.stub(:can_manage_project?).and_return(false)
allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
post api("/projects/#{project.id}/runners/#{runner.id}"), options
response.status.should == 401
expect(response.status).to eq 401
end
end
 
Loading
Loading
@@ -233,18 +233,18 @@ describe API::API do
end
 
it "should remove the project from the runner" do
project.runners.should be_present
expect(project.runners).to be_present
delete api("/projects/#{project.id}/runners/#{runner.id}"), options
response.status.should == 200
expect(response.status).to eq 200
 
project.reload
project.runners.should be_empty
expect(project.runners).to be_empty
end
 
it "non-manager is not authorized" do
User.any_instance.stub(:can_manage_project?).and_return(false)
allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
post api("/projects/#{project.id}/runners/#{runner.id}"), options
response.status.should == 401
expect(response.status).to eq 401
end
end
end
Loading
Loading
Loading
Loading
@@ -24,10 +24,10 @@ describe API::API do
 
it "should retrieve a list of all runners" do
get api("/runners"), options
response.status.should == 200
json_response.count.should == 5
json_response.last.should have_key("id")
json_response.last.should have_key("token")
expect(response.status).to eq 200
expect(json_response.count).to eq 5
expect(json_response.last).to have_key("id")
expect(json_response.last).to have_key("token")
end
end
 
Loading
Loading
@@ -35,41 +35,41 @@ describe API::API do
describe "should create a runner if token provided" do
before { post api("/runners/register"), token: GitlabCi::REGISTRATION_TOKEN }
 
it { response.status.should == 201 }
it { expect(response.status).to eq 201 }
end
 
describe "should create a runner with description" do
before { post api("/runners/register"), token: GitlabCi::REGISTRATION_TOKEN, description: "server.hostname" }
 
it { response.status.should == 201 }
it { Runner.first.description.should == "server.hostname" }
it { expect(response.status).to eq 201 }
it { expect(Runner.first.description).to eq "server.hostname" }
end
 
describe "should create a runner with tags" do
before { post api("/runners/register"), token: GitlabCi::REGISTRATION_TOKEN, tag_list: "tag1, tag2" }
 
it { response.status.should == 201 }
it { Runner.first.tag_list.sort.should == ["tag1", "tag2"] }
it { expect(response.status).to eq 201 }
it { expect(Runner.first.tag_list.sort).to eq ["tag1", "tag2"] }
end
 
describe "should create a runner if project token provided" do
let(:project) { FactoryGirl.create(:project) }
before { post api("/runners/register"), token: project.token }
 
it { response.status.should == 201 }
it { project.runners.size.should == 1 }
it { expect(response.status).to eq 201 }
it { expect(project.runners.size).to eq 1 }
end
 
it "should return 403 error if token is invalid" do
post api("/runners/register"), token: 'invalid'
 
response.status.should == 403
expect(response.status).to eq 403
end
 
it "should return 400 error if no token" do
post api("/runners/register")
 
response.status.should == 400
expect(response.status).to eq 400
end
end
 
Loading
Loading
@@ -77,7 +77,7 @@ describe API::API do
let!(:runner) { FactoryGirl.create(:runner) }
before { delete api("/runners/delete"), token: runner.token }
 
it { response.status.should == 200 }
it { Runner.count.should == 0 }
it { expect(response.status).to eq 200 }
it { expect(Runner.count).to eq 0 }
end
end
Loading
Loading
@@ -17,17 +17,17 @@ describe API::API do
context 'Handles errors' do
it 'should return bad request if token is missing' do
post api("/projects/#{project.id}/refs/master/trigger")
response.status.should == 400
expect(response.status).to eq 400
end
 
it 'should return not found if project is not found' do
post api('/projects/0/refs/master/trigger'), options
response.status.should == 404
expect(response.status).to eq 404
end
 
it 'should return unauthorized if token is for different project' do
post api("/projects/#{project2.id}/refs/master/trigger"), options
response.status.should == 401
expect(response.status).to eq 401
end
end
 
Loading
Loading
@@ -38,15 +38,15 @@ describe API::API do
 
it 'should create builds' do
post api("/projects/#{project.id}/refs/master/trigger"), options
response.status.should == 201
expect(response.status).to eq 201
@commit.builds.reload
@commit.builds.size.should == 2
expect(@commit.builds.size).to eq 2
end
 
it 'should return bad request with no builds created if there\'s no commit for that ref' do
post api("/projects/#{project.id}/refs/other-branch/trigger"), options
response.status.should == 400
json_response['message'].should == 'No builds created'
expect(response.status).to eq 400
expect(json_response['message']).to eq 'No builds created'
end
 
context 'Validates variables' do
Loading
Loading
@@ -56,21 +56,21 @@ describe API::API do
 
it 'should validate variables to be a hash' do
post api("/projects/#{project.id}/refs/master/trigger"), options.merge(variables: 'value')
response.status.should == 400
json_response['message'].should == 'variables needs to be a hash'
expect(response.status).to eq 400
expect(json_response['message']).to eq 'variables needs to be a hash'
end
 
it 'should validate variables needs to be a map of key-valued strings' do
post api("/projects/#{project.id}/refs/master/trigger"), options.merge(variables: {key: %w(1 2)})
response.status.should == 400
json_response['message'].should == 'variables needs to be a map of key-valued strings'
expect(response.status).to eq 400
expect(json_response['message']).to eq 'variables needs to be a map of key-valued strings'
end
 
it 'create trigger request with variables' do
post api("/projects/#{project.id}/refs/master/trigger"), options.merge(variables: variables)
response.status.should == 201
expect(response.status).to eq 201
@commit.builds.reload
@commit.builds.first.trigger_request.variables.should == variables
expect(@commit.builds.first.trigger_request.variables).to eq variables
end
end
end
Loading
Loading
Loading
Loading
@@ -12,7 +12,7 @@ describe "Builds" do
get status_project_build_path(@project, @build), format: :json
end
 
it { response.status.should == 200 }
it { response.body.should include(@build.sha) }
it { expect(response.status).to eq 200 }
it { expect(response.body).to include(@build.sha) }
end
end
Loading
Loading
@@ -11,7 +11,7 @@ describe "Commits" do
get status_project_ref_commit_path(@project, @commit.ref, @commit.sha), format: :json
end
 
it { response.status.should == 200 }
it { response.body.should include(@commit.sha) }
it { expect(response.status).to eq 200 }
it { expect(response.body).to include(@commit.sha) }
end
end
require 'spec_helper'
 
describe CreateCommitService do
let(:service) { CreateCommitService.new }
let(:service) { described_class.new }
let(:project) { FactoryGirl.create(:project) }
describe :execute do
describe '#execute' do
context 'valid params' do
let(:commit) do
service.execute(project,
Loading
Loading
@@ -16,11 +16,11 @@ describe CreateCommitService do
)
end
 
it { commit.should be_kind_of(Commit) }
it { commit.should be_valid }
it { commit.should be_persisted }
it { commit.should == project.commits.last }
it { commit.builds.first.should be_kind_of(Build) }
it { expect(commit).to be_kind_of(Commit) }
it { expect(commit).to be_valid }
it { expect(commit).to be_persisted }
it { expect(commit).to eq project.commits.last }
it { expect(commit.builds.first).to be_kind_of(Build) }
end
 
context "skip tag if there is no build for it" do
Loading
Loading
@@ -32,7 +32,7 @@ describe CreateCommitService do
ci_yaml_file: gitlab_ci_yaml,
commits: [ { message: "Message" } ]
)
result.should be_persisted
expect(result).to be_persisted
end
 
it "creates commit if there is no appropriate job but deploy job has right ref setting" do
Loading
Loading
@@ -45,11 +45,11 @@ describe CreateCommitService do
ci_yaml_file: config,
commits: [ { message: "Message" } ]
)
result.should be_persisted
expect(result).to be_persisted
end
end
 
describe :ci_skip? do
describe '#ci_skip?' do
it "skips builds creation if there is [ci skip] tag in commit message" do
commits = [{message: "some message[ci skip]"}]
commit = service.execute(project,
Loading
Loading
@@ -59,8 +59,8 @@ describe CreateCommitService do
commits: commits,
ci_yaml_file: gitlab_ci_yaml
)
commit.builds.any?.should be_false
commit.status.should == "skipped"
expect(commit.builds.any?).to be_falsey
expect(commit.status).to eq "skipped"
end
 
it "does not skips builds creation if there is no [ci skip] tag in commit message" do
Loading
Loading
@@ -74,7 +74,7 @@ describe CreateCommitService do
ci_yaml_file: gitlab_ci_yaml
)
commit.builds.first.name.should == "staging"
expect(commit.builds.first.name).to eq "staging"
end
 
it "skips builds creation if there is [ci skip] tag in commit message and yaml is invalid" do
Loading
Loading
@@ -86,8 +86,8 @@ describe CreateCommitService do
commits: commits,
ci_yaml_file: "invalid: file"
)
commit.builds.any?.should be_false
commit.status.should == "skipped"
expect(commit.builds.any?).to be_falsey
expect(commit.status).to eq "skipped"
end
end
 
Loading
Loading
@@ -100,7 +100,7 @@ describe CreateCommitService do
commits: commits,
ci_yaml_file: gitlab_ci_yaml
)
commit.builds.count(:all).should == 2
expect(commit.builds.count(:all)).to eq 2
 
commit = service.execute(project,
ref: 'refs/heads/master',
Loading
Loading
@@ -109,7 +109,7 @@ describe CreateCommitService do
commits: commits,
ci_yaml_file: gitlab_ci_yaml
)
commit.builds.count(:all).should == 2
expect(commit.builds.count(:all)).to eq 2
end
 
it "creates commit with failed status if yaml is invalid" do
Loading
Loading
@@ -123,8 +123,8 @@ describe CreateCommitService do
ci_yaml_file: "invalid: file"
)
 
commit.status.should == "failed"
commit.builds.any?.should be_false
expect(commit.status).to eq "failed"
expect(commit.builds.any?).to be_falsey
end
end
end
require 'spec_helper'
 
describe CreateProjectService do
let(:service) { CreateProjectService.new }
let(:service) { described_class.new }
let(:current_user) { double.as_null_object }
let(:project_dump) { YAML.load File.read(Rails.root.join('spec/support/gitlab_stubs/raw_project.yml')) }
 
before { Network.any_instance.stub(enable_ci: true) }
before { allow_any_instance_of(Network).to receive_messages(enable_ci: true) }
 
describe :execute do
describe '#execute' do
context 'valid params' do
let(:project) { service.execute(current_user, project_dump, 'http://localhost/projects/:project_id') }
 
it { project.should be_kind_of(Project) }
it { project.should be_persisted }
it { expect(project).to be_kind_of(Project) }
it { expect(project).to be_persisted }
end
 
context 'without project dump' do
it 'should raise exception' do
expect { service.execute(current_user, '', '') }.to raise_error
expect { service.execute(current_user, '', '') }.
to raise_error(NoMethodError)
end
end
 
Loading
Loading
@@ -31,9 +32,9 @@ describe CreateProjectService do
 
project = service.execute(current_user, project_dump, 'http://localhost/projects/:project_id', origin_project)
 
project.shared_runners_enabled.should be_true
project.public.should be_true
project.allow_git_fetch.should be_true
expect(project.shared_runners_enabled).to be_truthy
expect(project.public).to be_truthy
expect(project.allow_git_fetch).to be_truthy
end
end
end
Loading
Loading
require 'spec_helper'
 
describe CreateTriggerRequestService do
let(:service) { CreateTriggerRequestService.new }
let(:service) { described_class.new }
let(:project) { FactoryGirl.create :project }
let(:trigger) { FactoryGirl.create :trigger, project: project }
 
describe :execute do
describe '#execute' do
context 'valid params' do
subject { service.execute(project, trigger, 'master') }
 
Loading
Loading
@@ -13,14 +13,14 @@ describe CreateTriggerRequestService do
@commit = FactoryGirl.create :commit, project: project
end
 
it { subject.should be_kind_of(TriggerRequest) }
it { subject.commit.should == @commit }
it { expect(subject).to be_kind_of(TriggerRequest) }
it { expect(subject.commit).to eq @commit }
end
 
context 'no commit for ref' do
subject { service.execute(project, trigger, 'other-branch') }
 
it { subject.should be_nil }
it { expect(subject).to be_nil }
end
 
context 'no builds created' do
Loading
Loading
@@ -30,7 +30,7 @@ describe CreateTriggerRequestService do
FactoryGirl.create :commit_without_jobs, project: project
end
 
it { subject.should be_nil }
it { expect(subject).to be_nil }
end
 
context 'for multiple commits' do
Loading
Loading
@@ -43,9 +43,9 @@ describe CreateTriggerRequestService do
end
 
context 'retries latest one' do
it { subject.should be_kind_of(TriggerRequest) }
it { subject.should be_persisted }
it { subject.commit.should == @commit2 }
it { expect(subject).to be_kind_of(TriggerRequest) }
it { expect(subject).to be_persisted }
it { expect(subject.commit).to eq @commit2 }
end
end
end
Loading
Loading
Loading
Loading
@@ -8,27 +8,27 @@ describe EventService do
Event.destroy_all
end
describe :remove_project do
describe '#remove_project' do
it "creates event" do
EventService.new.remove_project(user, project)
described_class.new.remove_project(user, project)
 
Event.admin.last.description.should == "Project \"GitLab / gitlab-shell\" has been removed by root"
expect(Event.admin.last.description).to eq "Project \"GitLab / gitlab-shell\" has been removed by root"
end
end
 
describe :create_project do
describe '#create_project' do
it "creates event" do
EventService.new.create_project(user, project)
described_class.new.create_project(user, project)
 
Event.admin.last.description.should == "Project \"GitLab / gitlab-shell\" has been created by root"
expect(Event.admin.last.description).to eq "Project \"GitLab / gitlab-shell\" has been created by root"
end
end
 
describe :change_project_settings do
describe '#change_project_settings' do
it "creates event" do
EventService.new.change_project_settings(user, project)
described_class.new.change_project_settings(user, project)
 
Event.last.description.should == "User \"root\" updated projects settings"
expect(Event.last.description).to eq "User \"root\" updated projects settings"
end
end
end
\ No newline at end of file
end
require 'spec_helper'
 
describe ImageForBuildService do
let(:service) { ImageForBuildService.new }
let(:service) { described_class.new }
let(:project) { FactoryGirl.create(:project) }
let(:commit) { FactoryGirl.create(:commit, project: project, ref: 'master') }
let(:build) { FactoryGirl.create(:build, commit: commit) }
 
describe :execute do
describe '#execute' do
before { build }
 
context 'branch name' do
before { build.run! }
let(:image) { service.execute(project, ref: 'master') }
 
it { image.should be_kind_of(OpenStruct) }
it { image.path.to_s.should include('public/build-running.svg') }
it { image.name.should == 'build-running.svg' }
it { expect(image).to be_kind_of(OpenStruct) }
it { expect(image.path.to_s).to include('public/build-running.svg') }
it { expect(image.name).to eq 'build-running.svg' }
end
 
context 'unknown branch name' do
let(:image) { service.execute(project, ref: 'feature') }
 
it { image.should be_kind_of(OpenStruct) }
it { image.path.to_s.should include('public/build-unknown.svg') }
it { image.name.should == 'build-unknown.svg' }
it { expect(image).to be_kind_of(OpenStruct) }
it { expect(image.path.to_s).to include('public/build-unknown.svg') }
it { expect(image.name).to eq 'build-unknown.svg' }
end
 
context 'commit sha' do
before { build.run! }
let(:image) { service.execute(project, sha: build.sha) }
 
it { image.should be_kind_of(OpenStruct) }
it { image.path.to_s.should include('public/build-running.svg') }
it { image.name.should == 'build-running.svg' }
it { expect(image).to be_kind_of(OpenStruct) }
it { expect(image.path.to_s).to include('public/build-running.svg') }
it { expect(image.name).to eq 'build-running.svg' }
end
 
context 'unknown commit sha' do
let(:image) { service.execute(project, sha: '0000000') }
 
it { image.should be_kind_of(OpenStruct) }
it { image.path.to_s.should include('public/build-unknown.svg') }
it { image.name.should == 'build-unknown.svg' }
it { expect(image).to be_kind_of(OpenStruct) }
it { expect(image.path.to_s).to include('public/build-unknown.svg') }
it { expect(image.name).to eq 'build-unknown.svg' }
end
end
end
require 'spec_helper'
 
describe RegisterBuildService do
let!(:service) { RegisterBuildService.new }
let!(:service) { described_class.new }
let!(:project) { FactoryGirl.create :project }
let!(:commit) { FactoryGirl.create :commit, project: project }
let!(:pending_build) { FactoryGirl.create :build, project: project, commit: commit }
Loading
Loading
@@ -12,35 +12,35 @@ describe RegisterBuildService do
specific_runner.assign_to(project)
end
 
describe :execute do
describe '#execute' do
context 'runner follow tag list' do
it "picks build with the same tag" do
pending_build.tag_list = ["linux"]
pending_build.save
specific_runner.tag_list = ["linux"]
service.execute(specific_runner).should == pending_build
expect(service.execute(specific_runner)).to eq pending_build
end
 
it "does not pick build with different tag" do
pending_build.tag_list = ["linux"]
pending_build.save
specific_runner.tag_list = ["win32"]
service.execute(specific_runner).should be_false
expect(service.execute(specific_runner)).to be_falsey
end
 
it "picks build without tag" do
service.execute(specific_runner).should == pending_build
expect(service.execute(specific_runner)).to eq pending_build
end
 
it "does not pick build with tag" do
pending_build.tag_list = ["linux"]
pending_build.save
service.execute(specific_runner).should be_false
expect(service.execute(specific_runner)).to be_falsey
end
 
it "pick build without tag" do
specific_runner.tag_list = ["win32"]
service.execute(specific_runner).should == pending_build
expect(service.execute(specific_runner)).to eq pending_build
end
end
 
Loading
Loading
@@ -53,19 +53,19 @@ describe RegisterBuildService do
context 'shared runner' do
let(:build) { service.execute(shared_runner) }
 
it { build.should be_kind_of(Build) }
it { build.should be_valid }
it { build.should be_running }
it { build.runner.should == shared_runner }
it { expect(build).to be_kind_of(Build) }
it { expect(build).to be_valid }
it { expect(build).to be_running }
it { expect(build.runner).to eq shared_runner }
end
 
context 'specific runner' do
let(:build) { service.execute(specific_runner) }
 
it { build.should be_kind_of(Build) }
it { build.should be_valid }
it { build.should be_running }
it { build.runner.should == specific_runner }
it { expect(build).to be_kind_of(Build) }
it { expect(build).to be_valid }
it { expect(build).to be_running }
it { expect(build.runner).to eq specific_runner }
end
end
 
Loading
Loading
@@ -73,16 +73,16 @@ describe RegisterBuildService do
context 'shared runner' do
let(:build) { service.execute(shared_runner) }
 
it { build.should be_nil }
it { expect(build).to be_nil }
end
 
context 'specific runner' do
let(:build) { service.execute(specific_runner) }
 
it { build.should be_kind_of(Build) }
it { build.should be_valid }
it { build.should be_running }
it { build.runner.should == specific_runner }
it { expect(build).to be_kind_of(Build) }
it { expect(build).to be_valid }
it { expect(build).to be_running }
it { expect(build.runner).to eq specific_runner }
end
end
end
Loading
Loading
Loading
Loading
@@ -6,16 +6,16 @@ describe WebHookService do
let (:build) { FactoryGirl.create :build, commit: commit }
let (:hook) { FactoryGirl.create :web_hook, project: project }
 
describe :execute do
describe '#execute' do
it "should execute successfully" do
stub_request(:post, hook.url).to_return(status: 200)
WebHookService.new.build_end(build).should be_true
expect(described_class.new.build_end(build)).to be_truthy
end
end
 
context 'build_data' do
it "contains all needed fields" do
build_data(build).should include(
expect(build_data(build)).to include(
:build_id,
:project_id,
:ref,
Loading
Loading
@@ -31,6 +31,6 @@ describe WebHookService do
end
 
def build_data(build)
WebHookService.new.send :build_data, build
described_class.new.send :build_data, build
end
end
Loading
Loading
@@ -9,52 +9,28 @@ if ENV['COVERALLS']
end
 
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'shoulda/matchers'
require 'sidekiq/testing/inline'
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
Capybara.default_wait_time = 10
 
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
 
require 'webmock/rspec'
WebMock.disable_net_connect!(allow_localhost: true)
RSpec.configure do |config|
config.include LoginHelpers, type: :feature
config.use_transactional_fixtures = false
config.use_instantiated_fixtures = false
config.mock_with :rspec
 
config.include LoginHelpers, type: :feature
config.include LoginHelpers, type: :request
config.include StubGitlabCalls
config.include StubGitlabData
 
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = false
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
config.infer_spec_type_from_file_location!
config.raise_errors_for_deprecations!
end
ActiveRecord::Migration.maintain_test_schema!
require 'capybara/rails'
require 'capybara/rspec'
require 'capybara/poltergeist'
# Give CI some extra time
timeout = (ENV['CI'] || ENV['CI_SERVER']) ? 90 : 10
Capybara.javascript_driver = :poltergeist
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, js_errors: true, timeout: timeout)
end
Capybara.default_wait_time = timeout
Capybara.ignore_hidden_elements = true
unless ENV['CI'] || ENV['CI_SERVER']
require 'capybara-screenshot/rspec'
# Keep only the screenshots generated from the last failing test suite
Capybara::Screenshot.prune_strategy = :keep_last_run
end
Loading
Loading
@@ -17,6 +17,6 @@ module LoginHelpers
end
 
def skip_admin_auth
ApplicationController.any_instance.stub(authenticate_admin!: true)
allow_any_instance_of(ApplicationController).to receive_messages(authenticate_admin!: true)
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment