Sha256: 78ed9a36bd09567ee6214279ee062bdf441f52e6539b1c66719cc2a1c2b35aad

Contents?: true

Size: 728 Bytes

Versions: 2

Compression:

Stored size: 728 Bytes

Contents

module CustomMatchers
  class OnlyHaveAttributesMatcher
    
    def initialize(*attrs)  
      @attributes = attrs.map(&:to_s)
    end  
  
    def matches?(target)  
      @target_attributes = target.keys.map(&:to_s)
      (@target_attributes & @attributes) == @target_attributes
    end  
  
    def failure_message_for_should  
      "expected to only allow attributes #{@attributes.join(", ")}, allowed #{@target_attributes.join(", ")}"
    end  
  
    def failure_message_for_should_not  
      "expected to not only allow attributes #{@attributes.join(", ")}, allowed #{@target_attributes.join(", ")}"
    end  
    
  end  
  
  def only_have_attributes(*attrs)  
    OnlyHaveAttributesMatcher.new(*attrs)  
  end  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
scoped_attr_accessible-0.1.4 spec/support/custom_matchers.rb
scoped_attr_accessible-0.1.3 spec/support/custom_matchers.rb