Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
[dm-sweatshop] Rearrange specs so that more of them are run when Pars…
Browse files Browse the repository at this point in the history
…eTree is not available
  • Loading branch information
xaviershay committed Sep 15, 2009
1 parent db456f6 commit 1c8d8ca
Showing 1 changed file with 47 additions and 47 deletions.
94 changes: 47 additions & 47 deletions dm-sweatshop/spec/dm-sweatshop/unique_spec.rb
Expand Up @@ -7,15 +7,15 @@
end

describe DataMapper::Sweatshop::Unique do
unless skip_tests
describe '#unique' do
before(:each) do
@ss = DataMapper::Sweatshop
DataMapper::Sweatshop::UniqueWorker.class_eval do
self.count_map = Hash.new() { 0 }
end
describe '#unique' do
before(:each) do
@ss = DataMapper::Sweatshop
DataMapper::Sweatshop::UniqueWorker.class_eval do
self.count_map = Hash.new() { 0 }
end
end

unless skip_tests
it 'for the same block, yields an incrementing value' do
(1..3).to_a.collect { @ss.unique {|x| "a#{x}"} }.should ==
%w(a0 a1 a2)
Expand All @@ -29,55 +29,55 @@
(1..3).to_a.collect { @ss.unique {|x| "a#{x}"} }.should ==
%w(a3 a4 a5)
end
else
it 'requires the ParseTree gem to test'
end

it 'allows an optional key to be specified' do
(1..3).to_a.collect { @ss.unique {|x| "a#{x}"} }.should ==
%w(a0 a1 a2)
(1..3).to_a.collect { @ss.unique(:a) {|x| "a#{x}"} }.should ==
%w(a0 a1 a2)
describe 'when the block has an arity less than 1' do
it 'keeps yielding until a unique value is generated' do
a = [1,1,1,2]
(1..2).collect { @ss.unique(:a) { a.shift }}.should ==
[1, 2]
end

describe 'when the block has an arity less than 1' do
it 'keeps yielding until a unique value is generated' do
a = [1,1,1,2]
(1..2).collect { @ss.unique { a.shift }}.should ==
[1, 2]
end

it 'raises when a unique value cannot be generated' do
a = [1,1,1, nil]
lambda {
(1..3).collect { @ss.unique { a.shift }}
}.should raise_error(DataMapper::Sweatshop::Unique::TooManyTriesException)
end
it 'raises when a unique value cannot be generated' do
a = [1,1,1, nil]
lambda {
(1..3).collect { @ss.unique(:a) { a.shift }}
}.should raise_error(DataMapper::Sweatshop::Unique::TooManyTriesException)
end
end

describe 'when ParseTree is unavilable' do
it 'raises when no key is provided' do
Object.stub!(:const_defined?).with("ParseTree").and_return(false)
lambda {
@ss.unique {}
}.should raise_error
end
it 'allows an optional key to be specified' do
(1..3).to_a.collect { @ss.unique(:a) {|x| "a#{x}"} }.should ==
%w(a0 a1 a2)
(1..3).to_a.collect { @ss.unique(:b) {|x| "a#{x}"} }.should ==
%w(a0 a1 a2)
end

it 'does not raise when a key is provided' do
lambda {
@ss.unique(:a) {}
}.should_not raise_error
end
describe 'when ParseTree is unavilable' do
it 'raises when no key is provided' do
Object.stub!(:const_defined?).with("ParseTree").and_return(false)
lambda {
@ss.unique {}
}.should raise_error
end
end

describe 'when mixing into an object' do
it 'only the unique method is added to the public interface' do
obj = Object.new
old = obj.public_methods
obj.extend(DataMapper::Sweatshop::Unique)
new = obj.public_methods
(new - old).should == ["unique"]
it 'does not raise when a key is provided' do
lambda {
@ss.unique(:a) { "a" }
}.should_not raise_error
end
end
else
it 'requires the ParseTree gem to test'
end

describe 'when mixing into an object' do
it 'only the unique method is added to the public interface' do
obj = Object.new
old = obj.public_methods
obj.extend(DataMapper::Sweatshop::Unique)
new = obj.public_methods
(new - old).should == ["unique"]
end
end
end

0 comments on commit 1c8d8ca

Please sign in to comment.