packaging 0.108.1 → 0.109.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -2
  3. data/lib/packaging/artifactory.rb +15 -10
  4. data/lib/packaging/config/validations.rb +1 -1
  5. data/lib/packaging/config.rb +5 -5
  6. data/lib/packaging/deb/repo.rb +4 -4
  7. data/lib/packaging/nuget.rb +1 -1
  8. data/lib/packaging/paths.rb +4 -3
  9. data/lib/packaging/rpm/repo.rb +26 -8
  10. data/lib/packaging/sign/msi.rb +6 -8
  11. data/lib/packaging/sign/rpm.rb +8 -6
  12. data/lib/packaging/util/execution.rb +1 -1
  13. data/lib/packaging/util/ezbake.rb +1 -1
  14. data/lib/packaging/util/file.rb +4 -6
  15. data/lib/packaging/util/net.rb +8 -12
  16. data/lib/packaging/util/ship.rb +17 -7
  17. data/lib/packaging/util/tool.rb +1 -1
  18. data/lib/packaging/util/version.rb +7 -5
  19. data/spec/lib/packaging/config_spec.rb +300 -279
  20. data/spec/lib/packaging/deb/repo_spec.rb +138 -76
  21. data/spec/lib/packaging/deb_spec.rb +28 -25
  22. data/spec/lib/packaging/repo_spec.rb +52 -31
  23. data/spec/lib/packaging/rpm/repo_spec.rb +109 -71
  24. data/spec/lib/packaging/sign_spec.rb +22 -43
  25. data/spec/lib/packaging/tar_spec.rb +48 -44
  26. data/spec/lib/packaging/util/execution_spec.rb +32 -32
  27. data/spec/lib/packaging/util/file_spec.rb +112 -75
  28. data/spec/lib/packaging/util/gpg_spec.rb +24 -19
  29. data/spec/lib/packaging/util/jenkins_spec.rb +79 -48
  30. data/spec/lib/packaging/util/misc_spec.rb +13 -8
  31. data/spec/lib/packaging/util/net_spec.rb +193 -152
  32. data/spec/lib/packaging/util/rake_utils_spec.rb +24 -18
  33. data/spec/lib/packaging_spec.rb +7 -9
  34. data/tasks/apple.rake +7 -8
  35. data/tasks/deb.rake +1 -1
  36. data/tasks/fetch.rake +2 -2
  37. data/tasks/mock.rake +3 -3
  38. data/tasks/nightly_repos.rake +11 -9
  39. data/tasks/rpm.rake +2 -3
  40. data/tasks/ship.rake +4 -2
  41. data/tasks/sign.rake +8 -10
  42. data/tasks/z_data_dump.rake +3 -3
  43. metadata +48 -35
@@ -1,112 +1,146 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Pkg::Util::File" do
4
- let(:source) { "/tmp/placething.tar.gz" }
5
- let(:target) { "/tmp" }
6
- let(:options) { "--thing-for-tar" }
7
- let(:tar) { "/usr/bin/tar" }
8
- let(:files) { ["foo.rb", "foo/bar.rb"] }
9
- let(:symlinks) { ["bar.rb"] }
10
- let(:dirs) { ["foo"] }
11
- let(:empty_dirs) { ["bar"] }
12
-
13
-
14
- describe "#untar_into" do
3
+ describe 'Pkg::Util::File' do
4
+ let(:source) { '/tmp/placething.tar.gz' }
5
+ let(:target) { '/tmp' }
6
+ let(:options) { '--thing-for-tar' }
7
+ let(:tar) { '/usr/bin/tar' }
8
+ let(:files) { ['foo.rb', 'foo/bar.rb'] }
9
+ let(:symlinks) { ['bar.rb'] }
10
+ let(:dirs) { ['foo'] }
11
+ let(:empty_dirs) { ['bar'] }
12
+
13
+
14
+ describe '#untar_into' do
15
15
  before :each do
16
- Pkg::Util::Tool.stub(:find_tool).with('tar', :required => true) { tar }
16
+ allow(Pkg::Util::Tool)
17
+ .to receive(:find_tool)
18
+ .with('tar', required: true)
19
+ .and_return(tar)
17
20
  end
18
21
 
