|
7 | 7 |
|
8 | 8 | # mock class to test the module |
9 | 9 | class SpeccableTestClass |
10 | | - attr_accessor :world_property |
| 10 | + attr_accessor :world_property, :src_archive, :name, :version, :patches, |
| 11 | + :artifact_ids, :runtime_dependency_ids, :outputs |
11 | 12 |
|
12 | 13 | include Tetra::Speccable |
13 | 14 |
|
14 | 15 | def initialize |
15 | 16 | @world_property = "World!" |
| 17 | + @name = "test-package" |
| 18 | + @version = "1.0" |
| 19 | + @src_archive = nil |
| 20 | + @patches = [] |
| 21 | + @artifact_ids = [] |
| 22 | + @runtime_dependency_ids = [] |
| 23 | + @outputs = [] |
16 | 24 | end |
17 | 25 | end |
18 | 26 |
|
@@ -90,4 +98,56 @@ def initialize |
90 | 98 | end |
91 | 99 | end |
92 | 100 | end |
| 101 | + |
| 102 | + describe "#to_spec unzip requirement" do |
| 103 | + before(:each) do |
| 104 | + template_content = <<~ERB |
| 105 | + Name: <%= name %> |
| 106 | + <% if src_archive&.downcase&.end_with?(".zip") %> |
| 107 | + BuildRequires: unzip |
| 108 | + <% end %> |
| 109 | + ERB |
| 110 | + File.write(@template_path, template_content) |
| 111 | + end |
| 112 | + |
| 113 | + it "adds BuildRequires: unzip if the source is a .zip file" do |
| 114 | + instance.src_archive = "sources.zip" |
| 115 | + expect(instance._to_spec(@project, "test-package", "test.spec", "output")).to be_truthy |
| 116 | + |
| 117 | + @project.from_directory do |
| 118 | + spec_lines = File.readlines(@destination_path) |
| 119 | + expect(spec_lines).to include("BuildRequires: unzip\n") |
| 120 | + end |
| 121 | + end |
| 122 | + |
| 123 | + it "adds BuildRequires: unzip if the source is a .ZIP file (case insensitivity)" do |
| 124 | + instance.src_archive = "SOURCES.ZIP" |
| 125 | + expect(instance._to_spec(@project, "test-package", "test.spec", "output")).to be_truthy |
| 126 | + |
| 127 | + @project.from_directory do |
| 128 | + spec_lines = File.readlines(@destination_path) |
| 129 | + expect(spec_lines).to include("BuildRequires: unzip\n") |
| 130 | + end |
| 131 | + end |
| 132 | + |
| 133 | + it "does not add BuildRequires: unzip if the source is a tarball" do |
| 134 | + instance.src_archive = "sources.tar.gz" |
| 135 | + expect(instance._to_spec(@project, "test-package", "test.spec", "output")).to be_truthy |
| 136 | + |
| 137 | + @project.from_directory do |
| 138 | + spec_lines = File.readlines(@destination_path) |
| 139 | + expect(spec_lines).not_to include("BuildRequires: unzip\n") |
| 140 | + end |
| 141 | + end |
| 142 | + |
| 143 | + it "does not add BuildRequires: unzip if there is no source archive" do |
| 144 | + instance.src_archive = nil |
| 145 | + expect(instance._to_spec(@project, "test-package", "test.spec", "output")).to be_truthy |
| 146 | + |
| 147 | + @project.from_directory do |
| 148 | + spec_lines = File.readlines(@destination_path) |
| 149 | + expect(spec_lines).not_to include("BuildRequires: unzip\n") |
| 150 | + end |
| 151 | + end |
| 152 | + end |
93 | 153 | end |
0 commit comments