picky 0.0.0 → 0.0.2
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.
- data/bin/picky +14 -0
- data/lib/bundling.rb +10 -0
- data/lib/constants.rb +9 -0
- data/lib/deployment.rb +212 -0
- data/lib/picky/application.rb +40 -0
- data/lib/picky/cacher/convenience.rb +3 -0
- data/lib/picky/cacher/generator.rb +17 -0
- data/lib/picky/cacher/partial/default.rb +7 -0
- data/lib/picky/cacher/partial/none.rb +19 -0
- data/lib/picky/cacher/partial/strategy.rb +7 -0
- data/lib/picky/cacher/partial/subtoken.rb +91 -0
- data/lib/picky/cacher/partial_generator.rb +15 -0
- data/lib/picky/cacher/similarity/default.rb +7 -0
- data/lib/picky/cacher/similarity/double_levenshtone.rb +73 -0
- data/lib/picky/cacher/similarity/none.rb +25 -0
- data/lib/picky/cacher/similarity/strategy.rb +7 -0
- data/lib/picky/cacher/similarity_generator.rb +15 -0
- data/lib/picky/cacher/weights/default.rb +7 -0
- data/lib/picky/cacher/weights/logarithmic.rb +39 -0
- data/lib/picky/cacher/weights/strategy.rb +7 -0
- data/lib/picky/cacher/weights_generator.rb +15 -0
- data/lib/picky/configuration/configuration.rb +13 -0
- data/lib/picky/configuration/field.rb +68 -0
- data/lib/picky/configuration/indexes.rb +60 -0
- data/lib/picky/configuration/queries.rb +32 -0
- data/lib/picky/configuration/type.rb +52 -0
- data/lib/picky/cores.rb +101 -0
- data/lib/picky/db/configuration.rb +23 -0
- data/lib/picky/ext/ruby19/extconf.rb +7 -0
- data/lib/picky/ext/ruby19/performant.c +339 -0
- data/lib/picky/extensions/array.rb +45 -0
- data/lib/picky/extensions/hash.rb +11 -0
- data/lib/picky/extensions/module.rb +15 -0
- data/lib/picky/extensions/symbol.rb +18 -0
- data/lib/picky/generator.rb +156 -0
- data/lib/picky/helpers/cache.rb +23 -0
- data/lib/picky/helpers/gc.rb +11 -0
- data/lib/picky/helpers/measuring.rb +45 -0
- data/lib/picky/helpers/search.rb +27 -0
- data/lib/picky/index/bundle.rb +328 -0
- data/lib/picky/index/category.rb +109 -0
- data/lib/picky/index/combined.rb +38 -0
- data/lib/picky/index/type.rb +30 -0
- data/lib/picky/indexers/base.rb +77 -0
- data/lib/picky/indexers/default.rb +3 -0
- data/lib/picky/indexers/field.rb +13 -0
- data/lib/picky/indexers/no_source_specified_error.rb +5 -0
- data/lib/picky/indexers/solr.rb +60 -0
- data/lib/picky/indexes.rb +180 -0
- data/lib/picky/initializers/ext.rb +6 -0
- data/lib/picky/initializers/mysql.rb +22 -0
- data/lib/picky/loader.rb +287 -0
- data/lib/picky/loggers/search.rb +19 -0
- data/lib/picky/performant/array.rb +23 -0
- data/lib/picky/query/allocation.rb +82 -0
- data/lib/picky/query/allocations.rb +131 -0
- data/lib/picky/query/base.rb +124 -0
- data/lib/picky/query/combination.rb +69 -0
- data/lib/picky/query/combinations.rb +106 -0
- data/lib/picky/query/combinator.rb +92 -0
- data/lib/picky/query/full.rb +15 -0
- data/lib/picky/query/live.rb +22 -0
- data/lib/picky/query/qualifiers.rb +73 -0
- data/lib/picky/query/solr.rb +77 -0
- data/lib/picky/query/token.rb +215 -0
- data/lib/picky/query/tokens.rb +102 -0
- data/lib/picky/query/weigher.rb +159 -0
- data/lib/picky/query/weights.rb +55 -0
- data/lib/picky/rack/harakiri.rb +37 -0
- data/lib/picky/results/base.rb +103 -0
- data/lib/picky/results/full.rb +19 -0
- data/lib/picky/results/live.rb +19 -0
- data/lib/picky/routing.rb +165 -0
- data/lib/picky/signals.rb +11 -0
- data/lib/picky/solr/schema_generator.rb +73 -0
- data/lib/picky/sources/base.rb +19 -0
- data/lib/picky/sources/csv.rb +30 -0
- data/lib/picky/sources/db.rb +77 -0
- data/lib/picky/tokenizers/base.rb +130 -0
- data/lib/picky/tokenizers/default.rb +3 -0
- data/lib/picky/tokenizers/index.rb +73 -0
- data/lib/picky/tokenizers/query.rb +70 -0
- data/lib/picky/umlaut_substituter.rb +21 -0
- data/lib/picky-tasks.rb +6 -0
- data/lib/picky.rb +18 -0
- data/lib/tasks/application.rake +5 -0
- data/lib/tasks/cache.rake +53 -0
- data/lib/tasks/framework.rake +4 -0
- data/lib/tasks/index.rake +29 -0
- data/lib/tasks/server.rake +48 -0
- data/lib/tasks/shortcuts.rake +13 -0
- data/lib/tasks/solr.rake +36 -0
- data/lib/tasks/spec.rake +11 -0
- data/lib/tasks/statistics.rake +13 -0
- data/lib/tasks/try.rake +29 -0
- data/prototype_project/Gemfile +23 -0
- data/prototype_project/Rakefile +1 -0
- data/prototype_project/app/README +6 -0
- data/prototype_project/app/application.rb +50 -0
- data/prototype_project/app/application.ru +29 -0
- data/prototype_project/app/db.yml +10 -0
- data/prototype_project/app/logging.rb +20 -0
- data/prototype_project/app/unicorn.ru +10 -0
- data/prototype_project/log/README +1 -0
- data/prototype_project/script/console +34 -0
- data/prototype_project/tmp/README +0 -0
- data/prototype_project/tmp/pids/README +0 -0
- data/spec/ext/performant_spec.rb +64 -0
- data/spec/lib/application_spec.rb +61 -0
- data/spec/lib/cacher/partial/subtoken_spec.rb +89 -0
- data/spec/lib/cacher/partial_generator_spec.rb +35 -0
- data/spec/lib/cacher/similarity/double_levenshtone_spec.rb +60 -0
- data/spec/lib/cacher/similarity/none_spec.rb +23 -0
- data/spec/lib/cacher/similarity_generator_spec.rb +22 -0
- data/spec/lib/cacher/weights/logarithmic_spec.rb +30 -0
- data/spec/lib/cacher/weights_generator_spec.rb +21 -0
- data/spec/lib/configuration/configuration_spec.rb +38 -0
- data/spec/lib/configuration/type_spec.rb +49 -0
- data/spec/lib/configuration_spec.rb +8 -0
- data/spec/lib/cores_spec.rb +65 -0
- data/spec/lib/extensions/array_spec.rb +37 -0
- data/spec/lib/extensions/hash_spec.rb +11 -0
- data/spec/lib/extensions/module_spec.rb +27 -0
- data/spec/lib/extensions/symbol_spec.rb +85 -0
- data/spec/lib/generator_spec.rb +135 -0
- data/spec/lib/helpers/cache_spec.rb +35 -0
- data/spec/lib/helpers/gc_spec.rb +71 -0
- data/spec/lib/helpers/measuring_spec.rb +18 -0
- data/spec/lib/helpers/search_spec.rb +50 -0
- data/spec/lib/index/bundle_partial_generation_speed_spec.rb +47 -0
- data/spec/lib/index/bundle_spec.rb +260 -0
- data/spec/lib/index/category_spec.rb +203 -0
- data/spec/lib/indexers/base_spec.rb +73 -0
- data/spec/lib/indexers/field_spec.rb +20 -0
- data/spec/lib/loader_spec.rb +48 -0
- data/spec/lib/loggers/search_spec.rb +19 -0
- data/spec/lib/performant/array_spec.rb +13 -0
- data/spec/lib/query/allocation_spec.rb +194 -0
- data/spec/lib/query/allocations_spec.rb +336 -0
- data/spec/lib/query/base_spec.rb +104 -0
- data/spec/lib/query/combination_spec.rb +90 -0
- data/spec/lib/query/combinations_spec.rb +83 -0
- data/spec/lib/query/combinator_spec.rb +112 -0
- data/spec/lib/query/full_spec.rb +22 -0
- data/spec/lib/query/live_spec.rb +61 -0
- data/spec/lib/query/qualifiers_spec.rb +31 -0
- data/spec/lib/query/solr_spec.rb +51 -0
- data/spec/lib/query/token_spec.rb +297 -0
- data/spec/lib/query/tokens_spec.rb +189 -0
- data/spec/lib/query/weights_spec.rb +47 -0
- data/spec/lib/results/base_spec.rb +233 -0
- data/spec/lib/routing_spec.rb +318 -0
- data/spec/lib/solr/schema_generator_spec.rb +42 -0
- data/spec/lib/sources/db_spec.rb +91 -0
- data/spec/lib/tokenizers/base_spec.rb +61 -0
- data/spec/lib/tokenizers/index_spec.rb +51 -0
- data/spec/lib/tokenizers/query_spec.rb +105 -0
- data/spec/lib/umlaut_substituter_spec.rb +84 -0
- data/spec/specific/speed_spec.rb +55 -0
- metadata +371 -15
- data/README.textile +0 -9
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Cacher::Weights::Logarithmic do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
@cacher = Cacher::Weights::Logarithmic.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe 'generate_from' do
|
|
10
|
+
it 'should not fail on empties' do
|
|
11
|
+
@cacher.generate_from({ :key => [] }).should == { :key => 0 }
|
|
12
|
+
end
|
|
13
|
+
it 'should round to 2' do
|
|
14
|
+
@cacher.generate_from({ :key => [1,2,3,4] }).should == { :key => 1.39 }
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe 'weight_for' do
|
|
19
|
+
it 'should be 0 for 0' do
|
|
20
|
+
@cacher.weight_for(0).should == 0
|
|
21
|
+
end
|
|
22
|
+
it 'should be 0 for 1' do
|
|
23
|
+
@cacher.weight_for(1).should == 0
|
|
24
|
+
end
|
|
25
|
+
it 'should be log(x) for x' do
|
|
26
|
+
@cacher.weight_for(1234).should == Math.log(1234)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Cacher::WeightsGenerator do
|
|
4
|
+
|
|
5
|
+
context 'integration' do
|
|
6
|
+
it 'should generate the correct values' do
|
|
7
|
+
generator = Cacher::WeightsGenerator.new :a => Array.new(0),
|
|
8
|
+
:b => Array.new(1),
|
|
9
|
+
:c => Array.new(10),
|
|
10
|
+
:d => Array.new(100),
|
|
11
|
+
:e => Array.new(1000)
|
|
12
|
+
|
|
13
|
+
result = generator.generate
|
|
14
|
+
|
|
15
|
+
result[:c].should be_close 2.3, 0.011
|
|
16
|
+
result[:d].should be_close 4.6, 0.011
|
|
17
|
+
result[:e].should be_close 6.9, 0.011
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe Configuration do
|
|
5
|
+
|
|
6
|
+
# describe 'field' do
|
|
7
|
+
# it 'should define a new type' do
|
|
8
|
+
# Configuration::Field.should_receive(:new).once.with :some_name, :some_options
|
|
9
|
+
#
|
|
10
|
+
# Configuration.field :some_name, :some_options
|
|
11
|
+
# end
|
|
12
|
+
# it 'should respect the default' do
|
|
13
|
+
# Configuration::Field.should_receive(:new).once.with :some_name, {}
|
|
14
|
+
#
|
|
15
|
+
# Configuration.field :some_name
|
|
16
|
+
# end
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
# describe 'type' do
|
|
20
|
+
# it 'should define a new type' do
|
|
21
|
+
# Configuration::Type.should_receive(:new).once.with :some_name, :some_field, :some_other_field
|
|
22
|
+
#
|
|
23
|
+
# Configuration.type :some_name, :some_field, :some_other_field
|
|
24
|
+
# end
|
|
25
|
+
# end
|
|
26
|
+
#
|
|
27
|
+
# describe 'indexes' do
|
|
28
|
+
# it 'should define the indexes and save' do
|
|
29
|
+
# indexes = mock :indexes
|
|
30
|
+
#
|
|
31
|
+
# Configuration::Indexes.should_receive(:new).once.with(:some_types).and_return indexes
|
|
32
|
+
# indexes.should_receive(:save).once.with
|
|
33
|
+
#
|
|
34
|
+
# Configuration.indexes :some_types
|
|
35
|
+
# end
|
|
36
|
+
# end
|
|
37
|
+
|
|
38
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe Configuration::Type do
|
|
5
|
+
|
|
6
|
+
before(:each) do
|
|
7
|
+
@field = stub :field, :type= => nil, :virtual? => false
|
|
8
|
+
@field.stub! :dup => @field
|
|
9
|
+
|
|
10
|
+
@virtual_field = stub :virtual_field, :type= => nil, :virtual? => true
|
|
11
|
+
@virtual_field.stub! :dup => @virtual_field
|
|
12
|
+
@type = Configuration::Type.new :some_name,
|
|
13
|
+
:some_indexing_select,
|
|
14
|
+
@field,
|
|
15
|
+
@virtual_field,
|
|
16
|
+
:after_indexing => "some after indexing",
|
|
17
|
+
:result_type => :some_result_type,
|
|
18
|
+
:weights => :some_weights,
|
|
19
|
+
:ignore_unassigned_tokens => :some_ignore_unassigned_tokens_option,
|
|
20
|
+
:solr => :some_solr_option
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe 'solr_fields' do
|
|
24
|
+
it 'should return all non-virtual fields' do
|
|
25
|
+
@type.solr_fields.should == [@field]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe 'index_solr' do
|
|
30
|
+
it 'should get a new solr indexer and start it' do
|
|
31
|
+
solr = mock :solr
|
|
32
|
+
Indexers::Solr.should_receive(:new).once.with(@type).and_return solr
|
|
33
|
+
|
|
34
|
+
solr.should_receive(:index).once.with
|
|
35
|
+
|
|
36
|
+
@type.index_solr
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe 'index' do
|
|
41
|
+
it 'should index each of the fields' do
|
|
42
|
+
@field.should_receive(:index).once.with
|
|
43
|
+
@virtual_field.should_receive(:index).once.with
|
|
44
|
+
|
|
45
|
+
@type.index
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe Cores do
|
|
5
|
+
|
|
6
|
+
describe 'number_of_cores' do
|
|
7
|
+
before(:each) do
|
|
8
|
+
@linux = mock :linux, :null_object => true
|
|
9
|
+
@darwin = mock :darwin, :null_object => true
|
|
10
|
+
Cores.stub! :os_to_core_mapping => {
|
|
11
|
+
'linux' => @linux,
|
|
12
|
+
'darwin' => @darwin
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
context 'default' do
|
|
16
|
+
before(:each) do
|
|
17
|
+
Cores.stub! :platform => 'mswin'
|
|
18
|
+
end
|
|
19
|
+
it 'should return 1' do
|
|
20
|
+
Cores.number_of_cores.should == 1
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
context 'osx' do
|
|
24
|
+
before(:each) do
|
|
25
|
+
Cores.stub! :platform => 'i386-darwin9.8.0'
|
|
26
|
+
end
|
|
27
|
+
it 'should return whatever darwin returns' do
|
|
28
|
+
@darwin.stub! :call => '1234'
|
|
29
|
+
|
|
30
|
+
Cores.number_of_cores.should == 1234
|
|
31
|
+
end
|
|
32
|
+
it 'should call darwin' do
|
|
33
|
+
@darwin.should_receive(:call).once
|
|
34
|
+
|
|
35
|
+
Cores.number_of_cores
|
|
36
|
+
end
|
|
37
|
+
it 'should not call linux' do
|
|
38
|
+
@linux.should_receive(:call).never
|
|
39
|
+
|
|
40
|
+
Cores.number_of_cores
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
context 'linux' do
|
|
44
|
+
before(:each) do
|
|
45
|
+
Cores.stub! :platform => 'x86_64-linux'
|
|
46
|
+
end
|
|
47
|
+
it 'should return whatever linux returns' do
|
|
48
|
+
@linux.stub! :call => '1234'
|
|
49
|
+
|
|
50
|
+
Cores.number_of_cores.should == 1234
|
|
51
|
+
end
|
|
52
|
+
it 'should call linux' do
|
|
53
|
+
@linux.should_receive(:call).once
|
|
54
|
+
|
|
55
|
+
Cores.number_of_cores
|
|
56
|
+
end
|
|
57
|
+
it 'should not call darwin' do
|
|
58
|
+
@darwin.should_receive(:call).never
|
|
59
|
+
|
|
60
|
+
Cores.number_of_cores
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Array do
|
|
4
|
+
|
|
5
|
+
describe 'sort_by_levenshtein!' do
|
|
6
|
+
it 'should sort right' do
|
|
7
|
+
['fish', 'flash', 'flush', 'smooch'].sort_by_levenshtein!(:fush).should == ['fish', 'flush', 'flash', 'smooch']
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe 'random' do
|
|
12
|
+
it 'should choose one element from the array' do
|
|
13
|
+
left = [1,2,3]
|
|
14
|
+
100.times do
|
|
15
|
+
left.delete [1,2,3].random
|
|
16
|
+
end
|
|
17
|
+
left.should be_empty
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "clustered_uniq" do
|
|
22
|
+
it "should generate a new array" do
|
|
23
|
+
ary = [:test1, :test2, :test1]
|
|
24
|
+
ary.clustered_uniq.object_id.should_not == ary.object_id
|
|
25
|
+
end
|
|
26
|
+
it "should not change clusteredly unique arrays" do
|
|
27
|
+
[:test1, :test2, :test1].clustered_uniq.should == [:test1, :test2, :test1]
|
|
28
|
+
end
|
|
29
|
+
it "should not skip interspersed elements" do
|
|
30
|
+
[:test1, :test1, :test2, :test1].clustered_uniq.should == [:test1, :test2, :test1]
|
|
31
|
+
end
|
|
32
|
+
it "should work like uniq if no interspersed elements exist" do
|
|
33
|
+
[:test1, :test1, :test2, :test2, :test3].clustered_uniq.should == [:test1, :test2, :test3]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Module do
|
|
4
|
+
|
|
5
|
+
describe 'each_delegate' do
|
|
6
|
+
before(:each) do
|
|
7
|
+
@klass = Class.new do
|
|
8
|
+
|
|
9
|
+
each_delegate :bli, :bla, :blu, :to => :@some_enumerable
|
|
10
|
+
|
|
11
|
+
def initialize some_enumerable
|
|
12
|
+
@some_enumerable = some_enumerable
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
it 'should send each a bli' do
|
|
18
|
+
bli = stub :bli
|
|
19
|
+
delegating = @klass.new [bli, bli, bli, bli]
|
|
20
|
+
|
|
21
|
+
bli.should_receive(:bli).exactly(4).times
|
|
22
|
+
|
|
23
|
+
delegating.bli
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Symbol do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
GC.disable
|
|
7
|
+
end
|
|
8
|
+
after(:each) do
|
|
9
|
+
GC.enable
|
|
10
|
+
GC.start
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
context 'performance' do
|
|
14
|
+
include Helpers::Measuring
|
|
15
|
+
it 'should be fast' do
|
|
16
|
+
s = (((0..9).to_a)*10).to_s.to_sym
|
|
17
|
+
|
|
18
|
+
timed do
|
|
19
|
+
s.subtokens
|
|
20
|
+
end.should <= 0.003 # was 0.0019
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe "subtokens" do
|
|
25
|
+
context 'normal symbol' do
|
|
26
|
+
before(:each) do
|
|
27
|
+
@sym = :reinke
|
|
28
|
+
end
|
|
29
|
+
context 'no downto' do
|
|
30
|
+
it "should return an array of pieces of the original token, each 1 smaller than the other" do
|
|
31
|
+
@sym.subtokens.should == [:reinke, :reink, :rein, :rei, :re, :r]
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
context 'downto is larger than the symbol' do
|
|
35
|
+
before(:each) do
|
|
36
|
+
@downto = 8
|
|
37
|
+
end
|
|
38
|
+
it "should return an array of pieces of the original token, each 1 smaller than the other" do
|
|
39
|
+
@sym.subtokens(@downto).should == [:reinke]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
context 'downto is exactly the same as symbol' do
|
|
43
|
+
before(:each) do
|
|
44
|
+
@downto = 6
|
|
45
|
+
end
|
|
46
|
+
it "should return an array of pieces of the original token, each 1 smaller than the other" do
|
|
47
|
+
@sym.subtokens(@downto).should == [:reinke]
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
context 'downto is smaller than the length of the symbol' do
|
|
51
|
+
before(:each) do
|
|
52
|
+
@downto = 4
|
|
53
|
+
end
|
|
54
|
+
it "should return an array of pieces of the original token, each 1 smaller than the other" do
|
|
55
|
+
@sym.subtokens(@downto).should == [:reinke, :reink, :rein]
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
context 'downto is 1' do
|
|
59
|
+
before(:each) do
|
|
60
|
+
@downto = 1
|
|
61
|
+
end
|
|
62
|
+
it "should return an array of pieces of the original token, each 1 smaller than the other" do
|
|
63
|
+
@sym.subtokens(@downto).should == [:reinke, :reink, :rein, :rei, :re, :r]
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
# context 'downto is 0' do
|
|
67
|
+
# before(:each) do
|
|
68
|
+
# @downto = 0
|
|
69
|
+
# end
|
|
70
|
+
# it "should return an array of pieces of the original token, each 1 smaller than the other" do
|
|
71
|
+
# @sym.subtokens(@downto).should == [:reinke, :reink, :rein, :rei, :re, :r]
|
|
72
|
+
# end
|
|
73
|
+
# end
|
|
74
|
+
# context 'downto is less than zero' do
|
|
75
|
+
# before(:each) do
|
|
76
|
+
# @downto = -2
|
|
77
|
+
# end
|
|
78
|
+
# it "should return an array of pieces of the original token, each 1 smaller than the other" do
|
|
79
|
+
# @sym.subtokens(@downto).should == [:reinke, :reink, :rein, :rei, :re, :r]
|
|
80
|
+
# end
|
|
81
|
+
# end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe Picky::Generator do
|
|
5
|
+
|
|
6
|
+
describe "main class" do
|
|
7
|
+
before(:each) do
|
|
8
|
+
@generator = Picky::Generator.new
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "generator_for_class" do
|
|
12
|
+
it "should return me a generator for the given class" do
|
|
13
|
+
@generator.generator_for_class(Picky::Generator::Project, :some_args).should be_kind_of(Picky::Generator::Project)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe "generator_for" do
|
|
18
|
+
it "should not raise if a generator is available" do
|
|
19
|
+
lambda { @generator.generator_for('project', 'some_project') }.should_not raise_error
|
|
20
|
+
end
|
|
21
|
+
it "should raise if a generator is not available" do
|
|
22
|
+
lambda { @generator.generator_for('blarf', 'gnorf') }.should raise_error(Picky::NoGeneratorException)
|
|
23
|
+
end
|
|
24
|
+
it "should return a generator if it is available" do
|
|
25
|
+
@generator.generator_for('project', 'some_project').should be_kind_of(Picky::Generator::Project)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe "generate" do
|
|
30
|
+
it "should raise a NoGeneratorException if called with the wrong params" do
|
|
31
|
+
lambda { @generator.generate(['blarf', 'gnorf']) }.should raise_error(Picky::NoGeneratorException)
|
|
32
|
+
end
|
|
33
|
+
it "should not raise on the right params" do
|
|
34
|
+
@generator.stub! :generator_for_class => stub(:generator, :generate => nil)
|
|
35
|
+
|
|
36
|
+
lambda { @generator.generate(['project', 'some_project']) }.should_not raise_error
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe Picky::Generator::Project do
|
|
42
|
+
|
|
43
|
+
before(:each) do
|
|
44
|
+
@generator = Picky::Generator::Project.new 'some_name', []
|
|
45
|
+
@generator.stub! :exclaim
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
context "after initialize" do
|
|
49
|
+
it "should have a prototype project basedir" do
|
|
50
|
+
lambda {
|
|
51
|
+
@generator.prototype_project_basedir
|
|
52
|
+
}.should_not raise_error
|
|
53
|
+
end
|
|
54
|
+
it "should have a name" do
|
|
55
|
+
@generator.name.should == 'some_name'
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe "generate" do
|
|
60
|
+
it "should do things in order" do
|
|
61
|
+
@generator.should_receive(:create_target_directory).once.ordered
|
|
62
|
+
@generator.should_receive(:copy_all_files).once.ordered
|
|
63
|
+
|
|
64
|
+
@generator.generate
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe "create_target_directory" do
|
|
69
|
+
context "file exists" do
|
|
70
|
+
before(:each) do
|
|
71
|
+
File.stub! :exists? => true
|
|
72
|
+
end
|
|
73
|
+
it "should just tell the user that" do
|
|
74
|
+
@generator.stub! :target_directory => :some_target_directory
|
|
75
|
+
|
|
76
|
+
@generator.should_receive(:exists).once.with :some_target_directory
|
|
77
|
+
|
|
78
|
+
@generator.create_target_directory
|
|
79
|
+
end
|
|
80
|
+
it "should not make the directory" do
|
|
81
|
+
FileUtils.should_receive(:mkdir).never
|
|
82
|
+
|
|
83
|
+
@generator.create_target_directory
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
context "file does not exist" do
|
|
87
|
+
before(:each) do
|
|
88
|
+
File.stub! :exists? => false
|
|
89
|
+
FileUtils.stub! :mkdir
|
|
90
|
+
end
|
|
91
|
+
it "should make the directory" do
|
|
92
|
+
@generator.stub! :target_directory => :some_target_directory
|
|
93
|
+
|
|
94
|
+
FileUtils.should_receive(:mkdir).once.with :some_target_directory
|
|
95
|
+
|
|
96
|
+
@generator.create_target_directory
|
|
97
|
+
end
|
|
98
|
+
it "should tell the user" do
|
|
99
|
+
@generator.stub! :target_directory => :some_target_directory
|
|
100
|
+
|
|
101
|
+
@generator.should_receive(:created).once.with :some_target_directory
|
|
102
|
+
|
|
103
|
+
@generator.create_target_directory
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
describe "target_filename_for" do
|
|
109
|
+
it "should return the right filename" do
|
|
110
|
+
@generator.stub! :target_directory => 'some_target_directory'
|
|
111
|
+
|
|
112
|
+
test_filename = File.expand_path File.join(@generator.prototype_project_basedir, '/some/file/name')
|
|
113
|
+
|
|
114
|
+
@generator.target_filename_for(test_filename).should == 'some_target_directory/some/file/name'
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
describe "generate" do
|
|
119
|
+
it "should copy recursively" do
|
|
120
|
+
@generator.should_receive(:create_target_directory).once.with
|
|
121
|
+
@generator.should_receive(:copy_all_files).once.with
|
|
122
|
+
|
|
123
|
+
@generator.generate
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
describe "target_directory" do
|
|
128
|
+
it "should return the right dir name" do
|
|
129
|
+
@generator.target_directory.should == File.expand_path(File.join(__FILE__, '..', '..', '..', 'some_name'))
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Helpers::Cache do
|
|
4
|
+
include Helpers::Cache
|
|
5
|
+
|
|
6
|
+
describe "#cached" do
|
|
7
|
+
attr_reader :store, :key
|
|
8
|
+
before(:each) do
|
|
9
|
+
@store = {}
|
|
10
|
+
@key = 'some key'
|
|
11
|
+
end
|
|
12
|
+
describe "not yet cached" do
|
|
13
|
+
it "should cache" do
|
|
14
|
+
store.should_receive(:[]=).once.with(@key, 'value')
|
|
15
|
+
cached @store, @key do
|
|
16
|
+
'value'
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
describe "already cached" do
|
|
21
|
+
before(:each) do
|
|
22
|
+
cached @store, @key do
|
|
23
|
+
'value'
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
it "should not cache" do
|
|
27
|
+
store.should_receive(:[]=).never
|
|
28
|
+
cached @store, @key do
|
|
29
|
+
'value'
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Helpers::GC do
|
|
4
|
+
include Helpers::GC
|
|
5
|
+
|
|
6
|
+
before(:each) do
|
|
7
|
+
::GC.stub!(:disable)
|
|
8
|
+
::GC.stub!(:enable)
|
|
9
|
+
::GC.stub!(:start)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "block calling" do
|
|
13
|
+
it 'should call the block' do
|
|
14
|
+
inside_block = mock :inside
|
|
15
|
+
inside_block.should_receive(:call).once
|
|
16
|
+
|
|
17
|
+
disabled do
|
|
18
|
+
inside_block.call
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
it 'should call the block' do
|
|
22
|
+
inside_block = mock :inside
|
|
23
|
+
inside_block.should_receive(:call).once
|
|
24
|
+
|
|
25
|
+
gc_disabled do
|
|
26
|
+
inside_block.call
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe "gc calls" do
|
|
32
|
+
after(:each) do
|
|
33
|
+
disabled {}
|
|
34
|
+
end
|
|
35
|
+
it 'should disable the garbage collector' do
|
|
36
|
+
::GC.should_receive(:disable)
|
|
37
|
+
end
|
|
38
|
+
it 'should enable the garbage collector' do
|
|
39
|
+
::GC.should_receive(:enable)
|
|
40
|
+
end
|
|
41
|
+
it 'should start the garbage collector' do
|
|
42
|
+
::GC.should_receive(:start)
|
|
43
|
+
end
|
|
44
|
+
it 'should disable the gc, call the block, enable the gc and start the gc' do
|
|
45
|
+
::GC.should_receive(:disable).ordered
|
|
46
|
+
::GC.should_receive(:enable).ordered
|
|
47
|
+
::GC.should_receive(:start).ordered
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "gc calls" do
|
|
52
|
+
after(:each) do
|
|
53
|
+
gc_disabled {}
|
|
54
|
+
end
|
|
55
|
+
it 'should disable the garbage collector' do
|
|
56
|
+
::GC.should_receive(:disable)
|
|
57
|
+
end
|
|
58
|
+
it 'should enable the garbage collector' do
|
|
59
|
+
::GC.should_receive(:enable)
|
|
60
|
+
end
|
|
61
|
+
it 'should start the garbage collector' do
|
|
62
|
+
::GC.should_receive(:start)
|
|
63
|
+
end
|
|
64
|
+
it 'should disable the gc, call the block, enable the gc and start the gc' do
|
|
65
|
+
::GC.should_receive(:disable).ordered
|
|
66
|
+
::GC.should_receive(:enable).ordered
|
|
67
|
+
::GC.should_receive(:start).ordered
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Helpers::Measuring do
|
|
4
|
+
include Helpers::Measuring
|
|
5
|
+
|
|
6
|
+
describe "#timed" do
|
|
7
|
+
it "should return some duration" do
|
|
8
|
+
timed { 1 + 3 }.should_not be_nil
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "#log_performance" do
|
|
13
|
+
it "should log" do
|
|
14
|
+
log_performance('hello') { 10000*10000 }
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'Helpers::Search' do
|
|
4
|
+
include Helpers::Search
|
|
5
|
+
|
|
6
|
+
def self.it_should_return_class_for(klass, x)
|
|
7
|
+
it "should return class #{klass} for #{x} items" do
|
|
8
|
+
status_class_for(x).should == klass
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "search_status_class_for" do
|
|
13
|
+
it_should_return_class_for :none, 0
|
|
14
|
+
it_should_return_class_for :one, 1
|
|
15
|
+
it_should_return_class_for :few, 2
|
|
16
|
+
it_should_return_class_for :few, 3
|
|
17
|
+
it_should_return_class_for :few, 4
|
|
18
|
+
it_should_return_class_for :few, 5
|
|
19
|
+
it_should_return_class_for :few, 6
|
|
20
|
+
it_should_return_class_for :few, 7
|
|
21
|
+
it_should_return_class_for :some, 8
|
|
22
|
+
it_should_return_class_for :some, 9
|
|
23
|
+
it_should_return_class_for :some, 10
|
|
24
|
+
it_should_return_class_for :some, 11
|
|
25
|
+
it_should_return_class_for :some, 12
|
|
26
|
+
it_should_return_class_for :some, 13
|
|
27
|
+
it_should_return_class_for :some, 14
|
|
28
|
+
it_should_return_class_for :some, 15
|
|
29
|
+
it_should_return_class_for :several, 16
|
|
30
|
+
it_should_return_class_for :several, 17
|
|
31
|
+
it_should_return_class_for :several, 18
|
|
32
|
+
it_should_return_class_for :several, 19
|
|
33
|
+
it_should_return_class_for :several, 20
|
|
34
|
+
it_should_return_class_for :several, 21
|
|
35
|
+
it_should_return_class_for :several, 22
|
|
36
|
+
it_should_return_class_for :several, 23
|
|
37
|
+
it_should_return_class_for :several, 24
|
|
38
|
+
it_should_return_class_for :several, 25
|
|
39
|
+
it_should_return_class_for :many, 26
|
|
40
|
+
it_should_return_class_for :many, 27
|
|
41
|
+
it_should_return_class_for :many, 28
|
|
42
|
+
it_should_return_class_for :many, 29
|
|
43
|
+
# etc.
|
|
44
|
+
it_should_return_class_for :lots, 51
|
|
45
|
+
# etc.
|
|
46
|
+
it_should_return_class_for :too_many, 101
|
|
47
|
+
# etc.
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|