19
- it "raises an exception if the source doesn't exist" do
20
- Pkg::Util::File.should_receive(:file_exists?).with(source, {:required => true}).and_raise(RuntimeError)
21
- Pkg::Util::Execution.should_not_receive(:capture3)
22
+ it 'raises an exception if the source doesn\'t exist' do
23
+ expect(Pkg::Util::File)
24
+ .to receive(:file_exists?)
25
+ .with(source, { required: true })
26
+ .and_raise(RuntimeError)
27
+ expect(Pkg::Util::Execution).not_to receive(:capture3)
22
28
  expect { Pkg::Util::File.untar_into(source) }.to raise_error(RuntimeError)
23
29
  end
24
30
 
25
- it "unpacks the tarball to the current directory if no target is passed" do
26
- Pkg::Util::File.should_receive(:file_exists?).with(source, {:required => true}) { true }
27
- Pkg::Util::Execution.should_receive(:capture3).with("#{tar} -xf #{source}")
31
+ it 'unpacks the tarball to the current directory if no target is passed' do
32
+ expect(Pkg::Util::File)
33
+ .to receive(:file_exists?)
34
+ .with(source, { required: true }) { true }
35
+ expect(Pkg::Util::Execution)
36
+ .to receive(:capture3)
37
+ .with("#{tar} -xf #{source}")
28
38
  Pkg::Util::File.untar_into(source)
29
39
  end
30
40
 
31
- it "unpacks the tarball to the current directory with options if no target is passed" do
32
- Pkg::Util::File.should_receive(:file_exists?).with(source, {:required => true}) { true }
33
- Pkg::Util::Execution.should_receive(:capture3).with("#{tar} #{options} -xf #{source}")
41
+ it 'unpacks the tarball to the current directory with options if no target is passed' do
42
+ expect(Pkg::Util::File)
43
+ .to receive(:file_exists?)
44
+ .with(source, { required: true }) { true }
45
+ expect(Pkg::Util::Execution)
46
+ .to receive(:capture3)
47
+ .with("#{tar} #{options} -xf #{source}")
34
48
  Pkg::Util::File.untar_into(source, nil, options)
35
49
  end
36
50
 
37
- it "unpacks the tarball into the target" do
38
- File.stub(:capture3ist?).with(source) { true }
39
- Pkg::Util::File.should_receive(:file_exists?).with(source, {:required => true}) { true }
40
- Pkg::Util::File.should_receive(:file_writable?).with(target) { true }
41
- Pkg::Util::Execution.should_receive(:capture3).with("#{tar} -C #{target} -xf #{source}")
51
+ it 'unpacks the tarball into the target' do
52
+ allow(File).to receive(:capture3ist?).with(source).and_return(true)
53
+ expect(Pkg::Util::File).to receive(:file_exists?).with(source, { required: true }) { true }
54
+ expect(Pkg::Util::File).to receive(:file_writable?).with(target) { true }
55
+ expect(Pkg::Util::Execution).to receive(:capture3).with("#{tar} -C #{target} -xf #{source}")
42
56
  Pkg::Util::File.untar_into(source, target)
43
57
  end
44
58
 
45
59
  it "unpacks the tarball into the target with options passed" do
46
- File.stub(:capture3ist?).with(source) { true }
47
- Pkg::Util::File.should_receive(:file_exists?).with(source, {:required => true}) { true }
48
- Pkg::Util::File.should_receive(:file_writable?).with(target) { true }
49
- Pkg::Util::Execution.should_receive(:capture3).with("#{tar} #{options} -C #{target} -xf #{source}")
60
+ allow(File).to receive(:capture3ist?).with(source).and_return(true)
61
+ expect(Pkg::Util::File).to receive(:file_exists?).with(source, { required: true }) { true }
62
+ expect(Pkg::Util::File).to receive(:file_writable?).with(target) { true }
63
+ expect(Pkg::Util::Execution)
64
+ .to receive(:capture3)
65
+ .with("#{tar} #{options} -C #{target} -xf #{source}")
50
66
  Pkg::Util::File.untar_into(source, target, options)
51
67
  end
52
68
  end
53
69
 
54
- describe "#files_with_ext" do
55
- it "returns nothing if there are no files with that extension" do
56
- Pkg::Util::File.files_with_ext("./spec/fixtures/configs/components", ".fake").should be_empty
70
+ describe '#files_with_ext' do
71
+ it 'returns nothing if there are no files with that extension' do
72
+ expect(Pkg::Util::File.files_with_ext('./spec/fixtures/configs/components', '.fake'))
73
+ .to be_empty
57
74
  end
