Sha256: e0a8ef5dbe5c8bbfccd720878b337a501b23860063dbbd0681f5659604ddd81c

Contents?: true

Size: 838 Bytes

Versions: 3

Compression:

Stored size: 838 Bytes

Contents

module Riot
  # Asserts that two arrays contain the same elements, the same number of times.
  #
  #   asserts("test") { ["foo", "bar"] }.same_elements(["bar", "foo"])
  #   should("test") { ["foo", "bar"] }.same_elements(["bar", "foo"])
  #
  # Maybe you just want to make sure two sets arent't the same:
  #
  #  denies("test") { ["foo", "bar"] }.same_elements(["baz", "boo"])
  class SameElementsMacro < AssertionMacro
    register :same_elements
    require 'set'
    
    def evaluate(actual, expected)
      same = (Set.new(expected) == Set.new(actual))
      same ? pass : fail(expected_message.elements(expected).to_match(actual))
    end

    def devaluate(actual, expected)
      same = (Set.new(expected) == Set.new(actual))
      same ? fail(expected_message.elements(expected).not_to_match(actual)) : pass
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
riot-0.12.1 lib/riot/assertion_macros/same_elements.rb
riot-0.12.0 lib/riot/assertion_macros/same_elements.rb
riot-0.12.0.pre lib/riot/assertion_macros/same_elements.rb