em-redis 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,149 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/test_helper.rb")
2
-
3
- EM.describe EM::Protocols::Redis do
4
- default_timeout 1
5
-
6
- before do
7
- @c = TestConnection.new
8
- end
9
-
10
- # Inline request protocol
11
- should 'send inline commands correctly' do
12
- @c.call_command(["GET", 'a'])
13
- @c.sent_data.should == "get a\r\n"
14
- done
15
- end
16
-
17
- should "space-separate multiple inline arguments" do
18
- @c.call_command(["GET", 'a', 'b', 'c'])
19
- @c.sent_data.should == "get a b c\r\n"
20
- done
21
- end
22
-
23
- # Multiline request protocol
24
- should "send multiline commands correctly" do
25
- @c.call_command(["SET", "foo", "abc"])
26
- @c.sent_data.should == "set foo 3\r\nabc\r\n"
27
- done
28
- end
29
-
30
- should "send integers in multiline commands correctly" do
31
- @c.call_command(["SET", "foo", 1_000_000])
32
- @c.sent_data.should == "set foo 7\r\n1000000\r\n"
33
- done
34
- end
35
-
36
- # Specific calls
37
- #
38
- # SORT
39
- should "send sort command" do
40
- @c.sort "foo"
41
- @c.sent_data.should == "sort foo\r\n"
42
- done
43
- end
44
-
45
- should "send sort command with all optional parameters" do
46
- @c.sort "foo", :by => "foo_sort_*", :limit => [0, 10], :get => "data_*", :order => "DESC ALPHA"
47
- @c.sent_data.should == "sort foo BY foo_sort_* GET data_* DESC ALPHA LIMIT 0 10\r\n"
48
- done
49
- end
50
-
51
- should "parse keys response into an array" do
52
- @c.keys("*") do |resp|
53
- resp.should == ["a","b","c"]
54
- done
55
- end
56
- @c.receive_data "$5\r\na b c\r\n"
57
- end
58
-
59
-
60
- # Inline response
61
- should "parse an inline response" do
62
- @c.call_command(["PING"]) do |resp|
63
- resp.should == "OK"
64
- done
65
- end
66
- @c.receive_data "+OK\r\n"
67
- end
68
-
69
- should "parse an inline integer response" do
70
- @c.call_command(["integer"]) do |resp|
71
- resp.should == 0
72
- done
73
- end
74
- @c.receive_data ":0\r\n"
75
- end
76
-
77
- should "call processor if any" do
78
- @c.call_command(["EXISTS"]) do |resp|
79
- resp.should == false
80
- done
81
- end
82
- @c.receive_data ":0\r\n"
83
- end
84
-
85
- should "parse an inline error response" do
86
- lambda do
87
- @c.call_command(["blarg"])
88
- @c.receive_data "-FAIL\r\n"
89
- end.should.raise(EM::P::Redis::RedisError)
90
- done
91
- end
92
-
93
- should "trigger a given error callback (specified with on_error) for inline error response instead of raising an error" do
94
- lambda do
95
- @c.call_command(["blarg"])
96
- @c.on_error {|code| code.should == "FAIL"; done }
97
- @c.receive_data "-FAIL\r\n"
98
- end.should.not.raise(EM::P::Redis::RedisError)
99
- end
100
-
101
- should "trigger a given error callback for inline error response instead of raising an error" do
102
- lambda do
103
- @c.call_command(["blarg"])
104
- @c.errback { |code| code.should == "FAIL"; done }
105
- @c.receive_data "-FAIL\r\n"
106
- end.should.not.raise(EM::P::Redis::RedisError)
107
- end
108
-
109
- # Bulk response
110
- should "parse a bulk response" do
111
- @c.call_command(["GET", "foo"]) do |resp|
112
- resp.should == "bar"
113
- done
114
- end
115
- @c.receive_data "$3\r\n"
116
- @c.receive_data "bar\r\n"
117
- end
118
-
119
- should "distinguish nil in a bulk response" do
120
- @c.call_command(["GET", "bar"]) do |resp|
121
- resp.should == nil
122
- done
123
- end
124
- @c.receive_data "$-1\r\n"
125
- end
126
-
127
- # Multi-bulk response
128
- should "parse a multi-bulk response" do
129
- @c.call_command(["RANGE", 0, 10]) do |resp|
130
- resp.should == ["a", "b", "foo"]
131
- done
132
- end
133
- @c.receive_data "*3\r\n"
134
- @c.receive_data "$1\r\na\r\n"
135
- @c.receive_data "$1\r\nb\r\n"
136
- @c.receive_data "$3\r\nfoo\r\n"
137
- end
138
-
139
- should "distinguish nil in a multi-bulk response" do
140
- @c.call_command(["RANGE", 0, 10]) do |resp|
141
- resp.should == ["a", nil, "foo"]
142
- done
143
- end
144
- @c.receive_data "*3\r\n"
145
- @c.receive_data "$1\r\na\r\n"
146
- @c.receive_data "$-1\r\n"
147
- @c.receive_data "$3\r\nfoo\r\n"
148
- end
149
- end
@@ -1,25 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../lib/em-redis")
2
- require 'em-spec/bacon'
3
-
4
- EM.spec_backend = EventMachine::Spec::Bacon
5
-
6
- class TestConnection
7
- include EM::P::Redis
8
-
9
- def send_data data
10
- sent_data << data
11
- end
12
-
13
- def sent_data
14
- @sent_data ||= ''
15
- end
16
-
17
- def maybe_lock
18
- yield
19
- end
20
-
21
- def initialize
22
- super
23
- connection_completed
24
- end
25
- end