58
75
 
59
- it "returns only the files with that extension" do
60
- expect(Pkg::Util::File.files_with_ext("./spec/fixtures/configs/components", ".json")).to include("./spec/fixtures/configs/components/test_file.json")
61
- expect(Pkg::Util::File.files_with_ext("./spec/fixtures/configs/components", ".json")).to include("./spec/fixtures/configs/components/test_file_2.json")
76
+ it 'returns only the files with that extension' do
77
+ expect(Pkg::Util::File.files_with_ext('./spec/fixtures/configs/components', '.json'))
78
+ .to include('./spec/fixtures/configs/components/test_file.json')
79
+ expect(Pkg::Util::File.files_with_ext('./spec/fixtures/configs/components', '.json'))
80
+ .to include('./spec/fixtures/configs/components/test_file_2.json')
62
81
  end
63
82
  end
64
83
 
65
- describe "#install_files_into_dir" do
66
- it "selects the correct files to install" do
84
+ describe '#install_files_into_dir' do
85
+ it 'selects the correct files to install' do
67
86
  Pkg::Config.load_defaults
68
87
  workdir = Pkg::Util::File.mktemp
69
88
  patterns = []
70
89
 
71
- # Set up a bunch of default settings for these to avoid a lot more stubbing in each section below
72
- File.stub(:file?) { false }
73
- File.stub(:symlink?) { false }
74
- File.stub(:directory?) { false }
75
- Pkg::Util::File.stub(:empty_dir?) { false }
90
+ allow(File).to receive(:file?).and_return(false)
91
+ allow(File).to receive(:symlink?).and_return(false)
92
+ allow(File).to receive(:directory?).and_return(false)
93
+ allow(Pkg::Util::File).to receive(:empty_dir?).and_return(false)
76
94
 
77
95
  # Files should have the path made and should be copied
78
96
  files.each do |file|
79
- File.stub(:file?).with(file).and_return(true)
80
- Dir.stub(:[]).with(file).and_return(file)
81
- FileUtils.should_receive(:mkpath).with(File.dirname(File.join(workdir, file)), :verbose => false)
82
- FileUtils.should_receive(:cp).with(file, File.join(workdir, file), :verbose => false, :preserve => true)
97
+ allow(File).to receive(:file?).with(file).and_return(true)
98
+ allow(Dir).to receive(:[]).with(file).and_return(file)
99
+ expect(FileUtils)
100
+ .to receive(:mkpath)
101
+ .with(File.dirname(File.join(workdir, file)), verbose: false)
102
+ expect(FileUtils)
103
+ .to receive(:cp)
104
+ .with(file, File.join(workdir, file), verbose: false, preserve: true)
83
105
  patterns << file
84
106
  end
85
107
 
86
108
  # Symlinks should have the path made and should be copied
87
109
  symlinks.each do |file|
88
- File.stub(:symlink?).with(file).and_return(true)
89
- Dir.stub(:[]).with(file).and_return(file)
90
- FileUtils.should_receive(:mkpath).with(File.dirname(File.join(workdir, file)), :verbose => false)
91
- FileUtils.should_receive(:cp).with(file, File.join(workdir, file), :verbose => false, :preserve => true)
110
+ allow(File).to receive(:symlink?).with(file).and_return(true)
111
+ allow(Dir).to receive(:[]).with(file).and_return(file)
112
+ expect(FileUtils)
113
+ .to receive(:mkpath)
114
+ .with(File.dirname(File.join(workdir, file)), verbose: false)
115
+ expect(FileUtils)
116
+ .to receive(:cp)
117
+ .with(file, File.join(workdir, file), verbose: false, preserve: true)
92
118
  patterns << file
93
119
  end
94
120
 
95
- # Dirs should be added to patterns but no acted upon
121
+ # Dirs should be added to patterns but not acted upon
96
122
  dirs.each do |dir|
97
- File.stub(:directory?).with(dir).and_return(true)
98
- Dir.stub(:[]).with("#{dir}/**/*").and_return(dir)
99
- FileUtils.should_not_receive(:mkpath).with(File.dirname(File.join(workdir, dir)), :verbose => false)
100
- FileUtils.should_not_receive(:cp).with(dir, File.join(workdir, dir), :verbose => false, :preserve => true)
123
+ allow(File).to receive(:directory?).with(dir).and_return(true)
124
+ allow(Dir).to receive(:[]).with("#{dir}/**/*").and_return(dir)
125
+ expect(FileUtils)
126
+ .not_to receive(:mkpath)
127
+ .with(File.dirname(File.join(workdir, dir)), verbose: false)
128
+ expect(FileUtils)
129
+ .not_to receive(:cp)
130
+ .with(dir, File.join(workdir, dir), verbose: false, preserve: true)
101
131
  patterns << dir
