ccp 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Ccp::Kvs::Tokyo::Info do
5
+ let(:tmp) { tmp_path + "kvs/tokyo/info" }
6
+ before { FileUtils.rm_rf(tmp) if tmp.directory? }
7
+
8
+ describe ".parse" do
9
+ let(:buf) { <<-EOF
10
+ path: /tmp/tc/foo.tch
11
+ database type: hash database
12
+ record number: 0
13
+ size: 528704
14
+ EOF
15
+ }
16
+
17
+ subject { Ccp::Kvs::Tokyo::Info.parse(buf) }
18
+
19
+ its(:path ) { should == "/tmp/tc/foo.tch" }
20
+ its(:database_type) { should == "hash database" }
21
+ its(:record_number) { should == 0 }
22
+ its(:size ) { should == 528704 }
23
+
24
+ # alias
25
+ its(:count ) { should == 0 }
26
+ end
27
+ end
@@ -1,6 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'spec_helper'
3
- require 'fileutils'
4
3
 
5
4
  describe Ccp::Serializers::Core do
6
5
  subject { Object.new.extend Ccp::Serializers::Core }
@@ -0,0 +1,86 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'fileutils'
4
+
5
+ describe Ccp::Serializers do
6
+ # API
7
+ it { should respond_to(:lookup) }
8
+
9
+ describe "#reload!" do
10
+ def add_serializer(const_name)
11
+ # define a new serializer
12
+ ext = const_name.downcase
13
+ mod = Module.new
14
+ mod.module_eval <<-EOF
15
+ include Ccp::Serializers::Core
16
+ def ext; '#{ext}'; end
17
+ extend self
18
+ EOF
19
+ Ccp::Serializers[ext] = mod
20
+ end
21
+
22
+ def del_serialier(const_name)
23
+ ext = const_name.downcase
24
+ Ccp::Serializers.delete(ext)
25
+ end
26
+
27
+ specify do
28
+ # given
29
+ lambda { subject.lookup(:foo) }.should raise_error(Ccp::Serializers::NotFound)
30
+
31
+ begin
32
+ # main
33
+ add_serializer("Foo")
34
+ subject.lookup(:foo).should be_kind_of(Ccp::Serializers::Core)
35
+ ensure
36
+ del_serialier("Foo")
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "#lookup" do
42
+ context ":json" do
43
+ it "should return Ccp::Serializers::Json" do
44
+ subject.lookup(:json).should == Ccp::Serializers::Json
45
+ end
46
+ end
47
+
48
+ context "'json'" do
49
+ it "should return Ccp::Serializers::Json" do
50
+ subject.lookup('json').should == Ccp::Serializers::Json
51
+ end
52
+ end
53
+
54
+ context ":yaml" do
55
+ it "should return Ccp::Serializers::Yaml" do
56
+ subject.lookup(:yaml).should == Ccp::Serializers::Yaml
57
+ end
58
+ end
59
+
60
+ context "'yaml'" do
61
+ it "should return Ccp::Serializers::Yaml" do
62
+ subject.lookup('yaml').should == Ccp::Serializers::Yaml
63
+ end
64
+ end
65
+
66
+ context ":msgpack" do
67
+ it "should return Ccp::Serializers::Msgpack" do
68
+ subject.lookup(:msgpack).should == Ccp::Serializers::Msgpack
69
+ end
70
+ end
71
+
72
+ context "'msgpack'" do
73
+ it "should return Ccp::Serializers::Msgpack" do
74
+ subject.lookup('msgpack').should == Ccp::Serializers::Msgpack
75
+ end
76
+ end
77
+
78
+ context ":xxx" do
79
+ it "should raise NotFound" do
80
+ lambda {
81
+ subject.lookup(:xxx)
82
+ }.should raise_error(Ccp::Serializers::NotFound)
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ Ccp::Serializers.each do |serializer|
5
+ describe serializer do
6
+ its(:ext) { should == serializer.ext }
7
+
8
+ describe "#encode, #decode" do
9
+ let(:obj) { raise "Sub context responsibility" }
10
+ subject {
11
+ serializer.encode(obj).should be_kind_of(String)
12
+ serializer.decode(serializer.encode(obj)).should == obj
13
+ }
14
+
15
+ context "[1,2,3]" do
16
+ let(:obj) { [1,2,3] }
17
+ it { should be }
18
+ end
19
+
20
+ context "'foo' => 1" do
21
+ let(:obj) { { "foo" => 1 } }
22
+ it { should be }
23
+ end
24
+
25
+ context "complex objects" do
26
+ let(:obj) { {
27
+ "cpm" => 100.0,
28
+ "domains" => ["google", "yahoo"],
29
+ } }
30
+ it { should be }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,11 +1,31 @@
1
- # $:.unshift File.expand_path('..', __FILE__)
2
1
  $:.unshift File.expand_path('../../lib', __FILE__)
