From 3ef3014530846908aa5bd9545f01896256fb5349 Mon Sep 17 00:00:00 2001 From: Gregory Saumier-Finch Date: Mon, 2 Dec 2024 09:58:36 -0500 Subject: [PATCH] using File.expand_path to ensure path is good when tests are run from any dir --- test/sparql_test.rb | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/test/sparql_test.rb b/test/sparql_test.rb index 910c0a4..8921631 100644 --- a/test/sparql_test.rb +++ b/test/sparql_test.rb @@ -8,8 +8,11 @@ class SparqlTest < Minitest::Test def setup - @sparql = SPARQL.parse(File.read("sparql/score_algorithm.sparql"), update: true) - shacl_files = Dir.glob("shacl/partials/*.ttl") + sparql_file = File.expand_path("../sparql/score_algorithm.sparql", __dir__) + shacl_dir = File.expand_path("../shacl/partials/*.ttl", __dir__) + + @sparql = SPARQL.parse(File.read(sparql_file), update: true) + shacl_files = Dir.glob(shacl_dir) shapes_graph = RDF::Graph.new shacl_files.each do |file| shapes_graph << RDF::Graph.load(file) @@ -21,7 +24,8 @@ def setup def test_required_properties # If any of the three required properties is missing, the score would be 0 (zero), no matter how good the rest of the structured data is. # An event with all three required properties would have a score of 12 + (2 x 8) = 28. - graph = RDF::Graph.load("fixtures/score_tests.jsonld") + fixture_file = File.expand_path("../fixtures/score_tests.jsonld", __dir__) + graph = RDF::Graph.load(fixture_file) graph << @shacl.execute(graph) graph.query(@sparql) # puts graph.dump(:ttl) @@ -35,7 +39,8 @@ def test_required_properties def test_event_types # Should accepts TheaterEvent, DanceEvent, MusicEvent, VisualArtsEvent, FilmEvent. - graph = RDF::Graph.load("fixtures/event_types.jsonld") + fixture_file = File.expand_path("../fixtures/event_types.jsonld", __dir__) + graph = RDF::Graph.load(fixture_file) graph << @shacl.execute(graph) graph.query(@sparql) actual = graph.query([nil, RDF::URI('http://example.org/score'), 0]).count @@ -45,7 +50,8 @@ def test_event_types # test high scores and precentages def test_high_scores - graph = RDF::Graph.load("fixtures/score_high_tests.jsonld") + fixture_file = File.expand_path("../fixtures/score_high_tests.jsonld", __dir__) + graph = RDF::Graph.load(fixture_file) graph << @shacl.execute(graph) graph.query(@sparql) @@ -62,7 +68,8 @@ def test_high_scores # Test that events with an @id are awarded 2 points def test_event_id - graph = RDF::Graph.load("fixtures/score_event_id.jsonld") + fixture_file = File.expand_path("../fixtures/score_event_id.jsonld", __dir__) + graph = RDF::Graph.load(fixture_file) graph << @shacl.execute(graph) graph.query(@sparql) actual = graph.query([ RDF::URI('http://event1'), RDF::URI('http://example.org/score'), nil]).first.object.value.to_i @@ -74,7 +81,8 @@ def test_event_id end def test_alternate_postal_code - graph = RDF::Graph.load("fixtures/score_alternate_postal_address.jsonld") + fixture_file = File.expand_path("../fixtures/score_alternate_postal_address.jsonld", __dir__) + graph = RDF::Graph.load(fixture_file) graph << @shacl.execute(graph) graph.query(@sparql) actual = graph.query([ nil, RDF::URI('http://example.org/postalCode_score'), nil]).first.object.value.to_i