102
132
  end
103
133
 
104
134
  # Empty dirs should have the path created and nothing copied
105
135
  empty_dirs.each do |dir|
106
- Pkg::Util::File.stub(:empty_dir?).with(dir).and_return(true)
107
- Dir.stub(:[]).with(dir).and_return(dir)
108
- FileUtils.should_receive(:mkpath).with(File.join(workdir, dir), :verbose => false)
109
- FileUtils.should_not_receive(:cp).with(dir, File.join(workdir, dir), :verbose => false, :preserve => true)
136
+ allow(Pkg::Util::File).to receive(:empty_dir?).with(dir).and_return(true)
137
+ allow(Dir).to receive(:[]).with(dir).and_return(dir)
138
+ expect(FileUtils)
139
+ .to receive(:mkpath)
140
+ .with(File.join(workdir, dir), verbose: false)
141
+ expect(FileUtils)
142
+ .not_to receive(:cp)
143
+ .with(dir, File.join(workdir, dir), verbose: false, preserve: true)
110
144
  patterns << dir
111
145
  end
112
146
 
@@ -115,25 +149,28 @@ describe "Pkg::Util::File" do
115
149
  end
116
150
  end
117
151
 
118
- describe "#directories" do
119
- it "returns nil if there is no directory" do
120
- File.should_receive(:directory?).with("/tmp").and_return(false)
121
- Pkg::Util::File.directories("/tmp").should be_nil
152
+ describe '#directories' do
153
+ it 'returns nil if there is no directory' do
154
+ expect(File).to receive(:directory?).with('/tmp').and_return(false)
155
+ expect(Pkg::Util::File.directories('/tmp')).to be_nil
122
156
  end
123
157
 
124
- it "returns the empty array if there are no dirs in the directory" do
125
- File.should_receive(:directory?).with("/tmp").and_return(true)
126
- Dir.should_receive(:glob).with("*").and_return([])
127
- Pkg::Util::File.directories("/tmp").should be_empty
158
+ it 'returns the empty array if there are no dirs in the directory' do
159
+ expect(File).to receive(:directory?).with('/tmp').and_return(true)
160
+ expect(Dir).to receive(:glob).with('*').and_return([])
161
+ expect(Pkg::Util::File.directories("/tmp")).to be_empty
128
162
  end
129
163
 
130
- it "returns an array of the top level directories inside a directory" do
131
- File.stub(:directory?) { false }
132
- ["/tmp", "/tmp/dir", "/tmp/other_dir"].each do |dir|
133
- File.should_receive(:directory?).with(dir).and_return(true)
164
+ it 'returns an array of the top level directories inside a directory' do
165
+ allow(File).to receive(:directory?).and_return(false)
166
+ ['/tmp', '/tmp/dir', '/tmp/other_dir'].each do |dir|
167
+ expect(File).to receive(:directory?).with(dir).and_return(true)
134
168
  end
135
- Dir.should_receive(:glob).with("*").and_return(["/tmp/file", "/tmp/dir", "/tmp/other_dir"])
136
- Pkg::Util::File.directories("/tmp").should eq(["/tmp/dir", "/tmp/other_dir"])
169
+ expect(Dir)
170
+ .to receive(:glob)
171
+ .with('*')
172
+ .and_return(['/tmp/file', '/tmp/dir', '/tmp/other_dir'])
173
+ expect(Pkg::Util::File.directories('/tmp')).to eq(['/tmp/dir', '/tmp/other_dir'])
137
174
  end
138
175
  end
139
176
  end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Pkg::Util::Gpg" do
4
- let(:gpg) { "/local/bin/gpg" }
5
- let(:keychain) { "/usr/local/bin/keychain" }
6
- let(:gpg_key) { "abcd1234" }
7
- let(:target_file) { "/tmp/file" }
3
+ describe 'Pkg::Util::Gpg' do
4
+ let(:gpg) { '/local/bin/gpg' }
5
+ let(:keychain) { '/usr/local/bin/keychain' }
6
+ let(:gpg_key) { 'abcd1234' }
7
+ let(:target_file) { '/tmp/file' }
8
8
 
