Sha256: 871e4a59d7ccbe976769c8c2809437c2d1f2bc06085528a52846fa321a7586a6

Contents?: true

Size: 1.23 KB

Versions: 71

Compression:

Stored size: 1.23 KB

Contents

module RelationshipGraphMatchers
  class EnforceOrderWithEdge
    def initialize(before, after)
      @before = before
      @after = after
    end

    def matches?(actual_graph)
      @actual_graph = actual_graph

      @reverse_edge = actual_graph.edge?(
          vertex_called(actual_graph, @after),
          vertex_called(actual_graph, @before))

      @forward_edge = actual_graph.edge?(
          vertex_called(actual_graph, @before),
          vertex_called(actual_graph, @after))

      @forward_edge && !@reverse_edge
    end

    def failure_message_for_should
      "expect #{@actual_graph.to_dot_graph} to only contain an edge from #{@before} to #{@after} but #{[forward_failure_message, reverse_failure_message].compact.join(' and ')}"
    end

    def forward_failure_message
      if !@forward_edge
        "did not contain an edge from #{@before} to #{@after}"
      end
    end

    def reverse_failure_message
      if @reverse_edge
        "contained an edge from #{@after} to #{@before}"
      end
    end

    private

    def vertex_called(graph, name)
      graph.vertices.find { |v| v.ref =~ /#{Regexp.escape(name)}/ }
    end
  end

  def enforce_order_with_edge(before, after)
    EnforceOrderWithEdge.new(before, after)
  end
end

Version data entries

71 entries across 71 versions & 1 rubygems

Version Path
puppet-3.8.7 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.7-x86-mingw32 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.7-x64-mingw32 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.6 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.6-x86-mingw32 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.6-x64-mingw32 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.5 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.5-x86-mingw32 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.5-x64-mingw32 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.4 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.4-x86-mingw32 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.4-x64-mingw32 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.3 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.3-x86-mingw32 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.3-x64-mingw32 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.2 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.2-x86-mingw32 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.2-x64-mingw32 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.1 spec/lib/matchers/relationship_graph_matchers.rb
puppet-3.8.1-x86-mingw32 spec/lib/matchers/relationship_graph_matchers.rb