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 Attribute Summary

Attributes inherited from AssertionMacro

#file, #line

Instance Method Summary collapse

Methods inherited from AssertionMacro

default, #error, #expected_message, expects_exception!, #expects_exception?, #fail, #new_message, #pass, register, #should_have_message

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_message.elements(expected).to_match(actual))
end