3
2
 
4
3
  require 'rspec'
5
4
  require 'ccp'
5
+ require 'fileutils'
6
6
 
7
7
  require File.join(File.dirname(__FILE__), "models")
8
8
 
9
+
10
+ RSpec.configure do |config|
11
+ # == Mock Framework
12
+ #
13
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
14
+ #
15
+ # config.mock_with :mocha
16
+ # config.mock_with :flexmock
17
+ # config.mock_with :rr
18
+ config.mock_with :rspec
19
+
20
+ config.filter_run :focus => true
21
+ config.run_all_when_everything_filtered = true
22
+ end
23
+
24
+
25
+ def tmp_path
26
+ Pathname(File.dirname(__FILE__)) + "../tmp"
27
+ end
28
+
9
29
  def breadcrumbs_receiver
10
30
  r = Ccp::Receivers::Base.new
11
31
  r.data[:breadcrumbs] = []
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ccp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 8
10
- version: 0.2.8
9
+ - 9
10
+ version: 0.2.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - maiha
@@ -15,12 +15,28 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-02-21 00:00:00 Z
18
+ date: 2013-08-22 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: typed
21
+ name: activesupport
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 3
31
+ - 2
32
+ - 0
33
+ version: 3.2.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: typed
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
24
40
  none: false
25
41
  requirements:
26
42
  - - ">="
@@ -32,27 +48,27 @@ dependencies:
32
48
  - 2
33
49
  version: 0.2.2
34
50
  type: :runtime
35
- version_requirements: *id001
51
+ version_requirements: *id002
36
52
  - !ruby/object:Gem::Dependency
37
53
  name: must
38
54
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
55
+ requirement: &id003 !ruby/object:Gem::Requirement
40
56
  none: false
41
57
  requirements:
42
58
  - - ">="
43
59
  - !ruby/object:Gem::Version
44
- hash: 25
60
+ hash: 5
45
61
  segments:
46
62
  - 0
47
63
  - 2
48
- - 7
49
- version: 0.2.7
64
+ - 9
65
+ version: 0.2.9
50
66
  type: :runtime
51
- version_requirements: *id002
67
+ version_requirements: *id003
52
68
  - !ruby/object:Gem::Dependency
53
69
  name: dsl_accessor
54
70
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
71
+ requirement: &id004 !ruby/object:Gem::Requirement
56
72
  none: false
57
73
  requirements:
58
74
  - - ">="
@@ -64,11 +80,70 @@ dependencies:
64
80
  - 1
65
81
  version: 0.4.1
66
82
  type: :runtime
67
- version_requirements: *id003
83
+ version_requirements: *id004
84
+ - !ruby/object:Gem::Dependency
85
+ name: json
86
+ prerelease: false
87
+ requirement: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ type: :runtime
97
+ version_requirements: *id005
98
+ - !ruby/object:Gem::Dependency
99
+ name: yajl-ruby
100
+ prerelease: false
101
+ requirement: &id006 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ type: :runtime
111
+ version_requirements: *id006
112
+ - !ruby/object:Gem::Dependency
113
+ name: msgpack
114
+ prerelease: false
115
+ requirement: &id007 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">"
119
+ - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
123
+ - 4
124
+ version: "0.4"
125
+ type: :runtime
126
+ version_requirements: *id007
127
+ - !ruby/object:Gem::Dependency
128
+ name: tokyocabinet
129
+ prerelease: false
130
+ requirement: &id008 !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ~>
134
+ - !ruby/object:Gem::Version
135
+ hash: 97
136
+ segments:
137
+ - 1
138
+ - 29
139
+ - 1
140
+ version: 1.29.1
141
+ type: :runtime
142
+ version_requirements: *id008
68
143
  - !ruby/object:Gem::Dependency
69
144
  name: rspec
70
145
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
146
+ requirement: &id009 !ruby/object:Gem::Requirement
72
147
  none: false
73
148
  requirements:
74
149
  - - ">="
@@ -78,7 +153,7 @@ dependencies:
78
153
  - 0
79
154
  version: "0"
80
155
  type: :development
81
- version_requirements: *id004
156
+ version_requirements: *id009
82
157
  description: CCP
83
158
  email:
84
159
  - maiha@wota.jp
