Skip to content

Commit

Permalink
Clean up messages to STDOUT/STDERR when running tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Feb 10, 2016
1 parent 604b78d commit f050146
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions spec/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
%w(
name abc.123 _col.1
).each {|v| expect(described_class.new({"name" => v}, logger: logger)).to be_valid}
expect(logger.to_s).not_to match(/ERROR|WARN/)
end

it "detects invalid names" do
Expand All @@ -235,6 +236,7 @@
it "allows absence of name" do
expect(described_class.new({"@type" => "Column"}, logger: logger)).to be_valid
expect(described_class.new({"@type" => "Column"}, logger: logger).name).to eql '_col.0'
expect(logger.to_s).not_to match(/ERROR|WARN/)
end

its(:type) {is_expected.to eql :Column}
Expand Down Expand Up @@ -287,6 +289,7 @@
it name do
subject.titles = input
expect(subject.normalize!.titles).to produce(output)
expect(logger.to_s).not_to match(/ERROR|WARN/)
end
end
end
Expand Down Expand Up @@ -348,6 +351,7 @@
base: RDF::URI("http://example.org/base"),
logger: logger)
expect(v).to be_valid
expect(logger.to_s).not_to match(/ERROR|WARN/)
end

it "is valid with multiple names if any column missing" do
Expand All @@ -364,6 +368,7 @@
describe "foreignKeys" do
subject {
RDF::Tabular::TableGroup.new({
"@context" => 'http://www.w3.org/ns/csvw',
tables: [{
url: "a",
tableSchema: {
Expand Down Expand Up @@ -410,6 +415,7 @@
subject.tables.first.tableSchema.foreignKeys << fk
subject.normalize!
expect(subject).to be_valid
expect(logger.to_s).not_to match(/ERROR|WARN/)
end
end
end
Expand Down Expand Up @@ -501,6 +507,7 @@
subject.send("#{prop}=".to_sym, v)
expect(subject).to be_valid
end
expect(logger.to_s).not_to match(/ERROR|WARN/)
end
it "warnings" do
params[:warning].each do |v|
Expand All @@ -519,6 +526,7 @@
it name do
subject.titles = input
expect(subject.normalize!.titles).to produce(output)
expect(logger.to_s).not_to match(/ERROR|WARN/)
end
end
end
Expand All @@ -534,12 +542,14 @@
described_class.const_get(:DEFAULTS).each do |p, v|
context "#{p}" do
it "retrieves #{v.inspect} by default" do
expect(logger.to_s).not_to match(/ERROR|WARN/)
expect(subject.send(p)).to eql v
end

it "retrieves set value" do
subject[p] = "foo"
expect(subject.send(p)).to eql "foo"
expect(logger.to_s).not_to match(/ERROR|WARN/)
end
end
end
Expand Down Expand Up @@ -611,6 +621,7 @@

result = dialect.embedded_metadata(props[:input], nil, base: RDF::URI("http://example.org/base"))
expect(::JSON.parse(result.to_json(JSON_STATE))).to produce(::JSON.parse(props[:result]), logger)
expect(logger.to_s).not_to match(/ERROR|WARN/)
end
end
end
Expand All @@ -624,6 +635,7 @@
its(:type) {is_expected.to eql :Table}

describe "#to_table_group" do
it "should be tested"
end

{
Expand Down Expand Up @@ -658,12 +670,14 @@
params[:valid].each do |v|
subject.send("#{prop}=".to_sym, v)
expect(subject).to be_valid
expect(logger.to_s).not_to match(/ERROR|WARN/)
end
end
it "invalidates" do
params[:invalid].each do |v|
subject.send("#{prop}=".to_sym, v)
expect(subject).not_to be_valid
expect(logger.to_s).to include("ERROR")
end
end if params[:invalid]
it "warnings" do
Expand Down Expand Up @@ -713,12 +727,14 @@
params[:valid].each do |v|
subject.send("#{prop}=".to_sym, v)
expect(subject).to be_valid
expect(logger.to_s).not_to match(/ERROR|WARN/)
end
end
it "invalidates" do
params[:invalid].each do |v|
subject.send("#{prop}=".to_sym, v)
expect(subject).not_to be_valid
expect(logger.to_s).to include("ERROR")
end
end if params[:invalid]
it "warnings" do
Expand All @@ -736,10 +752,13 @@
Dir.glob(File.expand_path("../data/*.json", __FILE__)).each do |filename|
next if filename =~ /-(atd|standard|minimal|roles).json/
context filename do
subject {RDF::Tabular::Metadata.open(filename)}
subject {RDF::Tabular::Metadata.open(filename, logger: logger)}
it {is_expected.to be_valid}
its(:filenames) {is_expected.to include("file:#{filename}")}
end
after(:each) do
expect(logger.to_s).not_to match(/ERROR|WARN/)
end
end
end

Expand All @@ -750,6 +769,9 @@
File.foreach(filename.sub(".json", "-errors.txt")) do |err|
it {is_expected.not_to be_valid}
end
after(:each) do
expect(logger.to_s).not_to include("ERROR")
end
end
end
end
Expand Down Expand Up @@ -816,7 +838,7 @@
":type Schema" => [{}, {type: :Schema}, RDF::Tabular::Schema],
":type Column" => [{}, {type: :Column}, RDF::Tabular::Column],
":type Dialect" => [{}, {type: :Dialect}, RDF::Tabular::Dialect],
"@type TableGroup" => [{"@type" => "TableGroup"}, RDF::Tabular::TableGroup],
"@type TableGroup" => [{}, {"@type" => "TableGroup"}, RDF::Tabular::TableGroup],
"@type Table" => [{"@type" => "Table"}, RDF::Tabular::Table],
"@type Template" => [{"@type" => "Template"}, RDF::Tabular::Transformation],
"@type Schema" => [{"@type" => "Schema"}, RDF::Tabular::Schema],
Expand All @@ -826,9 +848,9 @@
"dialect Table" => [{"dialect" => {}}, RDF::Tabular::Table],
"tableSchema Table" => [{"tableSchema" => {}}, RDF::Tabular::Table],
"transformations Table" => [{"transformations" => []}, RDF::Tabular::Table],
"targetFormat Transformation" => [{"targetFormat" => "foo"}, RDF::Tabular::Transformation],
"scriptFormat Transformation" => [{"scriptFormat" => "foo"}, RDF::Tabular::Transformation],
"source Transformation" => [{"source" => "foo"}, RDF::Tabular::Transformation],
"targetFormat Transformation" => [{"targetFormat" => "http://foo"}, RDF::Tabular::Transformation],
"scriptFormat Transformation" => [{"scriptFormat" => "http://foo"}, RDF::Tabular::Transformation],
"source Transformation" => [{"source" => "json"}, RDF::Tabular::Transformation],
"columns Schema" => [{"columns" => []}, RDF::Tabular::Schema],
"primaryKey Schema" => [{"primaryKey" => "foo"}, RDF::Tabular::Schema],
"foreignKeys Schema" => [{"foreignKeys" => []}, RDF::Tabular::Schema],
Expand All @@ -842,13 +864,18 @@
"quoteChar Dialect" => [{"quoteChar" => "\""}, RDF::Tabular::Dialect],
"skipBlankRows Dialect" => [{"skipBlankRows" => true}, RDF::Tabular::Dialect],
"skipColumns Dialect" => [{"skipColumns" => 0}, RDF::Tabular::Dialect],
"skipInitialSpace Dialect" => [{"skipInitialSpace" => "start"}, RDF::Tabular::Dialect],
"skipInitialSpace Dialect" => [{"skipInitialSpace" => true}, RDF::Tabular::Dialect],
"skipRows Dialect" => [{"skipRows" => 1}, RDF::Tabular::Dialect],
"trim Dialect" => [{"trim" => true}, RDF::Tabular::Dialect],
}.each do |name, args|
it name do
klass = args.pop
expect(described_class.new(*args)).to be_a(klass)
input, options = args
options ||= {}
options[:logger] = logger
options[:context] ||= 'http://www.w3.org/ns/csvw'
expect(described_class.new(input, options)).to be_a(klass)
expect(logger.to_s).not_to match(/ERROR|WARN/)
end
end
end
Expand Down Expand Up @@ -977,7 +1004,7 @@
},
}.each do |name, props|
context name do
let(:md) {RDF::Tabular::Table.new(subject.merge(props[:md]), base: RDF::URI("http://example.org/base")).normalize!}
let(:md) {RDF::Tabular::Table.new(subject.merge(props[:md]), base: RDF::URI("http://example.org/base"), logger: logger).normalize!}
let(:cells) {md.to_enum(:each_row, input).to_a.first.values}
let(:aboutUrls) {props[:aboutUrl].map {|u| u.is_a?(String) ? md.url.join(u) : u}}
let(:propertyUrls) {props[:propertyUrl].map {|u| u.is_a?(String) ? md.url.join(u) : u}}
Expand Down Expand Up @@ -1468,6 +1495,7 @@
{
"string with no language" => [
%({
"@context": "http://www.w3.org/ns/csvw",
"dc:title": "foo"
}),
%({
Expand All @@ -1477,7 +1505,7 @@
],
"string with language" => [
%({
"@context": {"@language": "en"},
"@context": ["http://www.w3.org/ns/csvw", {"@language": "en"}],
"dc:title": "foo"
}),
%({
Expand All @@ -1487,6 +1515,7 @@
],
"relative URL" => [
%({
"@context": "http://www.w3.org/ns/csvw",
"dc:source": {"@id": "foo"}
}),
%({
Expand All @@ -1496,7 +1525,7 @@
],
"array of values" => [
%({
"@context": {"@language": "en"},
"@context": ["http://www.w3.org/ns/csvw", {"@language": "en"}],
"dc:title": [
"foo",
{"@value": "bar"},
Expand Down Expand Up @@ -1526,9 +1555,10 @@
],
}.each do |name, (input, result)|
it name do
a = RDF::Tabular::Table.new(input, base: "http://example.com/A")
b = RDF::Tabular::Table.new(result, base: "http://example.com/A")
a = RDF::Tabular::Table.new(input, base: "http://example.com/A", logger: logger)
b = RDF::Tabular::Table.new(result, base: "http://example.com/A", logger: logger)
expect(a.normalize!).to eq b
expect(logger.to_s).not_to match(/ERROR|WARN/)
end
end
end
Expand Down Expand Up @@ -1724,6 +1754,7 @@
b = described_class.new(::JSON.parse(props[:B]))
if props[:R]
expect {a.verify_compatible!(b)}.not_to raise_error
expect(logger.to_s).not_to match(/ERROR|WARN/)
else
expect {a.verify_compatible!(b)}.to raise_error(RDF::Tabular::Error)
end
Expand Down

0 comments on commit f050146

Please sign in to comment.