9
9
  before(:each) do
10
10
  reset_env(['RPM_GPG_AGENT'])
@@ -12,36 +12,37 @@ describe "Pkg::Util::Gpg" do
12
12
  end
13
13
 
14
14
  describe '#key' do
15
- it "fails if Pkg::Config.gpg_key isn't set" do
15
+ it 'fails if Pkg::Config.gpg_key isn\'t set' do
16
16
  allow(Pkg::Config).to receive(:gpg_key).and_return(nil)
17
17
  expect { Pkg::Util::Gpg.key }.to raise_error(RuntimeError)
18
18
  end
19
- it "fails if Pkg::Config.gpg_key is an empty string" do
19
+ it 'fails if Pkg::Config.gpg_key is an empty string' do
20
20
  allow(Pkg::Config).to receive(:gpg_key).and_return('')
21
21
  expect { Pkg::Util::Gpg.key }.to raise_error(RuntimeError)
22
22
  end
23
23
  end
24
24
 
25
25
  describe '#kill_keychain' do
26
- it "doesn't reload the keychain if already loaded" do
26
+ it 'doesn\'t reload the keychain if already loaded' do
27
27
  Pkg::Util::Gpg.instance_variable_set("@keychain_loaded", true)
28
- Pkg::Util::Gpg.should_receive(:kill_keychain).never
29
- Pkg::Util::Gpg.should_receive(:start_keychain).never
28
+
29
+ expect(Pkg::Util::Gpg).not_to receive(:kill_keychain)
30
+ expect(Pkg::Util::Gpg).not_to receive(:start_keychain)
30
31
  Pkg::Util::Gpg.load_keychain
31
32
  Pkg::Util::Gpg.instance_variable_set("@keychain_loaded", nil)
32
33
  end
33
34
 
34
35
  it "doesn't reload the keychain if ENV['RPM_GPG_AGENT'] is set" do
35
36
  ENV['RPM_GPG_AGENT'] = 'blerg'
36
- Pkg::Util::Gpg.should_receive(:kill_keychain).never
37
- Pkg::Util::Gpg.should_receive(:start_keychain).never
37
+ expect(Pkg::Util::Gpg).not_to receive(:kill_keychain)
38
+ expect(Pkg::Util::Gpg).not_to receive(:start_keychain)
38
39
  Pkg::Util::Gpg.load_keychain
39
40
  end
40
41
 
41
42
  it 'kills and starts the keychain if not loaded already' do
42
43
  Pkg::Util::Gpg.instance_variable_set("@keychain_loaded", nil)
43
- Pkg::Util::Gpg.should_receive(:kill_keychain).once
44
- Pkg::Util::Gpg.should_receive(:start_keychain).once
44
+ expect(Pkg::Util::Gpg).to receive(:kill_keychain).once
45
+ expect(Pkg::Util::Gpg).to receive(:start_keychain).once
45
46
  Pkg::Util::Gpg.load_keychain
46
47
  end
47
48
  end
@@ -49,15 +50,19 @@ describe "Pkg::Util::Gpg" do
49
50
  describe '#sign_file' do
50
51
  it 'adds special flags if RPM_GPG_AGENT is set' do
51
52
  ENV['RPM_GPG_AGENT'] = 'blerg'
52
- additional_flags = "--no-tty --use-agent"
53
- Pkg::Util::Tool.should_receive(:find_tool).with('gpg').and_return(gpg)
54
- Pkg::Util::Execution.should_receive(:capture3).with("#{gpg}\s#{additional_flags}\s--armor --detach-sign -u #{gpg_key} #{target_file}")
53
+ additional_flags = '--no-tty --use-agent'
54
+ expect(Pkg::Util::Tool).to receive(:find_tool).with('gpg').and_return(gpg)
55
+ expect(Pkg::Util::Execution)
56
+ .to receive(:capture3)
57
+ .with("#{gpg}\s#{additional_flags}\s--armor --detach-sign -u #{gpg_key} #{target_file}")
55
58
  Pkg::Util::Gpg.sign_file(target_file)
56
59
  end
57
60
 
58
61
  it 'signs without extra flags when RPM_GPG_AGENT is not set' do
