Skip to content

Commit

Permalink
Simplify tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdub committed Apr 9, 2011
1 parent cce4e6d commit f42b8f1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 32 deletions.
7 changes: 5 additions & 2 deletions spec/enumerable_fu/filters/collect_spec.rb
Expand Up @@ -4,8 +4,11 @@
describe Enumerable, "#collecting" do

it "transforms items" do
@collect = [1,2,3].collecting { |x| x * 2 }
@collect.to_a.should == [2,4,6]
[1,2,3].collecting { |x| x * 2 }.to_a.should == [2,4,6]
end

it "is lazy" do
[1,2,3].with_time_bomb.collecting { |x| x * 2 }.first.should == 2
end

end
4 changes: 4 additions & 0 deletions spec/enumerable_fu/filters/reject_spec.rb
Expand Up @@ -7,4 +7,8 @@
(1..6).rejecting { |x| x.even? }.to_a.should == [1,3,5]
end

it "is lazy" do
(1..6).with_time_bomb.rejecting { |x| x.even? }.first == 1
end

end
9 changes: 2 additions & 7 deletions spec/enumerable_fu/filters/select_spec.rb
Expand Up @@ -4,16 +4,11 @@
describe EnumerableFu::Filters::Select do

it "excludes items that don't pass the predicate" do
@select = (1..10).selecting { |x| x.even? }
@select.take(3).should == [2,4,6]
(1..6).selecting { |x| x.even? }.to_a.should == [2,4,6]
end

it "is lazy" do
@select = [1,2,3].with_time_bomb.selecting { |x| x.even? }
@select.take(1)
lambda do
@select.take(2)
end.should raise_error(Boom)
(1..6).with_time_bomb.selecting { |x| x.even? }.first == 2
end

end
21 changes: 4 additions & 17 deletions spec/enumerable_fu/filters/uniq_spec.rb
Expand Up @@ -5,36 +5,23 @@

context "without a block" do

before do
@array = [1,3,2,4,3,5,4,6]
@uniq = @array.deduping
end

it "removes duplicates" do
@uniq.to_a.should == [1,3,2,4,5,6]
[1,3,2,4,3,5,4,6].deduping.to_a.should == [1,3,2,4,5,6]
end

end

context "with a block" do

before do
@array = %w(A1 A2 B1 A3 C1 B2 C2)
@uniq = @array.deduping { |s| s[0,1] }
end

it "uses the block to derive identity" do
@uniq.to_a.should == %w(A1 B1 C1)
@array = %w(A1 A2 B1 A3 C1 B2 C2)
@array.deduping { |s| s[0,1] }.to_a.should == %w(A1 B1 C1)
end

end

it "is lazy" do
@uniq = [1,2,3].with_time_bomb.deduping
@uniq.take(3).should == [1,2,3]
lambda do
@uniq.take(4)
end.should raise_error(Boom)
[1,2,3].with_time_bomb.deduping.first.should == 1
end

end
3 changes: 0 additions & 3 deletions spec/enumerable_fu/mixers/merge_spec.rb
Expand Up @@ -39,9 +39,6 @@
@enum2 = [2,4].with_time_bomb
@merge = Merge.new([@enum1, @enum2])
@merge.take(4).should == [1,2,3,4]
lambda do
@merge.take(5)
end.should raise_error(Boom)
end

end
3 changes: 0 additions & 3 deletions spec/enumerable_fu/mixers/zip_spec.rb
Expand Up @@ -16,9 +16,6 @@
it "is lazy" do
@zip = Zip.new([%w(a b c), [1,2].with_time_bomb])
@zip.take(2).should == [["a", 1], ["b", 2]]
lambda do
@zip.take(3)
end.should raise_error(Boom)
end

end

0 comments on commit f42b8f1

Please sign in to comment.