From 5bb4770e3c29ee3490fe84b79242405f62e848fb Mon Sep 17 00:00:00 2001 From: danijoo Date: Sun, 23 Mar 2014 16:18:14 +0100 Subject: [PATCH] better champ init for test and other stuff --- spec/champion_spec.rb | 27 +++++++++++++++++++++++--- spec/ranked_stats_spec.rb | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 spec/ranked_stats_spec.rb diff --git a/spec/champion_spec.rb b/spec/champion_spec.rb index 4247745..46747f2 100644 --- a/spec/champion_spec.rb +++ b/spec/champion_spec.rb @@ -1,12 +1,33 @@ require 'spec_helper' +require 'json' module Sightstone 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 it "should initialize a champion object" do - c = Champion.new({active: true, attackRank: 1, botEnabled: true, botMmEnabled: true, defenseRank: 1, - freeToPlay: false, id: 1, magicRank: 1, name: "testName", rankedPlayEnabled: true}) - c.should be_an_instance_of Champion + @c.should be_an_instance_of Champion + end + + 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 diff --git a/spec/ranked_stats_spec.rb b/spec/ranked_stats_spec.rb new file mode 100644 index 0000000..54475a2 --- /dev/null +++ b/spec/ranked_stats_spec.rb @@ -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