adapter 0.5 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,120 @@
1
+ shared_examples_for "an adapter" do
2
+ it "can read the client" do
3
+ adapter.client.should == client
4
+ end
5
+
6
+ Adapter::Spec::Types.each do |type, (key, key2)|
7
+ it "reads from keys that are #{type}s like a Hash" do
8
+ adapter[key].should == nil
9
+ end
10
+
11
+ it "writes String values to keys that are #{type}s like a Hash" do
12
+ adapter[key] = "value"
13
+ adapter[key].should == "value"
14
+ end
15
+
16
+ it "guarantees that a different String value is retrieved from the #{type} key" do
17
+ value = "value"
18
+ adapter[key] = value
19
+ adapter[key].should_not be_equal(value)
20
+ end
21
+
22
+ it "guarantees that a different Object value is retrieved from the #{type} key" do
23
+ value = {:foo => :bar}
24
+ adapter[key] = value
25
+ adapter[key].should_not be_equal(:foo => :bar)
26
+ end
27
+
28
+ it "returns false from key? if a #{type} key is not available" do
29
+ adapter.key?(key).should be_false
30
+ end
31
+
32
+ it "returns true from key? if a #{type} key is available" do
33
+ adapter[key] = "value"
34
+ adapter.key?(key).should be_true
35
+ end
36
+
37
+ it "removes and return an element with a #{type} key from the backing store via delete if it exists" do
38
+ adapter[key] = "value"
39
+ adapter.delete(key).should == "value"
40
+ adapter.key?(key).should be_false
41
+ end
42
+
43
+ it "returns nil from delete if an element for a #{type} key does not exist" do
44
+ adapter.delete(key).should be_nil
45
+ end
46
+
47
+ it "removes all #{type} keys from the store with clear" do
48
+ adapter[key] = "value"
49
+ adapter[key2] = "value2"
50
+ adapter.clear
51
+ adapter.key?(key).should_not be_true
52
+ adapter.key?(key2).should_not be_true
53
+ end
54
+
55
+ it "fetches a #{type} key with a default value with fetch, if the key is not available" do
56
+ adapter.fetch(key, "value").should == "value"
57
+ end
58
+
59
+ it "fetches a #{type} key with a block with fetch, if the key is not available" do
60
+ adapter.fetch(key) { |k| "value" }.should == "value"
61
+ end
62
+
63
+ it "does not run the block if the #{type} key is available" do
64
+ adapter[key] = "value"
65
+ unaltered = "unaltered"
66
+ adapter.fetch(key) { unaltered = "altered" }
67
+ unaltered.should == "unaltered"
68
+ end
69
+
70
+ it "fetches a #{type} key with a default value with fetch, if the key is available" do
71
+ adapter[key] = "value2"
72
+ adapter.fetch(key, "value").should == "value2"
73
+ end
74
+
75
+ it "writes #{key} values with #write" do
76
+ adapter.write(key, "value")
77
+ adapter[key].should == "value"
78
+ end
79
+ end
80
+
81
+ it "refuses to #[] from keys that cannot be marshalled" do
82
+ lambda do
83
+ adapter[Struct.new(:foo).new(:bar)]
84
+ end.should raise_error(TypeError)
85
+ end
86
+
87
+ it "refuses to fetch from keys that cannot be marshalled" do
88
+ lambda do
89
+ adapter.fetch(Struct.new(:foo).new(:bar), true)
90
+ end.should raise_error(TypeError)
91
+ end
92
+
93
+ it "refuses to #[]= to keys that cannot be marshalled" do
94
+ lambda do
95
+ adapter[Struct.new(:foo).new(:bar)] = "value"
96
+ end.should raise_error(TypeError)
97
+ end
98
+
99
+ it "refuses to store to keys that cannot be marshalled" do
100
+ lambda do
101
+ adapter.write Struct.new(:foo).new(:bar), "value"
102
+ end.should raise_error(TypeError)
103
+ end
104
+
105
+ it "refuses to check for key? if the key cannot be marshalled" do
106
+ lambda do
107
+ adapter.key? Struct.new(:foo).new(:bar)
108
+ end.should raise_error(TypeError)
109
+ end
110
+
111
+ it "refuses to delete a key if the key cannot be marshalled" do
112
+ lambda do
113
+ adapter.delete Struct.new(:foo).new(:bar)
114
+ end.should raise_error(TypeError)
115
+ end
116
+
117
+ it "specifies that it is writable via frozen?" do
118
+ adapter.should_not be_frozen
119
+ end
120
+ end
@@ -1,7 +1,7 @@
1
1
  shared_examples_for "a json adapter" do
2
2
  it_should_behave_like 'an adapter'
3
3
 