@@ -111,6 +186,15 @@ files:
111
186
  - lib/ccp/invokers.rb
112
187
  - lib/ccp/invokers/base.rb
113
188
  - lib/ccp/invokers/spec.rb
189
+ - lib/ccp/kvs.rb
190
+ - lib/ccp/kvs/core.rb
191
+ - lib/ccp/kvs/hash.rb
192
+ - lib/ccp/kvs/tch.rb
193
+ - lib/ccp/kvs/tokyo.rb
194
+ - lib/ccp/kvs/tokyo/base.rb
195
+ - lib/ccp/kvs/tokyo/cabinet.rb
196
+ - lib/ccp/kvs/tokyo/info.rb
197
+ - lib/ccp/kvs/tokyo/state_machine.rb
114
198
  - lib/ccp/persistent.rb
115
199
  - lib/ccp/persistent/base.rb
116
200
  - lib/ccp/persistent/dir.rb
@@ -134,6 +218,7 @@ files:
134
218
  - lib/ccp/serializers.rb
135
219
  - lib/ccp/serializers/core.rb
136
220
  - lib/ccp/serializers/json.rb
221
+ - lib/ccp/serializers/msgpack.rb
137
222
  - lib/ccp/serializers/yaml.rb
138
223
  - lib/ccp/utils.rb
139
224
  - lib/ccp/utils/colorize.rb
@@ -155,6 +240,12 @@ files:
155
240
  - spec/invokers/fixture_spec.rb
156
241
  - spec/invokers/save_fixture_spec.rb
157
242
  - spec/invokers/spec_spec.rb
243
+ - spec/kvs/core_spec.rb
244
+ - spec/kvs/kvs_spec.rb
245
+ - spec/kvs/lookup_spec.rb
246
+ - spec/kvs/tch_spec.rb
247
+ - spec/kvs/tokyo/cabinet_spec.rb
248
+ - spec/kvs/tokyo/info_spec.rb
158
249
  - spec/models.rb
159
250
  - spec/persistent/base_spec.rb
160
251
  - spec/persistent/dir_spec.rb
@@ -170,9 +261,8 @@ files:
170
261
  - spec/receivers/fixture_stub_spec.rb
171
262
  - spec/receivers/skippable_spec.rb
172
263
  - spec/serializers/core_spec.rb
173
- - spec/serializers/json_spec.rb
174
- - spec/serializers/spec.rb
175
- - spec/serializers/yaml_spec.rb
264
+ - spec/serializers/lookup_spec.rb
265
+ - spec/serializers/serializer_spec.rb
176
266
  - spec/spec_helper.rb
177
267
  homepage: http://github.com/maiha/ccp
178
268
  licenses: []
@@ -1,27 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
- require 'fileutils'
4
-
5
- describe Ccp::Serializers::Json do
6
- its(:ext) { should == "json" }
7
-
8
- describe "with Array(Integer)" do
9
- it "should encode" do
10
- subject.encode([1,2,3]).should == "[1,2,3]"
11
- end
12
-
13
- it "should decode" do
14
- subject.decode("[1,2,3]").should == [1,2,3]
15
- end
16
- end
17
-
18
- describe "with {String => Integer}" do
19
- it "should encode" do
20
- subject.encode("foo" => 1).should == '{"foo":1}'
21
- end
22
-
23
- it "should decode" do
24
- subject.decode('{"foo":1}').should == {"foo" => 1}
25
- end
26
- end
27
- end
@@ -1,39 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
- require 'fileutils'
4
-
5
- describe Ccp::Serializers do
6
- describe "#lookup" do
7
- context ":json" do
8
- it "should return Ccp::Serializers::Json" do
9
- subject.lookup(:json).should == Ccp::Serializers::Json
10
- end
11
- end
12
-
13
- context "'json'" do
14
- it "should return Ccp::Serializers::Json" do
15
- subject.lookup('json').should == Ccp::Serializers::Json
16
- end
17
- end
18
-
19
- context ":yaml" do
20
- it "should return Ccp::Serializers::Yaml" do
21
- subject.lookup(:yaml).should == Ccp::Serializers::Yaml
22
- end
23
- end
24
-
25
- context "'yaml'" do
26
- it "should return Ccp::Serializers::Yaml" do
27
- subject.lookup('yaml').should == Ccp::Serializers::Yaml
28
- end
29
- end
30
-
31
- context ":xxx" do
32
- it "should raise NotFound" do
33
- lambda {
34
- subject.lookup(:xxx)
35
- }.should raise_error(Ccp::Serializers::NotFound)
36
- end
37
- end
38
- end
39
- end