added specs for champion module

This commit is contained in:
danijoo
2014-03-25 11:07:22 +01:00
parent b89ae8fd4f
commit e6556976fa
7 changed files with 113 additions and 2 deletions

View File

@@ -7,6 +7,9 @@ PATH
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
addressable (2.3.6)
crack (0.4.2)
safe_yaml (~> 1.0.0)
diff-lcs (1.2.5) diff-lcs (1.2.5)
mime-types (2.2) mime-types (2.2)
rake (10.1.1) rake (10.1.1)
@@ -20,6 +23,10 @@ GEM
rspec-expectations (2.14.5) rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0) diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6) rspec-mocks (2.14.6)
safe_yaml (1.0.1)
webmock (1.17.4)
addressable (>= 2.2.7)
crack (>= 0.3.2)
PLATFORMS PLATFORMS
ruby ruby
@@ -29,3 +36,4 @@ DEPENDENCIES
rake rake
rspec rspec
sightstone! sightstone!
webmock

View File

@@ -13,7 +13,7 @@ class ChampionModule < SightstoneBaseModule
# @return [Array<Champion>] array of champs # @return [Array<Champion>] array of champs
def champions(optional={}) def champions(optional={})
region = optional[:region] || @sightstone.region region = optional[:region] || @sightstone.region
free_to_play = optional[:free_to_play] free_to_play = optional[:free_to_play] || false
uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.1/champion" uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.1/champion"
response = _get_api_response(uri, {'freeToPlay' => free_to_play}) response = _get_api_response(uri, {'freeToPlay' => free_to_play})

View File

@@ -12,5 +12,6 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'rest-client' s.add_runtime_dependency 'rest-client'
s.add_development_dependency 'rake' s.add_development_dependency 'rake'
s.add_development_dependency "rspec" s.add_development_dependency 'rspec'
s.add_development_dependency 'webmock'
end end

View File

@@ -0,0 +1,77 @@
require 'spec_helper'
module Sightstone
describe ChampionModule do
before :each do
@module = ChampionModule.new(Sightstone.new("api_key", "euw"))
end
describe "#new" do
it "should initialize a ChampionModule" do
@module.should be_instance_of ChampionModule
end
end
describe "#champions" do
before :each do
raw_response = File.new("spec/modules/raw_responses/champion_v1.1_euw.response")
stub_request(:get, "https://prod.api.pvp.net/api/lol/euw/v1.1/champion?api_key=api_key&freeToPlay=false").
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
to_return(raw_response)
raw_response_f2p = File.new("spec/modules/raw_responses/champion_v1.1_euw_f2p.response")
stub_request(:get, "https://prod.api.pvp.net/api/lol/euw/v1.1/champion?api_key=api_key&freeToPlay=true").
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
to_return(raw_response_f2p)
end
it "should return a list of champions for the default region" do
champions = @module.champions
champions.should be_instance_of Array
champions.each do |champ|
champ.should be_instance_of Champion
end
end
it "should return a list of champions for given region" do
@module.instance_variable_set("@sightstone", Sightstone.new("api_key", "na"))
champions = @module.champions(region: "euw")
champions.should be_instance_of Array
champions.each do |champ|
champ.should be_instance_of Champion
end
end
it "should only return free to play champions" do
champions = @module.champions({free_to_play: true})
champions.should be_instance_of Array
champions.each do |champ|
champ.should be_instance_of Champion
champ.freeToPlay.should be true
end
end
it "should evaluate codeblocks" do
filtered = []
@module.champions do |champions|
champions.each do |champ|
filtered << champ if champ.name == "Heimerdinger"
end
end
filtered.should have(1).item
filtered[0].name.should eql "Heimerdinger"
end
end
end
end

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,12 @@
HTTP/1.1 200 OK
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: GET, POST, DELETE, PUT
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=UTF-8
Date: Tue, 25 Mar 2014 09:57:23 GMT
Server: Jetty(9.1.1.v20140108)
Vary: Accept-Encoding, User-Agent
Content-Length: 1878
Connection: keep-alive
{"champions":[{"id":84,"name":"Akali","active":true,"attackRank":5,"defenseRank":3,"magicRank":8,"difficultyRank":6,"botEnabled":false,"freeToPlay":true,"botMmEnabled":false,"rankedPlayEnabled":true},{"id":59,"name":"JarvanIV","active":true,"attackRank":6,"defenseRank":8,"magicRank":3,"difficultyRank":5,"botEnabled":false,"freeToPlay":true,"botMmEnabled":true,"rankedPlayEnabled":true},{"id":21,"name":"MissFortune","active":true,"attackRank":8,"defenseRank":2,"magicRank":5,"difficultyRank":3,"botEnabled":true,"freeToPlay":true,"botMmEnabled":true,"rankedPlayEnabled":true},{"id":15,"name":"Sivir","active":true,"attackRank":9,"defenseRank":3,"magicRank":1,"difficultyRank":3,"botEnabled":true,"freeToPlay":true,"botMmEnabled":true,"rankedPlayEnabled":true},{"id":37,"name":"Sona","active":true,"attackRank":5,"defenseRank":2,"magicRank":8,"difficultyRank":1,"botEnabled":true,"freeToPlay":true,"botMmEnabled":true,"rankedPlayEnabled":true},{"id":16,"name":"Soraka","active":true,"attackRank":2,"defenseRank":5,"magicRank":7,"difficultyRank":3,"botEnabled":true,"freeToPlay":true,"botMmEnabled":true,"rankedPlayEnabled":true},{"id":17,"name":"Teemo","active":true,"attackRank":5,"defenseRank":3,"magicRank":7,"difficultyRank":4,"botEnabled":false,"freeToPlay":true,"botMmEnabled":false,"rankedPlayEnabled":true},{"id":101,"name":"Xerath","active":true,"attackRank":1,"defenseRank":3,"magicRank":10,"difficultyRank":6,"botEnabled":false,"freeToPlay":true,"botMmEnabled":false,"rankedPlayEnabled":true},{"id":5,"name":"XinZhao","active":true,"attackRank":8,"defenseRank":6,"magicRank":3,"difficultyRank":3,"botEnabled":true,"freeToPlay":true,"botMmEnabled":true,"rankedPlayEnabled":true},{"id":157,"name":"Yasuo","active":true,"attackRank":8,"defenseRank":4,"magicRank":4,"difficultyRank":8,"botEnabled":false,"freeToPlay":true,"botMmEnabled":false,"rankedPlayEnabled":true}]}

View File

@@ -1,5 +1,6 @@
require 'rspec' require 'rspec'
require 'sightstone' require 'sightstone'
require 'webmock/rspec'
RSpec.configure do |config| RSpec.configure do |config|
config.color_enabled = true config.color_enabled = true