4
- AdapterTestTypes.each do |type, (key, key2)|
4
+ Adapter::Spec::Types.each do |type, (key, key2)|
5
5
  it "writes Object values to keys that are #{type}s like a Hash" do
6
6
  adapter[key] = {:foo => :bar}
7
7
  adapter[key].should == {'foo' => 'bar'}
@@ -0,0 +1,10 @@
1
+ shared_examples_for "a marshaled adapter" do
2
+ it_should_behave_like 'an adapter'
3
+
4
+ Adapter::Spec::Types.each do |type, (key, key2)|
5
+ it "writes Object values to keys that are #{type}s like a Hash" do
6
+ adapter[key] = {:foo => :bar}
7
+ adapter[key].should == {:foo => :bar}
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module Adapter
2
+ module Spec
3
+ Types = {"String" => ["key", "key2"]}
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Adapter
2
- VERSION = '0.5'
2
+ VERSION = '0.5.1'
3
3
  end
@@ -13,9 +13,11 @@ lib_path = root_path.join('lib')
13
13
  log_path = root_path.join('log')
14
14
  log_path.mkpath
15
15
 
16
- require 'support/an_adapter'
17
- require 'support/marshal_adapter'
18
- require 'support/json_adapter'
16
+ require 'adapter/spec/an_adapter'
17
+ require 'adapter/spec/marshal_adapter'
18
+ require 'adapter/spec/json_adapter'
19
+ require 'adapter/spec/types'
20
+
19
21
  require 'support/module_helpers'
20
22
 
21
23
  logger = Logger.new(log_path.join('test.log'))
@@ -24,5 +26,3 @@ LogBuddy.init(:logger => logger)
24
26
  Rspec.configure do |c|
25
27
  c.include(ModuleHelpers)
26
28
  end
27
-
28
- AdapterTestTypes = {"String" => ["key", "key2"]}
@@ -18,12 +18,4 @@ module ModuleHelpers
18
18
  end
19
19
  end
20
20
  end
21
-
22
- def handle_failed_connections
23
- yield
24
- rescue => e
25
- puts e.inspect
26
- puts e.message unless e.message.nil?
27
- pending
28
- end
29
21
  end
metadata CHANGED
@@ -1,15 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adapter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- version: "0.5"
9
+ - 1
10
+ version: 0.5.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - John Nunemaker
14
+ - Geoffrey Dagley
15
+ - Brandon Keepers
13
16
  autorequire:
14
17
  bindir: bin
15
18
  cert_chain: []
@@ -21,6 +24,8 @@ dependencies: []
21
24
  description:
22
25
  email:
23
26
  - nunemaker@gmail.com
27
+ - gdagley@gmail.com
28
+ - brandon@opensoul.org
24
29
  executables: []
25
30
 
26
31
  extensions: []
@@ -32,6 +37,10 @@ files:
32
37
  - lib/adapter/defaults.rb
33
38
  - lib/adapter/exceptions.rb
34
39
  - lib/adapter/memory.rb
40
+ - lib/adapter/spec/an_adapter.rb
41
+ - lib/adapter/spec/json_adapter.rb
42
+ - lib/adapter/spec/marshal_adapter.rb
43
+ - lib/adapter/spec/types.rb
35
44
  - lib/adapter/version.rb
36
45
  - lib/adapter.rb
37
46
  - spec/adapter/defaults_spec.rb
@@ -39,9 +48,6 @@ files:
39
48
  - spec/adapter_spec.rb
40
49
  - spec/helper.rb
41
50
  - spec/spec.opts
42
- - spec/support/an_adapter.rb
43
- - spec/support/json_adapter.rb
44
- - spec/support/marshal_adapter.rb
45
51
  - spec/support/module_helpers.rb
46
52
  - LICENSE
47
53
  - Rakefile
@@ -1,162 +0,0 @@
1
- shared_examples_for "an adapter" do
2
- it "can read the client" do
3
- adapter.client.should == client
4
- end
5
-
6
- AdapterTestTypes.each do |type, (key, key2)|
7
- it "reads from keys that are #{type}s like a Hash" do
8
- handle_failed_connections do
9
- adapter[key].should == nil
10
- end
11
- end
12
-
13
- it "writes String values to keys that are #{type}s like a Hash" do
14
- handle_failed_connections do
15
- adapter[key] = "value"
16
- adapter[key].should == "value"
17
- end
18
- end
19
-
20
- it "guarantees that a different String value is retrieved from the #{type} key" do
21
- handle_failed_connections do
22
- value = "value"
23
- adapter[key] = value
24
- adapter[key].should_not be_equal(value)
25
- end
26
- end
27
-
28
- it "guarantees that a different Object value is retrieved from the #{type} key" do
29
- handle_failed_connections do
30
- value = {:foo => :bar}
31
- adapter[key] = value
32
- adapter[key].should_not be_equal(:foo => :bar)
33
- end
34
- end
35
-
36
- it "returns false from key? if a #{type} key is not available" do
37
- handle_failed_connections do
38
- adapter.key?(key).should be_false
39
- end
40
- end
41
-
42
- it "returns true from key? if a #{type} key is available" do
43
- handle_failed_connections do
44
- adapter[key] = "value"
45
- adapter.key?(key).should be_true
46
- end
47
- end
48
-
49
- it "removes and return an element with a #{type} key from the backing store via delete if it exists" do
50
- handle_failed_connections do
51
- adapter[key] = "value"
52
- adapter.delete(key).should == "value"
53
- adapter.key?(key).should be_false
54
- end
55
- end
56
-
57
- it "returns nil from delete if an element for a #{type} key does not exist" do
58
- handle_failed_connections do
59
- adapter.delete(key).should be_nil
60
- end
61
- end
62
-
63
- it "removes all #{type} keys from the store with clear" do
64
- handle_failed_connections do
65
- adapter[key] = "value"
66
- adapter[key2] = "value2"
67
- adapter.clear
68
- adapter.key?(key).should_not be_true
69
- adapter.key?(key2).should_not be_true
70
- end
71
- end
72
-
73
- it "fetches a #{type} key with a default value with fetch, if the key is not available" do
74
- handle_failed_connections do
75
- adapter.fetch(key, "value").should == "value"
76
- end
77
- end
78
-
79
- it "fetches a #{type} key with a block with fetch, if the key is not available" do
80
- handle_failed_connections do
81
- adapter.fetch(key) { |k| "value" }.should == "value"
82
- end
83
- end
84
-
85
- it "does not run the block if the #{type} key is available" do
86
- handle_failed_connections do
87
- adapter[key] = "value"
88
- unaltered = "unaltered"
89
- adapter.fetch(key) { unaltered = "altered" }
90
- unaltered.should == "unaltered"
91
- end
92
- end
93
-
94
- it "fetches a #{type} key with a default value with fetch, if the key is available" do
95
- handle_failed_connections do
96
- adapter[key] = "value2"
97
- adapter.fetch(key, "value").should == "value2"
98
- end
99
- end
100
-
101
- it "writes #{key} values with #write" do
102
- handle_failed_connections do
103
- adapter.write(key, "value")
104
- adapter[key].should == "value"
105
- end
106
- end
107
- end
108
-
109
- it "refuses to #[] from keys that cannot be marshalled" do
110
- handle_failed_connections do
111
- lambda do
112
- adapter[Struct.new(:foo).new(:bar)]
113
- end.should raise_error(TypeError)
114
- end
115
- end
116
-
117
- it "refuses to fetch from keys that cannot be marshalled" do
118
- handle_failed_connections do
119
- lambda do
120
- adapter.fetch(Struct.new(:foo).new(:bar), true)
121
- end.should raise_error(TypeError)
122
- end
123
- end
124
-
125
- it "refuses to #[]= to keys that cannot be marshalled" do
126
- handle_failed_connections do
127
- lambda do
128
- adapter[Struct.new(:foo).new(:bar)] = "value"
129
- end.should raise_error(TypeError)
130
- end
131
- end
132
-
133
- it "refuses to store to keys that cannot be marshalled" do
134
- handle_failed_connections do
135
- lambda do
136
- adapter.write Struct.new(:foo).new(:bar), "value"
137
- end.should raise_error(TypeError)
138
- end
139
- end
140
-
141
- it "refuses to check for key? if the key cannot be marshalled" do
142
- handle_failed_connections do
143
- lambda do
144
- adapter.key? Struct.new(:foo).new(:bar)
145
- end.should raise_error(TypeError)
146
- end
147
- end
148
-
149
- it "refuses to delete a key if the key cannot be marshalled" do
150
- handle_failed_connections do
151
- lambda do
152
- adapter.delete Struct.new(:foo).new(:bar)
153
- end.should raise_error(TypeError)
154
- end
155
- end
156
-
157
- it "specifies that it is writable via frozen?" do
158
- handle_failed_connections do
159
- adapter.should_not be_frozen
160
- end
161
- end
162
- end
@@ -1,12 +0,0 @@
1
- shared_examples_for "a marshaled adapter" do
2
- it_should_behave_like 'an adapter'
3
-
4
- AdapterTestTypes.each do |type, (key, key2)|
5
- it "writes Object values to keys that are #{type}s like a Hash" do
6
- handle_failed_connections do
7
- adapter[key] = {:foo => :bar}
8
- adapter[key].should == {:foo => :bar}
9
- end
10
- end
11
- end
12
- end