Extracting tournament round building logic
This commit is contained in:
64
rails/map-mash/spec/lib/mash_tournament_builder_spec.rb
Normal file
64
rails/map-mash/spec/lib/mash_tournament_builder_spec.rb
Normal file
@@ -0,0 +1,64 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe MashTournamentBuilder do
|
||||
let(:subject) do
|
||||
MashTournamentBuilder.new(
|
||||
MashTournament.make(:requester => Requester.make),
|
||||
MashTournament, MashTournamentRound, Map, Mash
|
||||
)
|
||||
end
|
||||
|
||||
let(:mock_subject) do
|
||||
@tournament = mock(Object)
|
||||
@tournament_model = mock(Object)
|
||||
@round_model = mock(Object)
|
||||
@map_model = mock(Object)
|
||||
@mash_model = mock(Object)
|
||||
|
||||
MashTournamentBuilder.new(
|
||||
@tournament, @tournament_model,
|
||||
@round_model, @map_model, @mash_model
|
||||
)
|
||||
end
|
||||
|
||||
context 'creating rounds' do
|
||||
it 'should reject invalid numbers of contenders' do
|
||||
[11, 24, 40].each do |n|
|
||||
expect do
|
||||
subject.create_rounds_for_contenders(n)
|
||||
end.to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
before(:all) do
|
||||
subject.map_model.destroy_all
|
||||
40.times do
|
||||
subject.map_model.make.save
|
||||
end
|
||||
end
|
||||
|
||||
[[8, 3], [16, 4], [32, 5]].each do |n_contenders,n_rounds|
|
||||
context "for #{n_contenders} total contenders" do
|
||||
it "should create #{n_rounds} rounds" do
|
||||
subject.create_rounds_for_contenders(n_contenders)
|
||||
subject.tournament.total_rounds.should == n_rounds
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'filling in rounds' do
|
||||
before(:each) do
|
||||
subject.id.should_not be_nil
|
||||
subject.create_rounds_for_contenders(8)
|
||||
end
|
||||
|
||||
xit 'should fill in every map for every mash in a given round' do
|
||||
subject.fill_in_next_round
|
||||
subject.round(1).mashes.each do |mash|
|
||||
mash.map_a.should_not be_nil
|
||||
mash.map_b.should_not be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -5,56 +5,7 @@ describe MashTournament do
|
||||
@valid_attributes = {:requester_id => 1}
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
@requester = Requester.make
|
||||
@requester.save!
|
||||
subject.requester_id = @requester.id
|
||||
subject.save!
|
||||
subject.reload
|
||||
end
|
||||
|
||||
it "should create a new instance given valid attributes" do
|
||||
MashTournament.create!(@valid_attributes)
|
||||
end
|
||||
|
||||
context 'creating rounds' do
|
||||
it 'should reject invalid numbers of contenders' do
|
||||
[11, 24, 40].each do |n|
|
||||
expect do
|
||||
subject.create_rounds_for_contenders(n)
|
||||
end.to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
before(:all) do
|
||||
Map.destroy_all
|
||||
40.times do
|
||||
Map.make.save
|
||||
end
|
||||
end
|
||||
|
||||
[[8, 3], [16, 4], [32, 5]].each do |n_contenders,n_rounds|
|
||||
context "for #{n_contenders} total contenders" do
|
||||
it "should create #{n_rounds} rounds" do
|
||||
subject.create_rounds_for_contenders(n_contenders)
|
||||
subject.total_rounds.should == n_rounds
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'filling in rounds' do
|
||||
before(:each) do
|
||||
subject.id.should_not be_nil
|
||||
subject.create_rounds_for_contenders(8)
|
||||
end
|
||||
|
||||
xit 'should fill in every map for every mash in a given round' do
|
||||
subject.fill_in_next_round
|
||||
subject.round(1).mashes.each do |mash|
|
||||
mash.map_a.should_not be_nil
|
||||
mash.map_b.should_not be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user