spec/lol/client_spec.rb in ruby-lol-0.9.10 vs spec/lol/client_spec.rb in ruby-lol-0.9.11
- old
+ new
@@ -16,20 +16,57 @@
end
it "defaults on EUW as a region" do
expect(subject.region).to eq("euw")
end
+
+ it "sets caching if redis is specified in the options" do
+ client = Client.new "foo", redis: "redis://dummy-url"
+ expect(client.cached?).to be_true
+ end
+
+ it "sets a default ttl of 15 * 60s" do
+ client = Client.new "foo", redis: "redis://dummy-url"
+ expect(client.ttl).to eq(15*60)
+ end
+
+ it "accepts a custom ttl" do
+ client = Client.new "foo", redis: "redis://dummy-url", ttl: 10
+ expect(client.ttl).to eq(10)
+ end
+
+ it "instantiates a redis client if redis is in the options" do
+ client = Client.new "foo", redis: "redis://localhost:6379"
+ expect(client.instance_variable_get(:@redis)).to be_a(Redis)
+ end
+
+ it "passes the redis_store to the request" do
+ client = Client.new "foo", redis: "redis://localhost:6379"
+ champion_request = client.champion
+ expect(champion_request.cache_store).to eq(client.cache_store)
+ end
end
+ describe "#cached?" do
+ it "is true if @cached is true" do
+ subject.instance_variable_set(:@cached, true)
+ expect(subject.cached?).to be_true
+ end
+ it "is false if @cached is false" do
+ subject.instance_variable_set(:@cached, false)
+ expect(subject.cached?).to be_false
+ end
+ end
+
describe "#champion" do
it "returns an instance of ChampionRequest" do
expect(subject.champion).to be_a(ChampionRequest)
end
it "initializes the ChampionRequest with the current API key and region" do
- expect(ChampionRequest).to receive(:new).with(subject.api_key, subject.region)
+ expect(ChampionRequest).to receive(:new).with(subject.api_key, subject.region, subject.cache_store)
subject.champion
end
end
@@ -37,11 +74,11 @@
it "returns an instance of GameRequest" do
expect(subject.game).to be_a(GameRequest)
end
it "initializes the GameRequest with the current API key and region" do
- expect(GameRequest).to receive(:new).with(subject.api_key, subject.region)
+ expect(GameRequest).to receive(:new).with(subject.api_key, subject.region, subject.cache_store)
subject.game
end
end
@@ -49,11 +86,11 @@
it "returns an instance of StatsRequest" do
expect(subject.stats).to be_a(StatsRequest)
end
it "initializes the StatsRequest with the current API key and region" do
- expect(StatsRequest).to receive(:new).with(subject.api_key, subject.region)
+ expect(StatsRequest).to receive(:new).with(subject.api_key, subject.region, subject.cache_store)
subject.stats
end
end
@@ -61,11 +98,11 @@
it "returns an instance of TeamRequest" do
expect(subject.team).to be_a(TeamRequest)
end
it "initializes the TeamRequest with the current API key and region" do
- expect(TeamRequest).to receive(:new).with(subject.api_key, subject.region)
+ expect(TeamRequest).to receive(:new).with(subject.api_key, subject.region, subject.cache_store)
subject.team
end
end
@@ -73,11 +110,11 @@
it "returns an instance of LeagueRequest" do
expect(subject.league).to be_a(LeagueRequest)
end
it "initializes the LeagueRequest with the current API key and region" do
- expect(LeagueRequest).to receive(:new).with(subject.api_key, subject.region)
+ expect(LeagueRequest).to receive(:new).with(subject.api_key, subject.region, subject.cache_store)
subject.league
end
end
@@ -85,11 +122,11 @@
it "returns an instance of SummonerRequest" do
expect(subject.summoner).to be_a(SummonerRequest)
end
it "initializes the SummonerRequest with the current API key and region" do
- expect(SummonerRequest).to receive(:new).with(subject.api_key, subject.region)
+ expect(SummonerRequest).to receive(:new).with(subject.api_key, subject.region, subject.cache_store)
subject.summoner
end
end
@@ -97,10 +134,10 @@
it "returns an instance of StaticRequest" do
expect(subject.static).to be_a(StaticRequest)
end
it "initializes the StaticRequest with the current API key and region" do
- expect(StaticRequest).to receive(:new).with(subject.api_key, subject.region)
+ expect(StaticRequest).to receive(:new).with(subject.api_key, subject.region, subject.cache_store)
subject.static
end
end