59
- Pkg::Util::Tool.should_receive(:find_tool).with('gpg').and_return(gpg)
60
- Pkg::Util::Execution.should_receive(:capture3).with("#{gpg}\s\s--armor --detach-sign -u #{gpg_key} #{target_file}")
62
+ expect(Pkg::Util::Tool).to receive(:find_tool).with('gpg').and_return(gpg)
63
+ expect(Pkg::Util::Execution)
64
+ .to receive(:capture3)
65
+ .with("#{gpg}\s\s--armor --detach-sign -u #{gpg_key} #{target_file}")
61
66
  Pkg::Util::Gpg.sign_file(target_file)
62
67
  end
63
68
  end
@@ -1,9 +1,10 @@
1
1
  # -*- ruby -*-
2
2
  require 'spec_helper'
3
+ require 'json'
3
4
 
4
5
  describe Pkg::Util::Jenkins do
5
- let(:build_host) {"Jenkins-foo"}
6
- let(:name) {"job-foo"}
6
+ let(:build_host) { 'Jenkins-foo' }
7
+ let(:name) { 'job-foo' }
7
8
  around do |example|
8
9
  old_build_host = Pkg::Config.jenkins_build_host
9
10
  Pkg::Config.jenkins_build_host = build_host
@@ -11,51 +12,77 @@ describe Pkg::Util::Jenkins do
11
12
  Pkg::Config.jenkins_build_host = old_build_host
12
13
  end
13
14
 
14
- describe "#create_jenkins_job" do
15
- let(:xml_file) {"bar.xml"}
15
+ describe '#create_jenkins_job' do
16
+ let(:xml_file) { 'bar.xml' }
16
17
 
17
- it "should call curl_form_data with the correct arguments" do
18
- Pkg::Util::Net.should_receive(:curl_form_data).with("http://#{build_host}/createItem?name=#{name}", ["-H", '"Content-Type: application/xml"', "--data-binary", "@#{xml_file}"])
18
+ it 'should call curl_form_data with the correct arguments' do
19
+ expect(Pkg::Util::Net)
20
+ .to receive(:curl_form_data)
21
+ .with("http://#{build_host}/createItem?name=#{name}",
22
+ ['-H', '"Content-Type: application/xml"',
23
+ '--data-binary',
24
+ "@#{xml_file}"])
19
25
  Pkg::Util::Jenkins.create_jenkins_job(name, xml_file)
20
26
  end
21
27
  end
22
28
 
23
- describe "#jenkins_job_exists?" do
24
-
25
- it "should call curl_form_data with correct arguments" do
26
- Pkg::Util::Net.should_receive(:curl_form_data).with("http://#{build_host}/job/#{name}/config.xml", ["--silent", "--fail"], :quiet => true).and_return(['output', 0])
27
- Pkg::Util::Execution.should_receive(:success?).and_return(true)
29
+ describe '#jenkins_job_exists?' do
30
+ it 'should call curl_form_data with correct arguments' do
31
+ expect(Pkg::Util::Net)
32
+ .to receive(:curl_form_data)
33
+ .with("http://#{build_host}/job/#{name}/config.xml",
34
+ ['--silent', '--fail'],
35
+ quiet: true)
36
+ .and_return(['output', 0])
37
+ expect(Pkg::Util::Execution).to receive(:success?).and_return(true)
28
38
  Pkg::Util::Jenkins.jenkins_job_exists?(name)
29
39
  end
30
40
 
31
- it "should return false on job not existing" do
32
- Pkg::Util::Net.should_receive(:curl_form_data).with("http://#{build_host}/job/#{name}/config.xml", ["--silent", "--fail"], :quiet => true).and_return(['output', 1])
33
- Pkg::Util::Execution.should_receive(:success?).and_return(false)
34
- Pkg::Util::Jenkins.jenkins_job_exists?(name).should be_false
41
+ it 'should return false on job not existing' do
42
+ expect(Pkg::Util::Net)
43
+ .to receive(:curl_form_data)
44
+ .with("http://#{build_host}/job/#{name}/config.xml",
45
+ ['--silent', '--fail'],
46
+ quiet: true)
47
+ .and_return(['output', 1])
48
+ expect(Pkg::Util::Execution)
49
+ .to receive(:success?)
50
+ .and_return(false)
51
+ expect(Pkg::Util::Jenkins.jenkins_job_exists?(name)).to be false
35
52
  end
36
53
 
