Sha256: 9328124717bcc45dade0c8ffef525550d2457669e6c731102ff3bc23c8d09317
Contents?: true
Size: 1.35 KB
Versions: 2
Compression:
Stored size: 1.35 KB
Contents
require 'spec_helper' describe EventMachine::Hiredis, "connecting" do let(:replies) do # shove db number into PING reply since redis has no way # of exposing the currently selected DB replies = { :select => lambda { |db| $db = db; "+OK" }, :ping => lambda { "+PONG #{$db}" }, :auth => lambda { |password| $auth = password; "+OK" }, :get => lambda { |key| $auth == "secret" ? "$3\r\nbar" : "$-1" }, } end def connect_to_mock(url, &blk) redis_mock(replies) do connect(url, &blk) end end it "doesn't call select by default" do connect_to_mock("redis://localhost:6380/") do |redis| redis.ping do |response| response.should == "PONG " done end end end it "selects the right db" do connect_to_mock("redis://localhost:6380/9") do |redis| redis.ping do |response| response.should == "PONG 9" done end end end it "authenticates with a password" do connect_to_mock("redis://:secret@localhost:6380/9") do |redis| redis.get("foo") do |response| response.should == "bar" done end end end it "rejects a bad password" do connect_to_mock("redis://:failboat@localhost:6380/9") do |redis| redis.get("foo") do |response| response.should be_nil done end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
em-hiredis-0.1.1 | spec/connection_spec.rb |
em-hiredis-0.1.0 | spec/connection_spec.rb |