diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/project_services/hip_chat_message_spec.rb | 65 | ||||
-rw-r--r-- | spec/models/project_services/hip_chat_service_spec.rb | 15 |
2 files changed, 79 insertions, 1 deletions
diff --git a/spec/models/project_services/hip_chat_message_spec.rb b/spec/models/project_services/hip_chat_message_spec.rb new file mode 100644 index 0000000..6096b5c --- /dev/null +++ b/spec/models/project_services/hip_chat_message_spec.rb @@ -0,0 +1,65 @@ +require 'spec_helper' + +describe HipChatMessage do + subject { HipChatMessage.new(build) } + + let(:project) { FactoryGirl.create(:project) } + let(:commit) { FactoryGirl.create(:commit, project: project) } + let(:job) { FactoryGirl.create(:job, project: project) } + let(:build) { FactoryGirl.create(:build, commit: commit, job: job, status: 'success') } + + context 'when build succeeds' do + + before { build.save } + + it 'returns a successful message' do + expect( subject.status_color ).to eq 'green' + expect( subject.notify? ).to be_false + expect( subject.to_s ).to match(/Build '[^']+' #\d+/) + expect( subject.to_s ).to match(/Successful in \d+ second\(s\)\./) + end + end + + context 'when build fails' do + + before do + build.status = 'failed' + build.save + end + + it 'returns a failure message' do + expect( subject.status_color ).to eq 'red' + expect( subject.notify? ).to be_true + expect( subject.to_s ).to match(/Build '[^']+' #\d+/) + expect( subject.to_s ).to match(/Failed in \d+ second\(s\)\./) + end + end + + context 'when all matrix builds succeed' do + let(:job2) { FactoryGirl.create(:job, project: project, name: 'Another Job') } + let(:build2) { FactoryGirl.create(:build, id: 10, commit: commit, job: job2, status: 'success') } + + before { build.save; build2.save } + + it 'returns a successful message' do + expect( subject.status_color ).to eq 'green' + expect( subject.notify? ).to be_false + expect( subject.to_s ).to match(/Commit #\d+/) + expect( subject.to_s ).to match(/Successful in \d+ second\(s\)\./) + end + end + + context 'when at least one matrix build fails' do + let(:job2) { FactoryGirl.create(:job, project: project, name: 'Another Job') } + let(:build2) { FactoryGirl.create(:build, id: 10, commit: commit, job: job2, status: 'failed') } + + before { build.save; build2.save } + + it 'returns a failure message' do + expect( subject.status_color ).to eq 'red' + expect( subject.notify? ).to be_true + expect( subject.to_s ).to match(/Commit #\d+/) + expect( subject.to_s ).to match(/Failed in \d+ second\(s\)\./) + end + end +end diff --git a/spec/models/project_services/hip_chat_service_spec.rb b/spec/models/project_services/hip_chat_service_spec.rb index e578461..5642221 100644 --- a/spec/models/project_services/hip_chat_service_spec.rb +++ b/spec/models/project_services/hip_chat_service_spec.rb @@ -41,7 +41,20 @@ describe HipChatService do service.execute(build) HipChatNotifierWorker.drain - WebMock.should have_requested(:post, api_url).once + expect( WebMock ).to have_requested(:post, api_url).once + end + + it "calls the worker with expected arguments" do + expect( HipChatNotifierWorker ).to receive(:perform_async) \ + .with(an_instance_of(String), hash_including( + token: 'a1b2c3d4e5f6', + room: 123, + server: 'https://api.hipchat.com', + color: 'red', + notify: true + )) + + service.execute(build) end end end |