Class: Riot::SameElementsMacro

Inherits:
AssertionMacro show all
Defined in:
lib/riot/assertion_macros/same_elements.rb

Overview

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"])

Instance Method Summary collapse

Methods inherited from AssertionMacro

default, #error, expects_exception!, #expects_exception?, #fail, #pass, register

Instance Method Details

#evaluate(actual, expected) ⇒ Object



8
9
10
11
12
# File 'lib/riot/assertion_macros/same_elements.rb', line 8

def evaluate(actual, expected)
  require 'set'
  same = (Set.new(expected) == Set.new(actual))
  same ? pass : fail("expected elements #{expected.inspect} to match #{actual.inspect}")
end