37
- it "should return false if curl_form_data raised a runtime error" do
38
- Pkg::Util::Net.should_receive(:curl_form_data).with("http://#{build_host}/job/#{name}/config.xml", ["--silent", "--fail"], :quiet => true).and_return(false)
39
- Pkg::Util::Jenkins.jenkins_job_exists?(name).should be_false
54
+ it 'should return false if curl_form_data raised a runtime error' do
55
+ expect(Pkg::Util::Net)
56
+ .to receive(:curl_form_data)
57
+ .with("http://#{build_host}/job/#{name}/config.xml",
58
+ ['--silent', '--fail'],
59
+ quiet: true)
60
+ .and_return(false)
61
+ expect(Pkg::Util::Jenkins.jenkins_job_exists?(name)).to be false
40
62
  end
41
63
 
42
- it "should return true when job exists" do
43
- Pkg::Util::Net.should_receive(:curl_form_data).with("http://#{build_host}/job/#{name}/config.xml", ["--silent", "--fail"], :quiet => true).and_return(['output', 0])
44
- Pkg::Util::Execution.should_receive(:success?).and_return(true)
45
- Pkg::Util::Jenkins.jenkins_job_exists?(name).should be_true
64
+ it 'should return true when job exists' do
65
+ expect(Pkg::Util::Net)
66
+ .to receive(:curl_form_data)
67
+ .with("http://#{build_host}/job/#{name}/config.xml",
68
+ ['--silent', '--fail'],
69
+ quiet: true)
70
+ .and_return(['output', 0])
71
+ expect(Pkg::Util::Execution).to receive(:success?).and_return(true)
72
+ expect(Pkg::Util::Jenkins.jenkins_job_exists?(name)).to be true
46
73
  end
47
74
  end
48
75
 
49
76
  describe '#poll_jenkins_job' do
50
- let(:job_url) { "http://cat.meow/" }
77
+ let(:job_url) { 'http://cat.meow' }
51
78
  let(:build_url) { "#{job_url}/1" }
52
- let(:result) { "SUCCESS" }
53
- let(:job_hash) { {'lastBuild' => { 'url' => build_url } }}
54
- let(:build_hash) { {'result' => result, 'building' => false } }
79
+ let(:result) { 'SUCCESS' }
80
+ let(:job_hash) { { 'lastBuild' => { 'url' => build_url } } }
81
+ let(:build_hash) { { 'result' => result, 'building' => false } }
55
82
 
56
83
  before :each do
57
- subject.stub(:get_jenkins_info).with(job_url).and_return(job_hash)
58
- subject.stub(:wait_for_build).with(build_url).and_return(build_hash)
84
+ allow(subject).to receive(:get_jenkins_info).with(job_url).and_return(job_hash)
85
+ allow(subject).to receive(:wait_for_build).with(build_url).and_return(build_hash)
59
86
  end
60
87
 
61
88
  context "when polling the given url" do
@@ -66,47 +93,51 @@ describe Pkg::Util::Jenkins do
66
93
  end
67
94
 
68
95
  describe '#wait_for_build' do
69
- let(:job_url) { "http://cat.meow/" }
96
+ let(:job_url) { 'http://cat.meow' }
70
97
  let(:build_url) { "#{job_url}/1" }
71
- let(:build_hash) { {'building' => false } }
98
+ let(:build_hash) { { 'building' => false } }
72
99
 
73
100
  context "when waiting for the given build to finish" do
74
101
  it "return the resulting build_hash when build completes successfully" do
75
- subject.should_receive(:get_jenkins_info).with(job_url).and_return(build_hash)
102
+ expect(subject).to receive(:get_jenkins_info).with(job_url).and_return(build_hash)
76
103
  subject.wait_for_build(job_url)
77
104
  end
78
105
  end
79
106
  end
80
107
 
81
108
  describe '#get_jenkins_info' do
82
- let(:url) { "http://cat.meow/" }
109
+ let(:url) { 'http://cat.meow' }
83
110
  let(:uri) { URI(url) }
84
111
  let(:response) { double }
