Skip to content

Commit

Permalink
Ruby: Merge pull request #9 from mkllnk/specs
Browse files Browse the repository at this point in the history
Rewrite MiniTest tests as Rspec specs
  • Loading branch information
lecoqlibre authored Nov 20, 2023
2 parents baedfa8 + 2079105 commit 6d9d116
Show file tree
Hide file tree
Showing 27 changed files with 321 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run tests
run: bundle exec rake
run: bundle exec rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
source "https://rubygems.org"
gemspec

gem "rspec"
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ GEM
remote: https://rubygems.org/
specs:
bcp47_spec (0.2.1)
diff-lcs (1.5.0)
htmlentities (4.3.4)
json-canonicalization (0.3.2)
json-ld (3.3.0)
Expand All @@ -18,13 +19,24 @@ GEM
rack (>= 2.2, < 4)
rdf (~> 3.3)
link_header (0.0.8)
minitest (5.20.0)
multi_json (1.15.0)
rack (3.0.8)
rake (13.1.0)
rdf (3.3.1)
bcp47_spec (~> 0.2)
link_header (~> 0.0, >= 0.0.8)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
virtual_assembly-semantizer (1.0.5)
json-ld (~> 3.2, >= 3.2.3)

Expand All @@ -33,8 +45,7 @@ PLATFORMS

DEPENDENCIES
datafoodconsortium-connector!
minitest
rake
rspec

BUNDLED WITH
2.4.21
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ To produce the documentation just type `yard doc`. Then open the `index.html` fi

## Tests

Some unit tests are in the `/test` folder.
Some unit tests are in the `/spec` folder.

To run them, just type `rake`.
To run them, just type `rspec`.

## Contributing

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ Gem::Specification.new do |s|
s.license = "MIT"

s.add_runtime_dependency "virtual_assembly-semantizer", "~> 1.0", ">= 1.0.5"
s.add_development_dependency "minitest"
s.add_development_dependency "rake"
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
describe DataFoodConsortium::Connector::Address do
it "can be empty when exported" do
subject = DataFoodConsortium::Connector::Address.new(
"https://myplatform.com/a"
)
result = connector.export(subject)
expect(result).to eq(
'{"@context":"https://www.datafoodconsortium.org","@id":"https://myplatform.com/a","@type":"dfc-b:Address","dfc-b:hasStreet":"","dfc-b:hasPostalCode":"","dfc-b:hasCity":"","dfc-b:hasCountry":""}'
)
end

it "contains all fields when exported" do
subject = DataFoodConsortium::Connector::Address.new(
"https://myplatform.com/a",
street: "street",
postalCode: "postalCode",
city: "city",
country: "country"
)
result = connector.export(subject)
expect(result).to eq(
'{"@context":"https://www.datafoodconsortium.org","@id":"https://myplatform.com/a","@type":"dfc-b:Address","dfc-b:hasStreet":"street","dfc-b:hasPostalCode":"postalCode","dfc-b:hasCity":"city","dfc-b:hasCountry":"country"}'
)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
describe DataFoodConsortium::Connector::CatalogItem do
it "can be empty when exported" do
subject = DataFoodConsortium::Connector::CatalogItem.new(
"https://myplatform.com/ci"
)
result = connector.export(subject)
expect(result).to eq(
'{"@context":"https://www.datafoodconsortium.org","@id":"https://myplatform.com/ci","@type":"dfc-b:CatalogItem","dfc-b:sku":"","dfc-b:stockLimitation":0.0}'
)
end

it "contains all fields when exported" do
sp = DataFoodConsortium::Connector::CatalogItem.new("https://myplatform.com/sp")
offer = DataFoodConsortium::Connector::CatalogItem.new("https://myplatform.com/o")
subject = DataFoodConsortium::Connector::CatalogItem.new(
"https://myplatform.com/ci",
product: sp,
sku: "sku",
stockLimitation: 10,
offers: [offer]
)
result = connector.export(subject)
expect(result).to eq(
'{"@context":"https://www.datafoodconsortium.org","@id":"https://myplatform.com/ci","@type":"dfc-b:CatalogItem","dfc-b:references":"https://myplatform.com/sp","dfc-b:sku":"sku","dfc-b:stockLimitation":10,"dfc-b:offeredThrough":"https://myplatform.com/o"}'
)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
describe DataFoodConsortium::Connector::CustomerCategory do
it "can be empty when exported" do
subject = DataFoodConsortium::Connector::CustomerCategory.new(
"https://myplatform.com/cc"
)
result = connector.export(subject)
expect(result).to eq(
'{"@context":"https://www.datafoodconsortium.org","@id":"https://myplatform.com/cc","@type":"dfc-b:CustomerCategory","dfc-b:description":""}'
)
end

