Skip to content

Commit

Permalink
Adding more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
batasha committed Mar 17, 2015
1 parent 03c173d commit bd39e7c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
5 changes: 5 additions & 0 deletions spec/fixtures/console_output1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"output" : "Test Console Output\r\nStarted by user Test User\r\n",
"size" : "1000",
"more" : true
}
5 changes: 5 additions & 0 deletions spec/fixtures/console_output2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"output" : "Finished: SUCCESS\r\n",
"size" : "2000",
"more" : null
}
11 changes: 11 additions & 0 deletions spec/git_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,15 @@
expect { create_patch "temp-patch" }.to raise_error IOError
end
end

describe '#delete_patch' do
it 'deletes the patch file' do
filename = 'tmpfile'
File.new filename, 'w'
expect(File).to exist filename

delete_patch filename
expect(File).not_to exist filename
end
end
end
22 changes: 21 additions & 1 deletion spec/jenkins_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
include Test::Drive

describe 'JenkinsClient' do

build_details = JSON.parse(File.read 'spec/fixtures/build_details.json')
output1 = JSON.parse(File.read 'spec/fixtures/console_output1.json')
output2 = JSON.parse(File.read 'spec/fixtures/console_output2.json')

let(:test_client) {
test_client = JenkinsClient.new '0.0.0.0', 'user', 'api_key'
test_client.client = instance_double JenkinsApi::Client, job: double(JenkinsApi::Client::Job)
allow(test_client.client.job).to receive(:get_build_details).and_return(JSON.parse(File.read 'spec/fixtures/build_details.json'))
allow(test_client.client.job).to receive(:get_build_details).and_return(build_details)
allow(test_client.client.job).to receive(:get_console_output).and_return(output1, output2)
test_client
}

Expand All @@ -28,4 +34,18 @@
expect { test_client.get_build_number 'TestDrive', id_hash, 10, 0 }.to raise_error
end
end

describe '#print_output' do
it 'prints Jenkins progressive console output to the terminal' do
expected_output = "Test Console Output\r\nStarted by user Test User\r\nFinished: SUCCESS\r\n"
expect { test_client.print_output 'TestDrive', 1, 0 }.to output(expected_output).to_stdout
end
end

describe '#wait_for_job_status' do
it 'returns the build result' do
build_result = test_client.wait_for_job_status 'TestDrive', 10
expect(build_result).to eq 'SUCCESS'
end
end
end

0 comments on commit bd39e7c

Please sign in to comment.