summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2023-11-19 11:54:53 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2023-11-19 11:54:53 +0100
commitf3779466615840bbe5a77d5ff18cf9c3b70b8658 (patch)
treea9a05adb2c316cce2fb3f35671295329130c1fa4 /spec
parentfcf6ba4f7962f893e44aa9f3c515a64efd0c0232 (diff)
downloadcolonial-twilight-f3779466615840bbe5a77d5ff18cf9c3b70b8658.zip
colonial-twilight-f3779466615840bbe5a77d5ff18cf9c3b70b8658.tar.gz
Forces spec : improve code quality
Diffstat (limited to 'spec')
-rw-r--r--spec/forces_spec.rb85
1 files changed, 50 insertions, 35 deletions
diff --git a/spec/forces_spec.rb b/spec/forces_spec.rb
index 549b917..ce6316f 100644
--- a/spec/forces_spec.rb
+++ b/spec/forces_spec.rb
@@ -4,60 +4,72 @@ require './lib/colonial_twilight/forces'
describe ColonialTwilight::Forces do
describe 'Available' do
- f = ColonialTwilight::Forces.new :available
+ before do
+ @f = ColonialTwilight::Forces.new :available
+ end
+
it 'nil' do
%i[control fln_active].each do |sym|
- expect(f.send(sym)).to be nil
+ expect(@f.send(sym)).to be nil
end
end
it 'fln_active -> fln_underground' do
- f.add :fln_active, 1
- expect(f.fln_underground).to be 1
+ @f.add :fln_active, 1
+ expect(@f.fln_underground).to be 1
end
end
describe 'Casualties' do
- f = ColonialTwilight::Forces.new :casualties
+ before do
+ @f = ColonialTwilight::Forces.new :casualties
+ end
+
it 'nil' do
%i[control fln_active fln_bases].each do |sym|
- expect(f.send(sym)).to be nil
+ expect(@f.send(sym)).to be nil
end
end
it 'raise' do
%i[fln_active fln_bases].each do |sym|
- expect { f.add sym, 1 }.to raise_error(Exception)
+ expect { @f.add sym, 1 }.to raise_error(Exception)
end
end
end
describe 'OutOfPlay' do
- f = ColonialTwilight::Forces.new :out_of_play
+ before do
+ @f = ColonialTwilight::Forces.new :out_of_play
+ end
+
it 'nil' do
%i[control algerian_troops algerian_police fln_active fln_bases].each do |sym|
- expect(f.send(sym)).to be nil
+ expect(@f.send(sym)).to be nil
end
end
it 'raise' do
%i[algerian_troops algerian_police fln_active fln_bases].each do |sym|
- expect { f.add sym, 1 }.to raise_error(Exception)
+ expect { @f.add sym, 1 }.to raise_error(Exception)
end
end
end
describe 'Country' do
- f = ColonialTwilight::Forces.new :Country
+ before do
+ @f = ColonialTwilight::Forces.new :Country
+ end
+
it 'nil' do
%i[control algerian_troops algerian_police french_troops french_police].each do |sym|
- expect(f.send(sym)).to be nil
+ expect(@f.send(sym)).to be nil
end
end
it 'raise' do
%i[algerian_troops algerian_police french_troops french_police].each do |sym|
- expect { f.add sym, 1 }.to raise_error(Exception)
+ expect { @f.add sym, 1 }.to raise_error(Exception)
end
end
end
@@ -67,60 +79,63 @@ describe ColonialTwilight::Forces do
end
describe 'Sector' do
- f = ColonialTwilight::Forces.new :Sector
- data = { fln_bases: 0, gov_bases: 1, algerian_troops: 2, algerian_police: 3,
- french_troops: 4, french_police: 5, fln_underground: 6, fln_active: 7 }
- f.init data
+ before do
+ @f = ColonialTwilight::Forces.new :Sector
+ @data = { fln_bases: 0, gov_bases: 1, algerian_troops: 2, algerian_police: 3,
+ french_troops: 4, french_police: 5, fln_underground: 6, fln_active: 7 }
+ @f.init @data
+ end
+
it 'init' do
- data.keys.each_with_index do |k, i|
- expect(f.send(k)).to be i
+ @data.keys.each_with_index do |k, i|
+ expect(@f.send(k)).to be i
end
end
it 'count bases' do
- expect(f.bases).to be 1
+ expect(@f.bases).to be 1
end
it 'count fln' do
- expect(f.fln).to be 13
+ expect(@f.fln).to be 13
end
it 'count guerrillas' do
- expect(f.guerrillas).to be 13
+ expect(@f.guerrillas).to be 13
end
it 'count troops' do
- expect(f.troops).to be 6
+ expect(@f.troops).to be 6
end
it 'count police' do
- expect(f.police).to be 8
+ expect(@f.police).to be 8
end
it 'switch control' do
- expect(f.control).to be :GOV
- f.add :fln_active, 2
- expect(f.control).to be :uncontrolled
- f.add :fln_active, 1
- expect(f.control).to be :FLN
+ expect(@f.control).to be :GOV
+ @f.add :fln_active, 2
+ expect(@f.control).to be :uncontrolled
+ @f.add :fln_active, 1
+ expect(@f.control).to be :FLN
end
it 'inspect' do
- expect(f.inspect.instance_of?(String)).to be true
+ expect(@f.inspect.instance_of?(String)).to be true
end
it 'raise' do
- expect { f.add :fln_bases, 2 }.to raise_error(Exception)
+ expect { @f.add :fln_bases, 2 }.to raise_error(Exception)
end
it 'raise wrong type' do
- expect { f.add :wrong, 1 }.to raise_error(Exception)
+ expect { @f.add :wrong, 1 }.to raise_error(Exception)
end
it 'data' do
- d = f.data
- data.keys do |k, v|
- expect(d[k]).to be v
+ d = @f.data
+ @data.keys do |k, v|
+ expect(d[k]).to be v
end
end
end