From facc411c4ff61a3e1fac8caf86871059e2108e31 Mon Sep 17 00:00:00 2001 From: Karol Date: Wed, 16 Aug 2023 21:40:30 +0200 Subject: [PATCH] implement suggested changes --- lib/proforma/helpers/import_helpers.rb | 2 +- spec/factories/test.rb | 47 +++++++++++++++++++ spec/proforma/exporter_spec.rb | 62 ++------------------------ spec/proforma/importer_spec.rb | 62 ++------------------------ 4 files changed, 55 insertions(+), 118 deletions(-) diff --git a/lib/proforma/helpers/import_helpers.rb b/lib/proforma/helpers/import_helpers.rb index 5f5156a..4fd9100 100644 --- a/lib/proforma/helpers/import_helpers.rb +++ b/lib/proforma/helpers/import_helpers.rb @@ -96,7 +96,7 @@ def meta_data(any_data_node, use_namespace: false) private def convert_xml_node_to_json(any_node) - xml_snippet = Nokogiri::XML::DocumentFragment.parse any_node.to_xml(save_with: 0) + xml_snippet = Nokogiri::XML::DocumentFragment.new(Nokogiri::XML::Document.new, any_node) xml_snippet.children.first.add_namespace_definition(any_node.namespace.prefix, any_node.namespace.href) JSON.parse(Dachsfisch::XML2JSONConverter.perform(xml: xml_snippet.to_xml)) end diff --git a/spec/factories/test.rb b/spec/factories/test.rb index d79e992..2a5a8ec 100644 --- a/spec/factories/test.rb +++ b/spec/factories/test.rb @@ -105,5 +105,52 @@ } end end + + trait(:with_multiple_custom_configurations) do + configuration do + { + 'unit:unittest' => { + '@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'}, + '@version' => '4.10', + '@framework' => 'JUnit', + 'unit:entry-point' => { + '$1' => 'HelloWorldTest', + '@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'}, + }, + }, + 'regex:regexptest' => + { + '@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'}, + 'regex:entry-point' => { + '$1' => 'HelloWorldTest', + '@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'}, + }, + 'regex:parameter' => { + '$1' => 'gui', + '@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'}, + }, + 'regex:regular-expressions' => { + '@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'}, + 'regex:regexp-disallow' => { + '$1' => 'foobar', + '@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'}, + '@dotall' => 'true', + '@multiline' => 'true', + '@free-spacing' => 'true', + '@case-insensitive' => 'true', + }, + }, + }, + 'check:java-checkstyle' => { + '@xmlns' => {'check' => 'urn:proforma:tests:java-checkstyle:v1.1'}, + '@version' => '3.14', + 'check:max-checkstyle-warnings' => { + '$1' => '4', + '@xmlns' => {'check' => 'urn:proforma:tests:java-checkstyle:v1.1'}, + }, + }, + } + end + end end end diff --git a/spec/proforma/exporter_spec.rb b/spec/proforma/exporter_spec.rb index 1bb98c1..5841552 100644 --- a/spec/proforma/exporter_spec.rb +++ b/spec/proforma/exporter_spec.rb @@ -362,21 +362,10 @@ end end - context 'when test has is unittest and has extra test-configuration' do - let(:task) do - build(:task, tests: build_list(:test, 1, test_type: 'unittest', configuration:)) - end + context 'when test is unittest and has extra test-configuration' do + let(:task) { build(:task, tests:) } + let(:tests) { build_list(:test, 1, :with_unittest) } - let(:configuration) do - { - 'unit:unittest' => { - '@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'}, - '@framework' => 'JUnit', - '@version' => '4.10', - 'unit:entry-point' => {'@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'}, '$1' => 'HelloWorldTest'}, - }, - } - end let(:unittest_node) { doc.xpath('/xmlns:task/xmlns:tests/xmlns:test/xmlns:test-configuration').xpath('unit:unittest') } it 'adds namespace to task' do @@ -400,50 +389,7 @@ end context 'with multiple custom data entries' do - let(:configuration) do - { - 'unit:unittest' => { - '@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'}, - '@version' => '4.10', - '@framework' => 'JUnit', - 'unit:entry-point' => { - '$1' => 'HelloWorldTest', - '@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'}, - }, - }, - 'regex:regexptest' => - { - '@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'}, - 'regex:entry-point' => { - '$1' => 'HelloWorldTest', - '@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'}, - }, - 'regex:parameter' => { - '$1' => 'gui', - '@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'}, - }, - 'regex:regular-expressions' => { - '@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'}, - 'regex:regexp-disallow' => { - '$1' => 'foobar', - '@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'}, - '@dotall' => 'true', - '@multiline' => 'true', - '@free-spacing' => 'true', - '@case-insensitive' => 'true', - }, - }, - }, - 'check:java-checkstyle' => { - '@xmlns' => {'check' => 'urn:proforma:tests:java-checkstyle:v1.1'}, - '@version' => '3.14', - 'check:max-checkstyle-warnings' => { - '$1' => '4', - '@xmlns' => {'check' => 'urn:proforma:tests:java-checkstyle:v1.1'}, - }, - }, - } - end + let(:tests) { build_list(:test, 1, :with_multiple_custom_configurations) } it 'adds all namespaces to task' do expect(doc.xpath('/xmlns:task').first.namespaces).to include( diff --git a/spec/proforma/importer_spec.rb b/spec/proforma/importer_spec.rb index 3a7a8fc..1dec966 100644 --- a/spec/proforma/importer_spec.rb +++ b/spec/proforma/importer_spec.rb @@ -170,71 +170,15 @@ end context 'when test-configuration has custom data' do - let(:task) do - build(:task, tests: build_list(:test, 1, test_type: 'unittest', configuration:)) - end - - let(:configuration) do - { - 'unit:unittest' => { - '@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'}, - '@framework' => 'JUnit', - '@version' => '4.10', - 'unit:entry-point' => {'@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'}, '$1' => 'HelloWorldTest'}, - }, - } - end + let(:task) { build(:task, tests:) } + let(:tests) { build_list(:test, 1, :with_unittest) } it 'successfully imports the task' do expect(imported_task).to be_an_equal_task_as ref_task end context 'with multiple custom data entries' do - let(:configuration) do - { - 'unit:unittest' => { - '@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'}, - '@version' => '4.10', - '@framework' => 'JUnit', - 'unit:entry-point' => { - '$1' => 'HelloWorldTest', - '@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'}, - }, - }, - 'regex:regexptest' => - { - '@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'}, - 'regex:entry-point' => { - '$1' => 'HelloWorldTest', - '@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'}, - }, - 'regex:parameter' => { - '$1' => 'gui', - '@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'}, - }, - 'regex:regular-expressions' => { - '@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'}, - 'regex:regexp-disallow' => { - '$1' => 'foobar', - '@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'}, - '@dotall' => 'true', - '@multiline' => 'true', - '@free-spacing' => 'true', - '@case-insensitive' => 'true', - }, - }, - }, - 'check:java-checkstyle' => { - '@xmlns' => {'check' => 'urn:proforma:tests:java-checkstyle:v1.1'}, - '@version' => '3.14', - 'check:max-checkstyle-warnings' => { - '$1' => '4', - '@xmlns' => {'check' => 'urn:proforma:tests:java-checkstyle:v1.1'}, - }, - }, - } - end - let(:custom_namespaces) { [{prefix: 'test', uri: 'test.com'}, {prefix: 'unit', uri: 'urn:proforma:tests:unittest:v1.1'}, {prefix: 'regex', uri: 'urn:proforma:tests:regexptest:v0.9'}, {prefix: 'check', uri: 'urn:proforma:tests:java-checkstyle:v1.1'}] } + let(:tests) { build_list(:test, 1, :with_multiple_custom_configurations) } it 'successfully imports the task' do expect(imported_task).to be_an_equal_task_as ref_task