summaryrefslogtreecommitdiff
path: root/spec/unit/chef_fs
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-05-19 10:36:26 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-05-19 10:36:26 -0700
commit15d4ff065806478d1c20bf78ce7c2a4c2fb74022 (patch)
treecafcc3d38d2b68b10f4a52094d395373acf35c99 /spec/unit/chef_fs
parent9f0bb81b3c8f873456a8e18eff3bee24c573ac8c (diff)
downloadchef-15d4ff065806478d1c20bf78ce7c2a4c2fb74022.tar.gz
Do not provide "lazy" unless it is available (Ruby 2.0+)
Diffstat (limited to 'spec/unit/chef_fs')
-rw-r--r--spec/unit/chef_fs/parallelizer.rb62
1 files changed, 44 insertions, 18 deletions
diff --git a/spec/unit/chef_fs/parallelizer.rb b/spec/unit/chef_fs/parallelizer.rb
index fa13d917a7..5bc2ecfd17 100644
--- a/spec/unit/chef_fs/parallelizer.rb
+++ b/spec/unit/chef_fs/parallelizer.rb
@@ -361,9 +361,8 @@ describe Chef::ChefFS::Parallelizer do
x
end
enum.take(2).should == [1,2]
- enum.lazy.take(2).to_a.should == [1,2]
- outputs_processed.should == 4
- input_mapper.num_processed.should == 4
+ outputs_processed.should == 2
+ input_mapper.num_processed.should == 2
end
it ".drop does not process anything other than the last result(s)" do
@@ -375,24 +374,51 @@ describe Chef::ChefFS::Parallelizer do
x
end
enum.drop(2).should == [3,4,5,6]
- enum.lazy.drop(2).to_a.should == [3,4,5,6]
- outputs_processed.should == 8
- input_mapper.num_processed.should == 12
+ outputs_processed.should == 4
+ input_mapper.num_processed.should == 6
end
- it "lazy enumerable is actually lazy" do
- outputs_processed = 0
- input_mapper = InputMapper.new(1,2,3,4,5,6)
- enum = parallelizer.parallelize(input_mapper) do |x|
- outputs_processed += 1
- sleep(0.05) # Just enough to yield and get other inputs in the queue
- x
+ if Enumerable.method_defined?(:lazy)
+ it ".lazy.take does not enumerate anything other than the first result(s)" do
+ outputs_processed = 0
+ input_mapper = InputMapper.new(1,2,3,4,5,6)
+ enum = parallelizer.parallelize(input_mapper) do |x|
+ outputs_processed += 1
+ sleep(0.05) # Just enough to yield and get other inputs in the queue
+ x
+ end
+ enum.lazy.take(2).to_a.should == [1,2]
+ outputs_processed.should == 2
+ input_mapper.num_processed.should == 2
+ end
+
+ it ".drop does not process anything other than the last result(s)" do
+ outputs_processed = 0
+ input_mapper = InputMapper.new(1,2,3,4,5,6)
+ enum = parallelizer.parallelize(input_mapper) do |x|
+ outputs_processed += 1
+ sleep(0.05) # Just enough to yield and get other inputs in the queue
+ x
+ end
+ enum.lazy.drop(2).to_a.should == [3,4,5,6]
+ outputs_processed.should == 4
+ input_mapper.num_processed.should == 6
+ end
+
+ it "lazy enumerable is actually lazy" do
+ outputs_processed = 0
+ input_mapper = InputMapper.new(1,2,3,4,5,6)
+ enum = parallelizer.parallelize(input_mapper) do |x|
+ outputs_processed += 1
+ sleep(0.05) # Just enough to yield and get other inputs in the queue
+ x
+ end
+ enum.lazy.take(2)
+ enum.lazy.drop(2)
+ sleep(0.1)
+ outputs_processed.should == 0
+ input_mapper.num_processed.should == 0
end
- enum.lazy.take(2)
- enum.lazy.drop(2)
- sleep(0.1)
- outputs_processed.should == 0
- input_mapper.num_processed.should == 0
end
end