Class: Riot::SameElementsMacro
- Inherits:
-
AssertionMacro
- Object
- AssertionMacro
- Riot::SameElementsMacro
- 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"])
Maybe you just want to make sure two sets arent’t the same:
denies("test") { ["foo", "bar"] }.same_elements(["baz", "boo"])
Instance Attribute Summary
Attributes inherited from AssertionMacro
Instance Method Summary collapse
-
#devaluate(actual, expected) ⇒ Array
Supports negative/converse assertion testing.
-
#evaluate(actual, expected) ⇒ Array
Supports positive assertion testing.
Methods inherited from AssertionMacro
#error, #expected_message, expects_exception!, #expects_exception?, #fail, #new_message, #pass, register, #should_have_message
Instance Method Details
#devaluate(actual, expected) ⇒ Array
Supports negative/converse assertion testing. This is also where magic happens.
23 24 25 26 |
# File 'lib/riot/assertion_macros/same_elements.rb', line 23 def devaluate(actual, expected) same = (Set.new(expected) == Set.new(actual)) same ? fail(.elements(expected).not_to_match(actual)) : pass(.has_same_elements_as(expected)) end |
#evaluate(actual, expected) ⇒ Array
Supports positive assertion testing. This is where magic happens.
16 17 18 19 |
# File 'lib/riot/assertion_macros/same_elements.rb', line 16 def evaluate(actual, expected) same = (Set.new(expected) == Set.new(actual)) same ? pass(.has_same_elements_as(expected)) : fail(.elements(expected).to_match(actual)) end |