Sha256: f2984d9ba19677bc2f95d469bea0ea5778b7cf5c79aa57038102eb66908d87c3

Contents?: true

Size: 1.09 KB

Versions: 15

Compression:

Stored size: 1.09 KB

Contents

module Mongoid::Acts::NestedSet
  module Matchers

    def have_nestedset_pos(lft, rgt, options = {})
      NestedSetPosition.new(lft, rgt, options)
    end

    class NestedSetPosition

      def initialize(lft, rgt, options)
        @lft = lft
        @rgt = rgt
        @options = options
      end

      def matches?(node)
        @node = node
        !!(
          node.respond_to?('left') && node.respond_to?('right') &&
          node.left == @lft &&
          node.right == @rgt
        )
      end

      def description
        "have position {left: #{@lft}, right: #{@rgt}}"
      end

      def failure_message_for_should
        sprintf("expected nested set position: {left: %2s, right: %2s}\n" +
                "                         got: {left: %2s, right: %2s}",
          @lft,
          @rgt,
          @node.respond_to?('left')  ? @node.left  : '?',
          @node.respond_to?('right') ? @node.right : '?'
        )
      end

      def failure_message_for_should_not
        sprintf("expected nested set to not have position: {left: %2s, right: %2s}", @lft, @rgt)
      end

    end

  end
end

Version data entries

15 entries across 14 versions & 3 rubygems

Version Path
glebtv-mongoid_nested_set-0.5.1 spec/matchers/nestedset_pos.rb
glebtv-mongoid_nested_set-0.5.0 spec/matchers/nestedset_pos.rb
glebtv-mongoid_nested_set-0.4.3 spec/matchers/nestedset_pos.rb
glebtv-mongoid_nested_set-0.4.2 spec/matchers/nestedset_pos.rb
glebtv-mongoid_nested_set-0.4.1 spec/matchers/nestedset_pos.rb
glebtv-mongoid_nested_set-0.4.0 spec/matchers/nestedset_pos.rb
glebtv-mongoid_nested_set-0.3.0 spec/matchers/nestedset_pos.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/mongoid_nested_set-0.2.1/spec/matchers/nestedset_pos.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/bundler/gems/mongoid_nested_set-d482b2642889/spec/matchers/nestedset_pos.rb
mongoid_nested_set-0.2.1 spec/matchers/nestedset_pos.rb
mongoid_nested_set-0.2.0 spec/matchers/nestedset_pos.rb
mongoid_nested_set-0.1.3 spec/matchers/nestedset_pos.rb
mongoid_nested_set-0.1.2 spec/matchers/nestedset_pos.rb
mongoid_nested_set-0.1.1 spec/matchers/nestedset_pos.rb
mongoid_nested_set-0.1.0 spec/matchers/nestedset_pos.rb