Skip to content

Commit

Permalink
get rid of CustomEnum
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Jan 6, 2015
1 parent 832d664 commit 39b525e
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions spec/in_threads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ def fast_check?
end
end

# Create custom Enumerables
module CustomEnum
def self.new(&block)
Class.new do
include Enumerable
define_method :each, &block
end.new
end
end

class TestException < StandardError; end

def describe_enum_method(method, &block)
Expand Down Expand Up @@ -172,20 +162,17 @@ def measure
describe 'underlying enumerable usage' do
%w[each map all?].each do |method|
it "should call underlying enumerable.each only once for #{method}" do
enum = CustomEnum.new do |&block|
100.times.each do |i|
block[ValueItem.new(i, i < 50)]
end
end
enum = 100.times.map{ |i| ValueItem.new(i, i < 50) }

expect(enum).to receive(:each).once.and_call_original
enum.in_threads(13).send(method, &:check?)
end
end

it 'should not yield all elements when not needed' do
enum = CustomEnum.new do |&block|
100.times{ block[1] }
enum = []
def enum.each
100.times{ yield 1 }
fail
end

Expand Down Expand Up @@ -522,10 +509,12 @@ def check_test_exception(enum, &block)

describe_enum_method 'each_entry' do
let(:enum) do
CustomEnum.new do |&block|
10.times{ block[1] }
10.times{ block[2, 3] }
10.times{ block[4, 5, 6] }
[].tap do |enum|
def enum.each
10.times{ yield 1 }
10.times{ yield 2, 3 }
10.times{ yield 4, 5, 6 }
end
end
end
let(:runner){ proc{ |o| ValueItem.new(0, o).value } }
Expand Down

0 comments on commit 39b525e

Please sign in to comment.