it "contains all fields when exported" do
subject = DataFoodConsortium::Connector::CustomerCategory.new(
"https://myplatform.com/cc",
description: "description"
)
result = connector.export(subject)
expect(result).to eq(
'{"@context":"https://www.datafoodconsortium.org","@id":"https://myplatform.com/cc","@type":"dfc-b:CustomerCategory","dfc-b:description":"description"}'
)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
describe DataFoodConsortium::Connector::Enterprise do
it "can be empty when exported" do
subject = DataFoodConsortium::Connector::Enterprise.new(
"https://myplatform.com/e"
)
result = connector.export(subject)
expect(result).to eq(
'{"@context":"https://www.datafoodconsortium.org","@id":"https://myplatform.com/e","@type":"dfc-b:Enterprise","dfc-b:name":"","dfc-b:hasDescription":"","dfc-b:VATnumber":""}'
)
end

it "contains all fields when exported" do
subject = DataFoodConsortium::Connector::Enterprise.new(
"https://myplatform.com/e",
name: "name",
description: "description",
vatNumber: "vatNumber",
customerCategories: [
DataFoodConsortium::Connector::CustomerCategory.new("https://myplatform.com/cc")
],
suppliedProducts: [
DataFoodConsortium::Connector::SuppliedProduct.new("https://myplatform.com/sp")
],
catalogItems: [
DataFoodConsortium::Connector::CatalogItem.new("https://myplatform.com/ci")
],
localizations: []
)
result = connector.export(subject)
expect(result).to eq(
'{"@context":"https://www.datafoodconsortium.org","@id":"https://myplatform.com/e","@type":"dfc-b:Enterprise","dfc-b:name":"name","dfc-b:hasDescription":"description","dfc-b:VATnumber":"vatNumber","dfc-b:defines":"https://myplatform.com/cc","dfc-b:manages":"https://myplatform.com/ci","dfc-b:supplies":"https://myplatform.com/sp"}'
)
end

it "contains collections as arrays when exported" do
subject = DataFoodConsortium::Connector::Enterprise.new(
"https://myplatform.com/e",
name: "name",
description: "description",
vatNumber: "vatNumber",
customerCategories: [
DataFoodConsortium::Connector::CustomerCategory.new("https://myplatform.com/cc"),
DataFoodConsortium::Connector::CustomerCategory.new("https://myplatform.com/cc2")
],
suppliedProducts: [
DataFoodConsortium::Connector::SuppliedProduct.new("https://myplatform.com/sp"),
DataFoodConsortium::Connector::SuppliedProduct.new("https://myplatform.com/sp2")
],
catalogItems: [
DataFoodConsortium::Connector::CatalogItem.new("https://myplatform.com/ci"),
DataFoodConsortium::Connector::CatalogItem.new("https://myplatform.com/ci2")
],
localizations: []
)
result = connector.export(subject)
expect(result).to eq(
'{"@context":"https://www.datafoodconsortium.org","@id":"https://myplatform.com/e","@type":"dfc-b:Enterprise","dfc-b:name":"name","dfc-b:hasDescription":"description","dfc-b:VATnumber":"vatNumber","dfc-b:defines":["https://myplatform.com/cc","https://myplatform.com/cc2"],"dfc-b:manages":["https://myplatform.com/ci","https://myplatform.com/ci2"],"dfc-b:supplies":["https://myplatform.com/sp","https://myplatform.com/sp2"]}'
)
end
end
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
require 'connector'
require "minitest/autorun"
require 'datafoodconsortium/connector'

class ExportTest < Minitest::Test

