Class: RoadForest::Testing::BeEquivalentGraph
- Inherits:
-
Object
- Object
- RoadForest::Testing::BeEquivalentGraph
- Includes:
- HelperMethods
- Defined in:
- lib/roadforest/test-support/matchers.rb
Defined Under Namespace
Classes: Info
Instance Attribute Summary collapse
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
Instance Method Summary collapse
- #description ⇒ Object
- #dump_graph(graph) ⇒ Object
- #failure_message_for_should ⇒ Object
-
#initialize(expected, info) ⇒ BeEquivalentGraph
constructor
A new instance of BeEquivalentGraph.
- #matches?(actual) ⇒ Boolean
Methods included from HelperMethods
#detect_format, #normalize, #statements_from_graph
Constructor Details
#initialize(expected, info) ⇒ BeEquivalentGraph
Returns a new instance of BeEquivalentGraph.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/roadforest/test-support/matchers.rb', line 56 def initialize(expected, info) @expected = normalize(expected) @info = if info.respond_to?(:about) info elsif info.is_a?(Hash) identifier = expected.is_a?(RDF::Graph) ? expected.context : info[:about] trace = info[:trace] trace = trace.join("\n") if trace.is_a?(Array) i = Info.new(identifier, "0000", trace, info[:compare]) i.format = info[:format] i else Info.new(expected.is_a?(RDF::Graph) ? expected.context : info, "0000", info.to_s) end @info.format ||= :ttl end |
Instance Attribute Details
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
75 76 77 |
# File 'lib/roadforest/test-support/matchers.rb', line 75 def expected @expected end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
75 76 77 |
# File 'lib/roadforest/test-support/matchers.rb', line 75 def info @info end |
Instance Method Details
#description ⇒ Object
92 93 94 |
# File 'lib/roadforest/test-support/matchers.rb', line 92 def description "be equivalent to an expected graph" #graphs tend to be too long to use end |
#dump_graph(graph) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/roadforest/test-support/matchers.rb', line 82 def dump_graph(graph) graph.dump(@info.format, :standard_prefixes => true) rescue begin graph.dump(:nquads, :standard_prefixes => true) rescue graph.inspect end end |
#failure_message_for_should ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/roadforest/test-support/matchers.rb', line 96 def info = @info.respond_to?(:about) ? @info.about : @info.inspect if @expected.is_a?(RDF::Graph) && @actual.size != @expected.size "Graph entry count differs:\nexpected: #{@expected.size}\nactual: #{@actual.size}" elsif @expected.is_a?(Array) && @actual.size != @expected.length "Graph entry count differs:\nexpected: #{@expected.length}\nactual: #{@actual.size}" else "Graph differs" end + "\n#{info + "\n" unless info.to_s.empty?}" + (@info.inputDocument ? "Input file: #{@info.inputDocument}\n" : "") + (@info.outputDocument ? "Output file: #{@info.outputDocument}\n" : "") + "\nExpected:\n#{dump_graph(@expected)}" + "\nResults:\n#{dump_graph(@actual)}" + (@info.trace ? "\nDebug:\n#{@info.trace}" : "") end |
#matches?(actual) ⇒ Boolean
77 78 79 80 |
# File 'lib/roadforest/test-support/matchers.rb', line 77 def matches?(actual) @actual = normalize(actual) @actual.isomorphic_with?(@expected)# rescue false end |