85
- let(:valid_json) { "{\"employees\":[
86
- {\"firstName\":\"John\", \"lastName\":\"Doe\"},
87
- {\"firstName\":\"Anna\", \"lastName\":\"Smith\"},
88
- {\"firstName\":\"Peter\", \"lastName\":\"Jones\"} ]}" }
112
+ let(:valid_json) do
113
+ {
114
+ 'employees' => [
115
+ { 'firstName' => 'John', 'lastName' => 'Doe' },
116
+ { 'firstName' => 'Anna', 'lastName' => 'Smith' },
117
+ { 'firstName' => 'Peter', 'lastName' => 'Jones' }
118
+ ]
119
+ }.to_json
120
+ end
89
121
 
90
122
  before :each do
91
- response.stub(:body).and_return( valid_json )
92
- response.stub(:code).and_return( '200' )
93
- Pkg::Util::Jenkins.should_receive(:URI).and_return(uri)
123
+ allow(response).to receive(:body).and_return(valid_json)
124
+ allow(response).to receive(:code).and_return('200')
125
+ expect(Pkg::Util::Jenkins).to receive(:URI).and_return(uri)
94
126
  end
95
127
 
96
- context "when making HTTP GET request to given url" do
97
- it "should return Hash of JSON contents when response is non-error" do
98
- Net::HTTP.should_receive(:get_response).with(uri).and_return(response)
128
+ context 'when making HTTP GET request to given url' do
129
+ it 'should return Hash of JSON contents when response is non-error' do
130
+ expect(Net::HTTP).to receive(:get_response).with(uri).and_return(response)
99
131
  subject.get_jenkins_info(url)
100
132
  end
101
133
 
102
- it "should raise Runtime error when response is error" do
103
- response.stub(:code).and_return( '400' )
104
- Net::HTTP.should_receive(:get_response).with(uri).and_return(response)
105
- expect{
134
+ it 'should raise Runtime error when response is error' do
135
+ allow(response).to receive(:code).and_return('400')
136
+ expect(Net::HTTP).to receive(:get_response).with(uri).and_return(response)
137
+ expect do
106
138
  subject.get_jenkins_info(url)
107
- }.to raise_error(Exception, /Unable to query .*, please check that it is valid./)
139
+ end.to raise_error(Exception, /Unable to query .*, please check that it is valid./)
108
140
  end
109
141
  end
110
142
  end
111
-
112
143
  end
@@ -2,7 +2,7 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe 'Pkg::Util::Misc' do
5
- context "#search_and_replace" do
5
+ context '#search_and_replace' do
6
6
  let(:orig_string) { "#!/bin/bash\necho '__REPO_NAME__'" }
7
7
  let(:updated_string) { "#!/bin/bash\necho 'abcdefg'" }
8
8
  let(:good_replacements) do
@@ -13,19 +13,24 @@ describe 'Pkg::Util::Misc' do
13
13
  end
14
14
 
15
15
  it 'replaces the token with the Pkg::Config variable' do
16
- Pkg::Config.config_from_hash({:project => "foo", :repo_name => 'abcdefg'})
17
- Pkg::Util::Misc.search_and_replace(orig_string, good_replacements).should eq(updated_string)
16
+ Pkg::Config.config_from_hash({ project: 'foo', repo_name: 'abcdefg' })
17
+ expect(Pkg::Util::Misc.search_and_replace(orig_string, good_replacements))
18
+ .to eq(updated_string)
18
19
  end
19
20
 
20
21
  it 'does no replacement if the Pkg::Config variable is not set' do
21
- Pkg::Config.config_from_hash({:project => 'foo',})
22
- Pkg::Util::Misc.search_and_replace(orig_string, good_replacements).should eq(orig_string)
22
+ Pkg::Config.config_from_hash({ project: 'foo' })
23
+ expect(Pkg::Util::Misc.search_and_replace(orig_string, good_replacements))
24
+ .to eq(orig_string)
23
25
  end
24
26
 
25
27
  it 'warns and continues if the Pkg::Config variable is unknown to packaging' do
26
- Pkg::Config.config_from_hash({:project => 'foo',})
27
- Pkg::Util::Misc.should_receive(:warn).with("replacement value for '#{warn_replacements.keys.first}' probably shouldn't be nil")
28
- Pkg::Util::Misc.search_and_replace(orig_string, warn_replacements).should eq(orig_string)
28
+ Pkg::Config.config_from_hash({ project: 'foo' })
29
+ expect(Pkg::Util::Misc)
30
+ .to receive(:warn)
31
+ .with("replacement value for '#{warn_replacements.keys.first}' probably shouldn't be nil")
32
+ expect(Pkg::Util::Misc.search_and_replace(orig_string, warn_replacements))
33
+ .to eq(orig_string)
29
34
  end
30
35
  end
31
36
  end