Sha256: ee36df64a39d74810c53c397dafbe5047508ada60828eb3849c3a05c23ad24fd
Contents?: true
Size: 1.17 KB
Versions: 2
Compression:
Stored size: 1.17 KB
Contents
require_relative "../lib/iterate" require "minitest/autorun" describe 'Kernel#iterate' do it 'should behave like Enumerable#each for a single argument' do array = [1, 2, 3] res_each = [] res_iterate = [] array.each do |ele| res_each << ele end iterate array do |ele| res_iterate << ele end assert_equal res_each, res_iterate end it 'should pass the right params to the block' do a = [1, 2, 3] b = %w[a b c d] res_a_b = [] res_b_a = [] iterate a, b do |e, f| res_a_b << [e, f] end assert_equal [ [1, 'a'], [2, 'b'], [3, 'c'], [nil, 'd'], ], res_a_b iterate b, a do |e, f| res_b_a << [e, f] end assert_equal [ ['a', 1], ['b', 2], ['c', 3], ['d', nil], ], res_b_a end it 'should return enumerators if no block is applied' do res = iterate [1, 2, 3], %w[a b c d] assert_kind_of Enumerator, res assert_equal [ [1,'a'], [2,'b'], [3,'c'], [nil, 'd'] ], res.to_a end it 'raises an ArgumentError for no arguments' do assert_raises ArgumentError do iterate end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
iterate-1.0.1 | spec/iterate_spec.rb |
iterate-1.0.0 | spec/iterate_spec.rb |