Sha256: cab14fe05f1f884167d00f07dad9aa09260cd47f9da4e2918dcf1955144865a3

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')

module CustomDotMatchers
  class HaveDotOptions
    def initialize(expected)
      @expected = expected
    end
    def matches?(target)
      @target = target
      return false unless @target =~ /\[(.*)\]/
      @options = $1
      @options == @expected
    end
    def failure_message
      "expected '#{@target.strip}' to have options '[#{@expected}]'"
    end
    def negative_failure_message
      "expected '#{@target.strip}' to not have options '[#{@expected}]'"
    end
    def description
      "have dot options"
    end
  end
  def have_dot_options(expected)
    HaveDotOptions.new expected
  end
end

describe DiagramGraph do
  include CustomDotMatchers

  before do
    @diagram_graph = DiagramGraph.new
  end

  describe ".dot_edge" do
    context "has_a/belongs_to" do
      it { @diagram_graph.send(:dot_edge, "one-one", "source", "target").must_include "arrowtail=odot, arrowhead=dot, dir=both" }
    end

    context "has_many/belongs_to" do
      it { @diagram_graph.send(:dot_edge, "one-many", "source", "target").must_include "arrowtail=odot, arrowhead=crow, dir=both" }
    end

    context "habtm" do
      it { @diagram_graph.send(:dot_edge, "many-many", "source", "target").must_include "arrowtail=crow, arrowhead=crow, dir=both" }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
railroady-1.2.0 test/lib/railroady/diagram_graph_spec.rb
railroady-1.1.2 test/lib/railroady/diagram_graph_spec.rb
railroady-1.1.1 test/lib/railroady/diagram_graph_spec.rb