Skip to content

Commit

Permalink
Rework spec to better comply with Codacy style rules.
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Hammond <[email protected]>
  • Loading branch information
macblazer committed Jan 3, 2024
1 parent 72ad824 commit 44fa59a
Showing 1 changed file with 51 additions and 49 deletions.
100 changes: 51 additions & 49 deletions spec/cyclonedx/cocoapods/bom_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,47 @@
'pkg:cocoapods/[email protected]' => []
}
end
# Important: these expected components are sorted alphabetically
let(:pod_result) do
'<components>
<component type="library">
<name>Alamofire</name>
<version>5.6.2</version>
<purl>pkg:cocoapods/[email protected]</purl>
<bomRef>pkg:cocoapods/[email protected]</bomRef>
</component>
<component type="library">
<name>FirebaseAnalytics</name>
<version>7.10.0</version>
<purl>pkg:cocoapods/[email protected]</purl>
<bomRef>pkg:cocoapods/[email protected]</bomRef>
</component>
<component type="library">
<name>MSAL</name>
<version>1.2.1</version>
<purl>pkg:cocoapods/[email protected]</purl>
<bomRef>pkg:cocoapods/[email protected]</bomRef>
</component>
<component type="library">
<name>MSAL/app-lib</name>
<version>1.2.1</version>
<purl>pkg:cocoapods/[email protected]#app-lib</purl>
<bomRef>pkg:cocoapods/[email protected]#app-lib</bomRef>
</component>
<component type="library">
<name>Realm</name>
<version>5.5.1</version>
<purl>pkg:cocoapods/[email protected]</purl>
<bomRef>pkg:cocoapods/[email protected]</bomRef>
</component>
<component type="library">
<name>RxSwift</name>
<version>5.1.2</version>
<purl>pkg:cocoapods/[email protected]</purl>
<bomRef>pkg:cocoapods/[email protected]</bomRef>
</component>
</components>'
end

shared_examples 'bom_generator' do
context 'with an incorrect version' do
Expand Down Expand Up @@ -362,64 +403,25 @@
end

it 'should properly delegate component node generation to pods' do
components_generated_from_bom_builder = xml.at('bom/components')

# Important: these expected components are sorted alphabetically
expected_components_string =
'<components>
<component type="library">
<name>Alamofire</name>
<version>5.6.2</version>
<purl>pkg:cocoapods/[email protected]</purl>
<bomRef>pkg:cocoapods/[email protected]</bomRef>
</component>
<component type="library">
<name>FirebaseAnalytics</name>
<version>7.10.0</version>
<purl>pkg:cocoapods/[email protected]</purl>
<bomRef>pkg:cocoapods/[email protected]</bomRef>
</component>
<component type="library">
<name>MSAL</name>
<version>1.2.1</version>
<purl>pkg:cocoapods/[email protected]</purl>
<bomRef>pkg:cocoapods/[email protected]</bomRef>
</component>
<component type="library">
<name>MSAL/app-lib</name>
<version>1.2.1</version>
<purl>pkg:cocoapods/[email protected]#app-lib</purl>
<bomRef>pkg:cocoapods/[email protected]#app-lib</bomRef>
</component>
<component type="library">
<name>Realm</name>
<version>5.5.1</version>
<purl>pkg:cocoapods/[email protected]</purl>
<bomRef>pkg:cocoapods/[email protected]</bomRef>
</component>
<component type="library">
<name>RxSwift</name>
<version>5.1.2</version>
<purl>pkg:cocoapods/[email protected]</purl>
<bomRef>pkg:cocoapods/[email protected]</bomRef>
</component>
</components>'

components = Nokogiri::XML expected_components_string

expect(components_generated_from_bom_builder.to_xml).to be_equivalent_to(components.root.to_xml).respecting_element_order
actual = xml.at('bom/components').to_xml

expected = Nokogiri::XML pod_result
expected = expected.root.to_xml

expect(actual).to be_equivalent_to(expected).respecting_element_order
end

it 'should generate a child dependencies node' do
expect(xml.at('bom/dependencies')).not_to be_nil
end

it 'should properly set dependencies node' do
dependencies_generated_from_bom_builder = xml.at('bom/dependencies')
actual = xml.at('bom/dependencies').to_xml

dependencies = Nokogiri::XML dependencies_result
expected = Nokogiri::XML dependencies_result
expected = expected.root.to_xml

expect(dependencies_generated_from_bom_builder.to_xml).to be_equivalent_to(dependencies.root.to_xml).respecting_element_order
expect(actual).to be_equivalent_to(expected).respecting_element_order
end
end
end
Expand Down

0 comments on commit 44fa59a

Please sign in to comment.