better champ init for test and other stuff

This commit is contained in:
danijoo
2014-03-23 16:18:14 +01:00
parent b17ac7e0bd
commit 5bb4770e3c
2 changed files with 64 additions and 3 deletions

View File

@@ -1,12 +1,33 @@
require 'spec_helper' require 'spec_helper'
require 'json'
module Sightstone module Sightstone
describe Champion do describe Champion do
before :all do
json = JSON.parse('{"botMmEnabled": false,"defenseRank": 4,"attackRank": 8,"id": 266,
"rankedPlayEnabled": true,"name": "Aatrox","botEnabled": false,"difficultyRank": 6,
"active": true,"freeToPlay": false,"magicRank": 3}')
@c = Champion.new(json)
end
describe "#new" do describe "#new" do
it "should initialize a champion object" do it "should initialize a champion object" do
c = Champion.new({active: true, attackRank: 1, botEnabled: true, botMmEnabled: true, defenseRank: 1, @c.should be_an_instance_of Champion
freeToPlay: false, id: 1, magicRank: 1, name: "testName", rankedPlayEnabled: true}) end
c.should be_an_instance_of Champion
it "should initialize all attributes correctly" do
@c.botMmEnabled.should satisfy {|s| [true, false].include? s}
@c.rankedPlayEnabled.should satisfy {|s| [true, false].include? s}
@c.botEnabled.should satisfy {|s| [true, false].include? s}
@c.active.should satisfy {|s| [true, false].include? s}
@c.freeToPlay.should satisfy {|s| [true, false].include? s}
@c.defenseRank.should be_a_kind_of Fixnum
@c.difficultyRank.should be_a_kind_of Fixnum
@c.magicRank.should be_a_kind_of Fixnum
@c.attackRank.should be_a_kind_of Fixnum
@c.id.should be_a_kind_of Fixnum
@c.name.should be_a_kind_of String
end end
end end
end end

40
spec/ranked_stats_spec.rb Normal file
View File

@@ -0,0 +1,40 @@
require 'spec_helper'
module Sightstone
describe RankedStats do
before :each do
stats = [{"id" => 1, "stats"=> {"Stat1" => 1, "Stat2" => 2}}, {"id" => 2, "stats"=> {"Stat1" => 1, "Stat2" => 2}}]
@rs = RankedStats.new({"summonerId" => 1, "modifyDate" => 1, "champions" => stats })
end
it "should have a summoner id" do
@rs.summonerId.should eql 1
end
it "should have a modification date" do
@rs.modifyDate.should eql 1
end
it "should have an array of champion stats" do
@rs.champions.should be_an_instance_of Hash
@rs.champions.should have(2).items
@rs.champions.each do |key, hash|
key.should be_a_kind_of Fixnum
hash.should be_an_instance_of Hash
hash.each do |stat, value|
stat.should be_an_instance_of String
value.should be_a_kind_of Fixnum
end
end
end
describe "#new" do
it "should create a ranked stats obejct" do
@rs.should be_an_instance_of RankedStats
end
end
end
end