def test_export
describe DataFoodConsortium::Connector::Connector do
it "exports multiple subjects in a graph" do
a = DataFoodConsortium::Connector::Address.new(
"https://myplatform.com/a",
street: "street",
Expand Down Expand Up @@ -92,7 +87,6 @@ def test_export
)
actual = connector.export(p, a, e, cc, sp, ci, o)
expected = '{"@context":"https://www.datafoodconsortium.org","@graph":[{"@id":"https://myplatform.com/p","@type":"dfc-b:Person","dfc-b:hasAddress":"https://myplatform.com/a","dfc-b:firstName":"firstName","dfc-b:familyName":"lastName","dfc-b:affiliates":"https://myplatform.com/e"},{"@id":"https://myplatform.com/a","@type":"dfc-b:Address","dfc-b:hasStreet":"street","dfc-b:hasPostalCode":"postalCode","dfc-b:hasCity":"city","dfc-b:hasCountry":"country"},{"@id":"https://myplatform.com/e","@type":"dfc-b:Enterprise","dfc-b:name":"name","dfc-b:hasDescription":"description","dfc-b:VATnumber":"vatNumber","dfc-b:defines":"https://myplatform.com/cc","dfc-b:manages":"https://myplatform.com/ci","dfc-b:supplies":"https://myplatform.com/sp"},{"@id":"https://myplatform.com/cc","@type":"dfc-b:CustomerCategory","dfc-b:description":"description"},{"@id":"https://myplatform.com/sp","@type":"dfc-b:SuppliedProduct","dfc-b:name":"name","dfc-b:description":"description","dfc-b:hasType":"dfc-pt:artichoke","dfc-b:hasQuantity":{"@type":"dfc-b:QuantitativeValue","dfc-b:hasUnit":"dfc-m:Kilogram","dfc-b:value":1.2},"dfc-b:alcoholPercentage":2.6,"dfc-b:lifetime":"lifetime","dfc-b:hasClaim":["dfc-f:EnergyFree","dfc-f:FatFree","dfc-f:HighFibre"],"dfc-b:usageOrStorageCondition":"usageOrStorageConditions","dfc-b:hasNutrientCharacteristic":{"@type":"dfc-b:NutrientCharacteristic","dfc-b:hasUnit":"dfc-m:Gram","dfc-b:value":8.47,"dfc-b:hasNutrientDimension":"dfc-m:Calcium"},"dfc-b:hasPhysicalCharacteristic":{"@type":"dfc-b:PhysicalCharacteristic","dfc-b:hasUnit":"dfc-m:Kilogram","dfc-b:value":3.25,"dfc-b:hasPhysicalDimension":"dfc-m:Weight"},"dfc-b:hasGeographicalOrigin":"dfc-f:Normandy","dfc-b:hasCertification":"dfc-f:Demeter","dfc-b:hasNatureOrigin":"https://github.com/datafoodconsortium/taxonomies/releases/latest/download/facets.rdf#PlantOrigin","dfc-b:hasPartOrigin":"https://github.com/datafoodconsortium/taxonomies/releases/latest/download/facets.rdf#PlantOrigin","dfc-b:totalTheoreticalStock":123},{"@id":"https://myplatform.com/ci","@type":"dfc-b:CatalogItem","dfc-b:references":"https://myplatform.com/sp","dfc-b:sku":"sku","dfc-b:stockLimitation":10,"dfc-b:offeredThrough":"https://myplatform.com/o"},{"@id":"https://myplatform.com/o","@type":"dfc-b:Offer","dfc-b:hasPrice":{"@type":"dfc-b:Price","dfc-b:value":12.78,"dfc-b:VATrate":5.22,"dfc-b:hasUnit":"dfc-m:Euro"},"dfc-b:stockLimitation":52,"dfc-b:offeredTo":"https://myplatform.com/cc"}]}'
assert_equal expected, actual
expect(actual).to eq(expected)
end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
describe DataFoodConsortium::Connector::Offer do
it "can be empty when exported" do
subject = DataFoodConsortium::Connector::Offer.new(
"https://myplatform.com/o"
)
result = connector.export(subject)
expect(result).to eq(
'{"@context":"https://www.datafoodconsortium.org","@id":"https://myplatform.com/o","@type":"dfc-b:Offer","dfc-b:stockLimitation":0.0}'
)
end

it "contains all fields when exported" do
ci = DataFoodConsortium::Connector::CatalogItem.new("https://myplatform.com/ci")
cc = DataFoodConsortium::Connector::CustomerCategory.new("https://myplatform.com/cc")
subject = DataFoodConsortium::Connector::Offer.new(
"https://myplatform.com/o",
price: DataFoodConsortium::Connector::Price.new(
value: 12.78,
vatRate: 5.22,
unit: connector.MEASURES.EURO
),
stockLimitation: 52,
offeredItem: ci,
offeredTo: cc
)
result = connector.export(subject)
expect(result).to eq(
'{"@context":"https://www.datafoodconsortium.org","@id":"https://myplatform.com/o","@type":"dfc-b:Offer","dfc-b:hasPrice":{"@type":"dfc-b:Price","dfc-b:value":12.78,"dfc-b:VATrate":5.22,"dfc-b:hasUnit":"dfc-m:Euro"},"dfc-b:stockLimitation":52,"dfc-b:offeredItem":"https://myplatform.com/ci","dfc-b:offeredTo":"https://myplatform.com/cc"}'
)
end
end
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
require 'connector'
require "minitest/autorun"
require 'datafoodconsortium/connector'

class PersonTest < Minitest::Test

def test_export_empty
describe DataFoodConsortium::Connector::Person do
it "can be empty when exported" do
p = DataFoodConsortium::Connector::Person.new("https://myplatform.com/p")
actual = connector.export(p)
expected = '{"@context":"https://www.datafoodconsortium.org","@id":"https://myplatform.com/p","@type":"dfc-b:Person","dfc-b:firstName":"","dfc-b:familyName":""}'
assert_equal expected, actual
expect(actual).to eq expected
end

def test_export_complete
it "contains all fields when exported" do
p = DataFoodConsortium::Connector::Person.new(
"https://myplatform.com/p",
firstName: "firstName",
Expand All @@ -25,7 +20,6 @@ def test_export_complete
)
actual = connector.export(p)
expected = '{"@context":"https://www.datafoodconsortium.org","@id":"https://myplatform.com/p","@type":"dfc-b:Person","dfc-b:hasAddress":"https://myplatform.com/a","dfc-b:firstName":"firstName","dfc-b:familyName":"lastName","dfc-b:affiliates":"https://myplatform.com/e"}'
assert_equal expected, actual
expect(actual).to eq expected
end

end
end
Loading

0 comments on commit 6d9d116

Please sign in to comment.