RSpec ã® contain_exactly ããã㣠㨠match_array ãããã£
contain_exactly ãããã£
`contain_exactly` matcher - Built in matchers - RSpec Expectations - RSpec - Relish
以ä¸ã®ããã«ã³ã¬ã¯ã·ã§ã³ã«å¯¾ãã¦ãé åºã¯åããªãããã¹ã¦ãå«ã¾ãã¦ãããããã§ãã¯ãããã¨ãã§ããã
expect([1, 2, 3]).to contain_exactly(2, 3, 1) # pass expect([:a, :c, :b]).to contain_exactly(:a, :c) # fail
match_array ãããã£
ã»ã¼åããããªãããã£ã¨ã㦠match_array ã¨ããã®ãããã ããã¯å¼æ°ã«é åãåãã®ã§æ³¨æããã
expect([1, 2, 3]).to match_array [2, 3, 1] # pass expect([:a, :c, :b]).to match_array [:a, :c] # fail
ã½ã¼ã¹ã³ã¼ããèªã
ãããã®ãããã£ã®åä½ãç解ããããã«ãã¾ã㯠contain_exactly
ã®ã½ã¼ã¹ã³ã¼ããèªãã§ã¿ãã
def match(_expected, _actual) return false unless convert_actual_to_an_array match_when_sorted? || (extra_items.empty? && missing_items.empty?) end def match_when_sorted? values_match?(safe_sort(expected), safe_sort(actual)) end
å¼æ°ãé åã«å¤æãã¦ãã½ã¼ããããã¨ã§ãããããããããããããã§ãã¯ãã¦ããã
ä¸æ¹ match_array
ã¯ä»¥ä¸ã®ãããªæãã
def match_array(items) contain_exactly(*items) end
contain_exactly
å¼ãã§ãã
ã¨ãããã¨ã§ contain_exactly
㨠match_array
ã¯å¼æ°ã«é
åãåããã©ãã以å¤ã¯åãæåããããã¨ãããã£ãã
ã¾ã¨ã
RSpec ã¯å¥¥ãæ·±ãã