Commit 88b3195e authored by Valery Sizov's avatar Valery Sizov

fix specs. Stage 6

parent e2cbb36b
require 'spec_helper'
describe Notify do
describe Ci::Notify do
include EmailSpec::Helpers
include EmailSpec::Matchers
before do
@project = FactoryGirl.create :project
@commit = FactoryGirl.create :commit, project: @project
@build = FactoryGirl.create :build, commit: @commit
@project = FactoryGirl.create :ci_project
@commit = FactoryGirl.create :ci_commit, project: @project
@build = FactoryGirl.create :ci_build, commit: @commit
end
describe 'build success' do
subject { Notify.build_success_email(@build.id, 'wow@example.com') }
subject { Ci::Notify.build_success_email(@build.id, 'wow@example.com') }
it 'has the correct subject' do
should have_subject /Build success for/
......@@ -23,7 +23,7 @@ describe Notify do
end
describe 'build fail' do
subject { Notify.build_fail_email(@build.id, 'wow@example.com') }
subject { Ci::Notify.build_fail_email(@build.id, 'wow@example.com') }
it 'has the correct subject' do
should have_subject /Build failed for/
......
......@@ -53,13 +53,13 @@ describe Ci::HipChatService do
it "should call the HipChat API" do
service.execute(build)
HipChatNotifierWorker.drain
Ci::HipChatNotifierWorker.drain
expect( WebMock ).to have_requested(:post, api_url).once
end
it "calls the worker with expected arguments" do
expect( HipChatNotifierWorker ).to receive(:perform_async) \
expect( Ci::HipChatNotifierWorker ).to receive(:perform_async) \
.with(an_instance_of(String), hash_including(
token: 'a1b2c3d4e5f6',
room: 123,
......
......@@ -5,14 +5,14 @@ describe Ci::CreateProjectService do
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
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
......@@ -31,9 +31,9 @@ describe Ci::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
......
......@@ -13,14 +13,14 @@ describe Ci::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
......@@ -30,7 +30,7 @@ describe Ci::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
......@@ -43,9 +43,9 @@ describe Ci::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
......
......@@ -12,7 +12,7 @@ describe Ci::EventService do
it "creates event" do
EventService.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
......@@ -20,7 +20,7 @@ describe Ci::EventService do
it "creates event" do
EventService.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
......@@ -28,7 +28,7 @@ describe Ci::EventService do
it "creates event" do
EventService.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
require 'spec_helper'
describe Ci::ImageForBuildService do
module Ci
describe ImageForBuildService do
let(:service) { ImageForBuildService.new }
let(:project) { FactoryGirl.create(:project) }
let(:commit) { FactoryGirl.create(:commit, project: project, ref: 'master') }
let(:build) { FactoryGirl.create(:build, commit: commit) }
let(:project) { FactoryGirl.create(:ci_project) }
let(:commit) { FactoryGirl.create(:ci_commit, project: project, ref: 'master') }
let(:build) { FactoryGirl.create(:ci_build, commit: commit) }
describe :execute do
before { build }
......@@ -13,34 +14,35 @@ describe Ci::ImageForBuildService 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/ci/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/ci/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/ci/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/ci/build-unknown.svg') }
it { expect(image.name).to eq('build-unknown.svg') }
end
end
end
end
\ No newline at end of file
require 'spec_helper'
require 'spec_helper'
describe Ci::RegisterBuildService do
module Ci
describe RegisterBuildService do
let!(:service) { RegisterBuildService.new }
let!(:project) { FactoryGirl.create :project }
let!(:commit) { FactoryGirl.create :commit, project: project }
let!(:pending_build) { FactoryGirl.create :build, project: project, commit: commit }
let!(:shared_runner) { FactoryGirl.create(:runner, is_shared: true) }
let!(:specific_runner) { FactoryGirl.create(:runner, is_shared: false) }
let!(:project) { FactoryGirl.create :ci_project }
let!(:commit) { FactoryGirl.create :ci_commit, project: project }
let!(:pending_build) { FactoryGirl.create :ci_build, project: project, commit: commit }
let!(:shared_runner) { FactoryGirl.create(:ci_runner, is_shared: true) }
let!(:specific_runner) { FactoryGirl.create(:ci_runner, is_shared: false) }
before do
specific_runner.assign_to(project)
......@@ -18,29 +19,29 @@ describe Ci::RegisterBuildService 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
......@@ -53,19 +54,19 @@ describe Ci::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
......@@ -73,16 +74,17 @@ describe Ci::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
end
......
......@@ -9,13 +9,13 @@ describe Ci::WebHookService 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(WebHookService.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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment