picky 2.0.0.pre2 → 2.0.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/lib/picky/application.rb +1 -1
  2. data/lib/picky/cli.rb +2 -2
  3. data/lib/picky/index/base.rb +1 -1
  4. data/lib/picky/internals/generators/similarity/double_metaphone.rb +32 -0
  5. data/lib/picky/internals/generators/similarity/metaphone.rb +32 -0
  6. data/lib/picky/internals/generators/similarity/{double_levenshtone.rb → phonetic.rb} +9 -21
  7. data/lib/picky/internals/generators/similarity/soundex.rb +32 -0
  8. data/lib/picky/internals/index/redis/basic.rb +15 -15
  9. data/lib/picky/internals/index/redis/list_hash.rb +13 -13
  10. data/lib/picky/internals/index/redis/string_hash.rb +11 -9
  11. data/lib/picky/internals/indexers/serial.rb +8 -8
  12. data/lib/picky/internals/indexing/bundle/base.rb +1 -1
  13. data/lib/picky/internals/indexing/bundle/memory.rb +1 -4
  14. data/lib/picky/internals/indexing/category.rb +3 -3
  15. data/lib/picky/internals/query/combinations/base.rb +5 -11
  16. data/lib/picky/internals/query/combinations/redis.rb +44 -24
  17. data/lib/picky/internals/query/indexes.rb +29 -24
  18. data/lib/picky/internals/query/token.rb +12 -12
  19. data/lib/picky/internals/tokenizers/base.rb +1 -1
  20. data/lib/picky/loader.rb +4 -4
  21. data/lib/picky/sources/couch.rb +4 -6
  22. data/lib/picky/sources/delicious.rb +1 -1
  23. data/spec/lib/analyzer_spec.rb +18 -0
  24. data/spec/lib/application_spec.rb +13 -3
  25. data/spec/lib/bundling_spec.rb +21 -0
  26. data/spec/lib/character_substituters/west_european_spec.rb +8 -2
  27. data/spec/lib/cli_spec.rb +45 -17
  28. data/spec/lib/index/redis_spec.rb +15 -0
  29. data/spec/lib/internals/adapters/rack/live_parameters_spec.rb +11 -6
  30. data/spec/lib/internals/frontend_adapters/rack_spec.rb +22 -0
  31. data/spec/lib/internals/generators/similarity/{double_levenshtone_spec.rb → double_metaphone_spec.rb} +1 -7
  32. data/spec/lib/internals/generators/similarity/metaphone_spec.rb +60 -0
  33. data/spec/lib/internals/generators/similarity/phonetic_spec.rb +13 -0
  34. data/spec/lib/internals/generators/similarity/soundex_spec.rb +60 -0
  35. data/spec/lib/internals/generators/similarity_generator_spec.rb +1 -1
  36. data/spec/lib/internals/index/file/basic_spec.rb +15 -5
  37. data/spec/lib/internals/index/redis/list_hash_spec.rb +34 -0
  38. data/spec/lib/internals/index/redis/string_hash_spec.rb +12 -0
  39. data/spec/lib/internals/indexed/bundle/memory_spec.rb +66 -0
  40. data/spec/lib/internals/indexing/bundle/memory_spec.rb +87 -71
  41. data/spec/lib/internals/indexing/bundle/redis_spec.rb +282 -0
  42. data/spec/lib/internals/indexing/bundle/super_base_spec.rb +1 -1
  43. data/spec/lib/internals/indexing/categories_spec.rb +49 -0
  44. data/spec/lib/internals/indexing/category_spec.rb +68 -35
  45. data/spec/lib/query/combinations/base_spec.rb +0 -9
  46. data/spec/lib/query/combinations/memory_spec.rb +0 -9
  47. data/spec/lib/query/combinations/redis_spec.rb +40 -5
  48. data/spec/lib/sources/couch_spec.rb +22 -0
  49. data/spec/lib/sources/csv_spec.rb +7 -0
  50. data/spec/lib/sources/db_spec.rb +7 -1
  51. data/spec/lib/sources/delicious_spec.rb +6 -2
  52. metadata +26 -5
@@ -0,0 +1,282 @@
1
+ require 'spec_helper'
2
+
3
+ describe Internals::Indexing::Bundle::Redis do
4
+
5
+ before(:each) do
6
+ @internal_index = stub :index, :name => :some_index
7
+ @category = stub :category, :name => :some_category
8
+ @configuration = Configuration::Index.new @internal_index, @category
9
+
10
+ @partial = stub :partial
11
+ @weights = stub :weights
12
+ @similarity = stub :similarity
13
+ end
14
+ let(:index) { described_class.new :some_name, @configuration, @similarity, @partial, @weights }
15
+
16
+ describe 'raise_cache_missing' do
17
+ it 'does something' do
18
+ expect {
19
+ index.raise_cache_missing :similarity
20
+ }.to raise_error("Error: The similarity cache for some_index:some_category:some_name is missing.")
21
+ end
22
+ end
23
+
24
+ describe 'warn_cache_small' do
25
+ it 'warns the user' do
26
+ index.should_receive(:warn).once.with "Warning: similarity cache for some_index:some_category:some_name smaller than 16 bytes."
27
+
28
+ index.warn_cache_small :similarity
29
+ end
30
+ end
31
+
32
+ describe 'identifier' do
33
+ it 'should return a specific identifier' do
34
+ index.identifier.should == 'some_index:some_category:some_name'
35
+ end
36
+ end
37
+
38
+ describe 'initialize_index_for' do
39
+ context 'token not yet assigned' do
40
+ before(:each) do
41
+ index.stub! :index => {}
42
+ end
43
+ it 'should assign it an empty array' do
44
+ index.initialize_index_for :some_token
45
+
46
+ index.index[:some_token].should == []
47
+ end
48
+ end
49
+ context 'token already assigned' do
50
+ before(:each) do
51
+ index.stub! :index => { :some_token => :already_assigned }
52
+ end
53
+ it 'should not assign it anymore' do
54
+ index.initialize_index_for :some_token
55
+
56
+ index.index[:some_token].should == :already_assigned
57
+ end
58
+ end
59
+ end
60
+
61
+ describe 'retrieve' do
62
+ before(:each) do
63
+ files = stub :files
64
+ files.should_receive(:retrieve).once.and_yield ' 1234', :some_token
65
+ index.stub! :files => files
66
+
67
+ @ary = stub :ary
68
+ @internal_index.should_receive(:[]).any_number_of_times.and_return @ary
69
+ index.stub! :index => @internal_index
70
+ end
71
+ context 'id key format' do
72
+ before(:each) do
73
+ index.should_receive(:[]).once.with(:key_format).and_return :to_i
74
+ end
75
+ it 'should call the other methods correctly' do
76
+ @ary.should_receive(:<<).once.with 1234
77
+
78
+ index.retrieve
79
+ end
80
+ end
81
+ context 'other key format' do
82
+ before(:each) do
83
+ index.should_receive(:[]).once.with(:key_format).and_return :strip
84
+ end
85
+ it 'should call the other methods correctly' do
86
+ @ary.should_receive(:<<).once.with '1234'
87
+
88
+ index.retrieve
89
+ end
90
+ end
91
+ context 'no key format - default' do
92
+ before(:each) do
93
+ index.should_receive(:[]).once.with(:key_format).and_return nil
94
+ end
95
+ it 'should call the other methods correctly' do
96
+ @ary.should_receive(:<<).once.with 1234
97
+
98
+ index.retrieve
99
+ end
100
+ end
101
+ end
102
+
103
+ describe 'load_from_index_file' do
104
+ it 'should call two methods in order' do
105
+ index.should_receive(:load_from_index_generation_message).once.ordered
106
+ index.should_receive(:clear).once.ordered
107
+ index.should_receive(:retrieve).once.ordered
108
+
109
+ index.load_from_index_file
110
+ end
111
+ end
112
+
113
+ describe 'generate_derived' do
114
+ it 'should call two methods in order' do
115
+ index.should_receive(:generate_weights).once.ordered
116
+ index.should_receive(:generate_similarity).once.ordered
117
+
118
+ index.generate_derived
119
+ end
120
+ end
121
+
122
+ describe 'generate_caches_from_memory' do
123
+ it 'should call two methods in order' do
124
+ index.should_receive(:cache_from_memory_generation_message).once.ordered
125
+ index.should_receive(:generate_derived).once.ordered
126
+
127
+ index.generate_caches_from_memory
128
+ end
129
+ end
130
+
131
+ describe 'generate_caches_from_source' do
132
+ it 'should call two methods in order' do
133
+ index.should_receive(:load_from_index_file).once.ordered
134
+ index.should_receive(:generate_caches_from_memory).once.ordered
135
+
136
+ index.generate_caches_from_source
137
+ end
138
+ end
139
+
140
+ describe 'dump' do
141
+ it 'should trigger dumps' do
142
+ index.should_receive(:dump_index).once.with
143
+ index.should_receive(:dump_weights).once.with
144
+ index.should_receive(:dump_similarity).once.with
145
+ index.should_receive(:dump_configuration).once.with
146
+
147
+ index.dump
148
+ end
149
+ end
150
+
151
+ describe 'raise_unless_cache_exists' do
152
+ it "calls methods in order" do
153
+ index.should_receive(:raise_unless_index_exists).once.ordered
154
+ index.should_receive(:raise_unless_similarity_exists).once.ordered
155
+
156
+ index.raise_unless_cache_exists
157
+ end
158
+ end
159
+ describe 'raise_unless_index_exists' do
160
+ context 'partial strategy saved' do
161
+ before(:each) do
162
+ strategy = stub :strategy, :saved? => true
163
+ index.stub! :partial_strategy => strategy
164
+ end
165
+ it "calls the methods in order" do
166
+ index.should_receive(:warn_if_index_small).once.ordered
167
+ index.should_receive(:raise_unless_index_ok).once.ordered
168
+
169
+ index.raise_unless_index_exists
170
+ end
171
+ end
172
+ context 'partial strategy not saved' do
173
+ before(:each) do
174
+ strategy = stub :strategy, :saved? => false
175
+ index.stub! :partial_strategy => strategy
176
+ end
177
+ it "calls nothing" do
178
+ index.should_receive(:warn_if_index_small).never
179
+ index.should_receive(:raise_unless_index_ok).never
180
+
181
+ index.raise_unless_index_exists
182
+ end
183
+ end
184
+ end
185
+ describe 'raise_unless_similarity_exists' do
186
+ context 'similarity strategy saved' do
187
+ before(:each) do
188
+ strategy = stub :strategy, :saved? => true
189
+ index.stub! :similarity_strategy => strategy
190
+ end
191
+ it "calls the methods in order" do
192
+ index.should_receive(:warn_if_similarity_small).once.ordered
193
+ index.should_receive(:raise_unless_similarity_ok).once.ordered
194
+
195
+ index.raise_unless_similarity_exists
196
+ end
197
+ end
198
+ context 'similarity strategy not saved' do
199
+ before(:each) do
200
+ strategy = stub :strategy, :saved? => false
201
+ index.stub! :similarity_strategy => strategy
202
+ end
203
+ it "calls nothing" do
204
+ index.should_receive(:warn_if_similarity_small).never
205
+ index.should_receive(:raise_unless_similarity_ok).never
206
+
207
+ index.raise_unless_similarity_exists
208
+ end
209
+ end
210
+ end
211
+ describe 'warn_if_similarity_small' do
212
+ let(:backend) { index.backend }
213
+ context "files similarity cache small" do
214
+ before(:each) do
215
+ backend.stub! :similarity_cache_small? => true
216
+ end
217
+ it "warns" do
218
+ index.should_receive(:warn_cache_small).once.with :similarity
219
+
220
+ index.warn_if_similarity_small
221
+ end
222
+ end
223
+ context "files similarity cache not small" do
224
+ before(:each) do
225
+ backend.stub! :similarity_cache_small? => false
226
+ end
227
+ it "does not warn" do
228
+ index.should_receive(:warn_cache_small).never
229
+
230
+ index.warn_if_similarity_small
231
+ end
232
+ end
233
+ end
234
+ describe 'raise_unless_similarity_ok' do
235
+ let(:backend) { index.backend }
236
+ context "files similarity cache ok" do
237
+ before(:each) do
238
+ backend.stub! :similarity_cache_ok? => true
239
+ end
240
+ it "warns" do
241
+ index.should_receive(:raise_cache_missing).never
242
+
243
+ index.raise_unless_similarity_ok
244
+ end
245
+ end
246
+ context "files similarity cache not ok" do
247
+ before(:each) do
248
+ backend.stub! :similarity_cache_ok? => false
249
+ end
250
+ it "does not warn" do
251
+ index.should_receive(:raise_cache_missing).once.with :similarity
252
+
253
+ index.raise_unless_similarity_ok
254
+ end
255
+ end
256
+ end
257
+
258
+ describe 'initialization' do
259
+ it 'should initialize the index correctly' do
260
+ index.index.should == {}
261
+ end
262
+ it 'should initialize the weights index correctly' do
263
+ index.weights.should == {}
264
+ end
265
+ it 'should initialize the similarity index correctly' do
266
+ index.similarity.should == {}
267
+ end
268
+ it 'should initialize the configuration correctly' do
269
+ index.configuration.should == {}
270
+ end
271
+ it 'should initialize the partial strategy correctly' do
272
+ index.partial_strategy.should == @partial
273
+ end
274
+ it 'should initialize the weights strategy correctly' do
275
+ index.weights_strategy.should == @weights
276
+ end
277
+ it 'should initialize the similarity strategy correctly' do
278
+ index.similarity_strategy.should == @similarity
279
+ end
280
+ end
281
+
282
+ end
@@ -5,7 +5,7 @@ describe Internals::Indexing::Bundle::SuperBase do
5
5
  before(:each) do
6
6
  @configuration = stub :configuration, :identifier => 'some_identifier'
7
7
  Internals::Index::Files.stub! :new
8
- @similarity = Similarity::Phonetic.new 3
8
+ @similarity = Similarity::DoubleMetaphone.new 3
9
9
  @bundle = described_class.new :some_name, @configuration, @similarity
10
10
  end
11
11
 
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe Internals::Indexing::Categories do
4
+
5
+ let(:categories) { described_class.new }
6
+
7
+ describe 'to_s' do
8
+ context 'no categories' do
9
+ it 'outputs the right thing' do
10
+ categories.to_s.should == ""
11
+ end
12
+ end
13
+ context 'with categories' do
14
+ before(:each) do
15
+ index = stub :index, :name => :some_name
16
+ categories << Internals::Indexing::Category.new(:some_name, index, :source => stub(:source))
17
+ end
18
+ it 'outputs the right thing' do
19
+ categories.to_s.should == " Category(some_name from some_name):\n Exact:\n Memory\n Partial:\n Memory\n"
20
+ end
21
+ end
22
+ end
23
+
24
+ describe 'find' do
25
+ context 'no categories' do
26
+ it 'raises on none existent category' do
27
+ expect do
28
+ categories.find :some_non_existent_name
29
+ end.to raise_error(%Q{Index category "some_non_existent_name" not found. Possible categories: "".})
30
+ end
31
+ end
32
+ context 'with categories' do
33
+ before(:each) do
34
+ index = stub :index, :name => :some_name
35
+ @category = Internals::Indexing::Category.new(:some_name, index, :source => stub(:source))
36
+ categories << @category
37
+ end
38
+ it 'returns it if found' do
39
+ categories.find(:some_name).should == @category
40
+ end
41
+ it 'raises on none existent category' do
42
+ expect do
43
+ categories.find :some_non_existent_name
44
+ end.to raise_error(%Q{Index category "some_non_existent_name" not found. Possible categories: "some_name".})
45
+ end
46
+ end
47
+ end
48
+
49
+ end
@@ -5,103 +5,136 @@ describe Internals::Indexing::Category do
5
5
  before(:each) do
6
6
  @index = stub :index, :name => :some_index
7
7
  @source = stub :some_given_source, :key_format => nil
8
- @category = described_class.new :some_category, @index, :source => @source
9
8
  end
9
+ let(:category) { described_class.new(:some_category, @index, :source => @source).tap { |c| c.stub! :timed_exclaim } }
10
+
10
11
  context "unit specs" do
11
- before(:each) do
12
- @exact = @category.exact
13
- @partial = @category.partial
12
+ let(:exact) { category.exact }
13
+ let(:partial) { category.partial }
14
+
15
+ describe 'backup_caches' do
16
+ it 'delegates to both bundles' do
17
+ exact.should_receive(:backup).once.with()
18
+ partial.should_receive(:backup).once.with()
19
+
20
+ category.backup_caches
21
+ end
22
+ end
23
+ describe 'restore_caches' do
24
+ it 'delegates to both bundles' do
25
+ exact.should_receive(:restore).once.with()
26
+ partial.should_receive(:restore).once.with()
27
+
28
+ category.restore_caches
29
+ end
14
30
  end
31
+ describe 'check_caches' do
32
+ it 'delegates to both bundles' do
33
+ exact.should_receive(:raise_unless_cache_exists).once.with()
34
+ partial.should_receive(:raise_unless_cache_exists).once.with()
35
+
36
+ category.check_caches
37
+ end
38
+ end
39
+ describe 'clear_caches' do
40
+ it 'delegates to both bundles' do
41
+ exact.should_receive(:delete).once.with()
42
+ partial.should_receive(:delete).once.with()
43
+
44
+ category.clear_caches
45
+ end
46
+ end
47
+
15
48
  describe 'dump_caches' do
16
49
  before(:each) do
17
- @exact.stub! :dump
18
- @partial.stub! :dump
50
+ exact.stub! :dump
51
+ partial.stub! :dump
19
52
  end
20
53
  it 'should dump the exact index' do
21
- @exact.should_receive(:dump).once.with
54
+ exact.should_receive(:dump).once.with
22
55
 
23
- @category.dump_caches
56
+ category.dump_caches
24
57
  end
25
58
  it 'should dump the partial index' do
26
- @partial.should_receive(:dump).once.with
59
+ partial.should_receive(:dump).once.with
27
60
 
28
- @category.dump_caches
61
+ category.dump_caches
29
62
  end
30
63
  end
31
64
 
32
65
  describe 'generate_caches_from_memory' do
33
66
  it 'should delegate to partial' do
34
- @partial.should_receive(:generate_caches_from_memory).once.with
67
+ partial.should_receive(:generate_caches_from_memory).once.with
35
68
 
36
- @category.generate_caches_from_memory
69
+ category.generate_caches_from_memory
37
70
  end
38
71
  end
39
72
 
40
73
  describe 'generate_partial' do
41
74
  it 'should return whatever the partial generation returns' do
42
- @exact.stub! :index
43
- @partial.stub! :generate_partial_from => :generation_returns
75
+ exact.stub! :index
76
+ partial.stub! :generate_partial_from => :generation_returns
44
77
 
45
- @category.generate_partial
78
+ category.generate_partial
46
79
  end
47
80
  it 'should use the exact index to generate the partial index' do
48
81
  exact_index = stub :exact_index
49
- @exact.stub! :index => exact_index
50
- @partial.should_receive(:generate_partial_from).once.with(exact_index)
82
+ exact.stub! :index => exact_index
83
+ partial.should_receive(:generate_partial_from).once.with(exact_index)
51
84
 
52
- @category.generate_partial
85
+ category.generate_partial
53
86
  end
54
87
  end
55
88
 
56
89
  describe 'generate_caches_from_source' do
57
90
  it 'should delegate to exact' do
58
- @exact.should_receive(:generate_caches_from_source).once.with
91
+ exact.should_receive(:generate_caches_from_source).once.with
59
92
 
60
- @category.generate_caches_from_source
93
+ category.generate_caches_from_source
61
94
  end
62
95
  end
63
96
 
64
97
  describe 'generate_caches' do
65
98
  it 'should call multiple methods in order' do
66
- @category.should_receive(:generate_caches_from_source).once.with().ordered
67
- @category.should_receive(:generate_partial).once.with().ordered
68
- @category.should_receive(:generate_caches_from_memory).once.with().ordered
69
- @category.should_receive(:dump_caches).once.with().ordered
70
- @category.should_receive(:timed_exclaim).once.ordered
99
+ category.should_receive(:generate_caches_from_source).once.with().ordered
100
+ category.should_receive(:generate_partial).once.with().ordered
101
+ category.should_receive(:generate_caches_from_memory).once.with().ordered
102
+ category.should_receive(:dump_caches).once.with().ordered
103
+ category.should_receive(:timed_exclaim).once.ordered
71
104
 
72
- @category.generate_caches
105
+ category.generate_caches
73
106
  end
74
107
  end
75
108
 
76
109
  describe "cache" do
77
110
  before(:each) do
78
- @category.stub! :generate_caches
111
+ category.stub! :generate_caches
79
112
  end
80
113
  it "prepares the cache directory" do
81
- @category.should_receive(:prepare_index_directory).once.with
114
+ category.should_receive(:prepare_index_directory).once.with
82
115
 
83
- @category.cache
116
+ category.cache
84
117
  end
85
118
  it "tells the indexer to index" do
86
- @category.should_receive(:generate_caches).once.with
119
+ category.should_receive(:generate_caches).once.with
87
120
 
88
- @category.cache
121
+ category.cache
89
122
  end
90
123
  end
91
124
  describe "index" do
92
125
  before(:each) do
93
126
  @indexer = stub :indexer, :index => nil
94
- @category.stub! :indexer => @indexer
127
+ category.stub! :indexer => @indexer
95
128
  end
96
129
  it "prepares the cache directory" do
97
- @category.should_receive(:prepare_index_directory).once.with
130
+ category.should_receive(:prepare_index_directory).once.with
98
131
 
99
- @category.index
132
+ category.index
100
133
  end
101
134
  it "tells the indexer to index" do
102
135
  @indexer.should_receive(:index).once.with
103
136
 
104
- @category.index
137
+ category.index
105
138
  end
106
139
  end
107
140
  describe "source" do
@@ -10,15 +10,6 @@ describe Internals::Query::Combinations::Base do
10
10
  @combinations = described_class.new @combinations_ary
11
11
  end
12
12
 
13
- describe "pack_into_allocation" do
14
- it "return an Allocation" do
15
- @combinations.pack_into_allocation(:some_result_identifier).should be_kind_of(Internals::Query::Allocation)
16
- end
17
- it "returns an Allocation with specific result_identifier" do
18
- @combinations.pack_into_allocation(:some_result_identifier).result_identifier.should == :some_result_identifier
19
- end
20
- end
21
-
22
13
  describe "to_result" do
23
14
  before(:each) do
24
15
  @combination1 = stub :combination1, :to_result => :result1
@@ -10,15 +10,6 @@ describe Internals::Query::Combinations::Memory do
10
10
  @combinations = described_class.new @combinations_ary
11
11
  end
12
12
 
13
- describe "pack_into_allocation" do
14
- it "return an Allocation" do
15
- @combinations.pack_into_allocation(:some_result_identifier).should be_kind_of(Internals::Query::Allocation)
16
- end
17
- it "returns an Allocation with specific result_identifier" do
18
- @combinations.pack_into_allocation(:some_result_identifier).result_identifier.should == :some_result_identifier
19
- end
20
- end
21
-
22
13
  describe "to_result" do
23
14
  before(:each) do
24
15
  @combination1 = stub :combination1, :to_result => :result1
@@ -10,12 +10,47 @@ describe Internals::Query::Combinations::Redis do
10
10
  @combinations = described_class.new @combinations_ary
11
11
  end
12
12
 
13
- describe "pack_into_allocation" do
14
- it "return an Allocation" do
15
- @combinations.pack_into_allocation(:some_result_identifier).should be_kind_of(Internals::Query::Allocation)
13
+ describe 'ids' do
14
+ context 'empty combinations' do
15
+ let(:combinations) { described_class.new [] }
16
+ it 'does something' do
17
+ combinations.ids(20,0).should == []
18
+ end
19
+ end
20
+ context 'non-empty' do
21
+ let(:combination) { stub :combination, :identifier => :some_combination }
22
+ let(:combinations) { described_class.new [combination] }
23
+ let(:redis) { stub :redis }
24
+ before(:each) do
25
+ combinations.stub! :redis => redis
26
+
27
+ combinations.stub! :host => 'some.host'
28
+ combinations.stub! :pid => 12345
29
+ end
30
+ it 'calls the redis backend correctly' do
31
+ redis.should_receive(:zinterstore).once.ordered.with :"some.host:12345:picky:result", ["some_combination"]
32
+ redis.should_receive(:zrange).once.ordered.with :"some.host:12345:picky:result", 0, 20
33
+ redis.should_receive(:del).once.ordered.with :"some.host:12345:picky:result"
34
+
35
+ combinations.ids 20,0
36
+ end
16
37
  end
17
- it "returns an Allocation with specific result_identifier" do
18
- @combinations.pack_into_allocation(:some_result_identifier).result_identifier.should == :some_result_identifier
38
+ end
39
+
40
+ describe 'pid' do
41
+ it "returns the Process' pid" do
42
+ Process.stub! :pid => 12345
43
+
44
+ @combinations.pid.should == 12345
45
+ end
46
+ end
47
+
48
+ describe 'host' do
49
+ before(:each) do
50
+ @combinations.class.stub! :extract_host => 'some.host'
51
+ end
52
+ it 'returns the host' do
53
+ @combinations.host.should == 'some.host'
19
54
  end
20
55
  end
21
56
 
@@ -2,6 +2,28 @@ require 'spec_helper'
2
2
 
3
3
  describe Sources::Couch do
4
4
 
5
+ describe 'key_format' do
6
+ context 'default' do
7
+ let(:source) { Sources::Couch.new(:a, :b, url: 'bla') }
8
+ it 'is correct' do
9
+ source.key_format.should == :to_sym
10
+ end
11
+ end
12
+ context 'non-default' do
13
+ let(:source) { Sources::Couch.new(:a, :b, url: 'bla', key_format: 'some_key_method') }
14
+ it 'is correct' do
15
+ source.key_format.should == :some_key_method
16
+ end
17
+ end
18
+ end
19
+
20
+ describe 'to_s' do
21
+ let(:source) { Sources::Couch.new(:a, :b, :url => 'bla') }
22
+ it 'is correct' do
23
+ source.to_s.should == 'Sources::Couch'
24
+ end
25
+ end
26
+
5
27
  describe 'special keys' do
6
28
  context 'uuid keys' do
7
29
  context "with database" do
@@ -3,6 +3,13 @@ require 'csv'
3
3
 
4
4
  describe Sources::CSV do
5
5
 
6
+ describe 'to_s' do
7
+ let(:source) { described_class.new :a, :b, :c, file:'some/file.csv' }
8
+ it 'outputs the correct string' do
9
+ source.to_s.should == 'Sources::CSV(a, b, c, {:file=>"some/file.csv"})'
10
+ end
11
+ end
12
+
6
13
  describe 'without separator' do
7
14
  before(:each) do
8
15
  @source = Sources::CSV.new :a, :b, :c, :file => :some_file
@@ -8,7 +8,7 @@ describe Sources::DB do
8
8
  @connection = stub :connection
9
9
  @adapter = stub :adapter, :connection => @connection
10
10
 
11
- @select_statement = stub :statement
11
+ @select_statement = stub :statement, :inspect => '"some statement"'
12
12
 
13
13
  @source = described_class.new @select_statement, :option => :some_options
14
14
 
@@ -16,6 +16,12 @@ describe Sources::DB do
16
16
  @source.stub! :connect_backend
17
17
  end
18
18
 
19
+ describe 'to_s' do
20
+ it 'does something' do
21
+ @source.to_s.should == 'Sources::DB("some statement", {:option=>:some_options})'
22
+ end
23
+ end
24
+
19
25
  describe "get_data" do
20
26
  before(:each) do
21
27
  @type = stub :type, :name => :some_type
@@ -1,11 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
- # TODO Slow spec.
4
- #
5
3
  describe Sources::Delicious do
6
4
 
7
5
  context "with file" do
8
6
 
7
+ describe 'to_s' do
8
+ it 'outputs correctly' do
9
+ described_class.new(:username, :password).to_s.should == 'Sources::Delicious(username)'
10
+ end
11
+ end
12
+
9
13
  describe "check_gem" do
10
14
  before(:each) do
11
15
  @source = Sources::Delicious.allocate