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

@@ -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 'sightstone'
require 'webmock/rspec'
RSpec.configure do |config|
config.color_enabled = true