thinking-sphinx 3.2.0 → 3.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.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -2
  3. data/Appraisals +13 -0
  4. data/Gemfile +2 -1
  5. data/HISTORY +19 -0
  6. data/README.textile +3 -2
  7. data/gemfiles/rails_3_2.gemfile +2 -1
  8. data/gemfiles/rails_4_0.gemfile +2 -1
  9. data/gemfiles/rails_4_1.gemfile +2 -1
  10. data/gemfiles/rails_4_2.gemfile +2 -1
  11. data/gemfiles/rails_5_0.gemfile +12 -0
  12. data/lib/thinking_sphinx.rb +2 -0
  13. data/lib/thinking_sphinx/active_record/attribute/type.rb +17 -3
  14. data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +12 -4
  15. data/lib/thinking_sphinx/active_record/database_adapters.rb +1 -1
  16. data/lib/thinking_sphinx/active_record/sql_builder/query.rb +4 -0
  17. data/lib/thinking_sphinx/active_record/sql_source.rb +1 -1
  18. data/lib/thinking_sphinx/configuration.rb +3 -2
  19. data/lib/thinking_sphinx/connection.rb +23 -10
  20. data/lib/thinking_sphinx/deltas/index_job.rb +6 -2
  21. data/lib/thinking_sphinx/errors.rb +25 -0
  22. data/lib/thinking_sphinx/middlewares/active_record_translator.rb +14 -2
  23. data/lib/thinking_sphinx/railtie.rb +1 -1
  24. data/lib/thinking_sphinx/rake_interface.rb +71 -23
  25. data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +15 -7
  26. data/lib/thinking_sphinx/real_time/populator.rb +3 -3
  27. data/lib/thinking_sphinx/tasks.rb +7 -8
  28. data/lib/thinking_sphinx/wildcard.rb +1 -1
  29. data/spec/acceptance/association_scoping_spec.rb +5 -5
  30. data/spec/acceptance/attribute_access_spec.rb +4 -4
  31. data/spec/acceptance/attribute_updates_spec.rb +3 -3
  32. data/spec/acceptance/batch_searching_spec.rb +4 -4
  33. data/spec/acceptance/big_integers_spec.rb +6 -6
  34. data/spec/acceptance/connection_spec.rb +23 -0
  35. data/spec/acceptance/excerpts_spec.rb +8 -8
  36. data/spec/acceptance/facets_spec.rb +13 -13
  37. data/spec/acceptance/geosearching_spec.rb +8 -8
  38. data/spec/acceptance/grouping_by_attributes_spec.rb +10 -10
  39. data/spec/acceptance/index_options_spec.rb +16 -16
  40. data/spec/acceptance/indexing_spec.rb +3 -3
  41. data/spec/acceptance/paginating_search_results_spec.rb +3 -3
  42. data/spec/acceptance/real_time_updates_spec.rb +4 -4
  43. data/spec/acceptance/remove_deleted_records_spec.rb +12 -12
  44. data/spec/acceptance/search_counts_spec.rb +2 -2
  45. data/spec/acceptance/search_for_just_ids_spec.rb +2 -2
  46. data/spec/acceptance/searching_across_models_spec.rb +6 -6
  47. data/spec/acceptance/searching_across_schemas_spec.rb +10 -10
  48. data/spec/acceptance/searching_on_fields_spec.rb +9 -9
  49. data/spec/acceptance/searching_with_filters_spec.rb +16 -16
  50. data/spec/acceptance/searching_with_sti_spec.rb +9 -9
  51. data/spec/acceptance/searching_within_a_model_spec.rb +17 -17
  52. data/spec/acceptance/sorting_search_results_spec.rb +6 -6
  53. data/spec/acceptance/specifying_sql_spec.rb +62 -62
  54. data/spec/acceptance/sphinx_scopes_spec.rb +9 -9
  55. data/spec/acceptance/sql_deltas_spec.rb +7 -7
  56. data/spec/acceptance/support/database_cleaner.rb +1 -1
  57. data/spec/acceptance/support/sphinx_controller.rb +4 -1
  58. data/spec/acceptance/support/sphinx_helpers.rb +4 -0
  59. data/spec/acceptance/suspended_deltas_spec.rb +9 -9
  60. data/spec/internal/app/indices/article_index.rb +2 -2
  61. data/spec/internal/app/indices/book_index.rb +2 -1
  62. data/spec/internal/app/indices/product_index.rb +0 -2
  63. data/spec/internal/app/models/categorisation.rb +8 -1
  64. data/spec/spec_helper.rb +2 -0
  65. data/spec/support/json_column.rb +5 -1
  66. data/spec/support/multi_schema.rb +3 -1
  67. data/spec/support/sphinx_yaml_helpers.rb +1 -1
  68. data/spec/thinking_sphinx/active_record/association_spec.rb +1 -1
  69. data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +41 -38
  70. data/spec/thinking_sphinx/active_record/base_spec.rb +29 -29
  71. data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +10 -10
  72. data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +48 -25
  73. data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +8 -8
  74. data/spec/thinking_sphinx/active_record/column_spec.rb +13 -13
  75. data/spec/thinking_sphinx/active_record/column_sql_presenter_spec.rb +5 -5
  76. data/spec/thinking_sphinx/active_record/database_adapters/abstract_adapter_spec.rb +5 -5
  77. data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +11 -11
  78. data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +13 -13
  79. data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +48 -48
  80. data/spec/thinking_sphinx/active_record/field_spec.rb +7 -7
  81. data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +32 -32
  82. data/spec/thinking_sphinx/active_record/index_spec.rb +35 -36
  83. data/spec/thinking_sphinx/active_record/interpreter_spec.rb +51 -51
  84. data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +14 -14
  85. data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +67 -67
  86. data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +140 -140
  87. data/spec/thinking_sphinx/active_record/sql_source_spec.rb +97 -95
  88. data/spec/thinking_sphinx/configuration_spec.rb +81 -81
  89. data/spec/thinking_sphinx/connection_spec.rb +13 -13
  90. data/spec/thinking_sphinx/deletion_spec.rb +11 -11
  91. data/spec/thinking_sphinx/deltas/default_delta_spec.rb +20 -20
  92. data/spec/thinking_sphinx/deltas_spec.rb +12 -12
  93. data/spec/thinking_sphinx/errors_spec.rb +30 -30
  94. data/spec/thinking_sphinx/excerpter_spec.rb +7 -7
  95. data/spec/thinking_sphinx/facet_search_spec.rb +16 -16
  96. data/spec/thinking_sphinx/index_set_spec.rb +7 -7
  97. data/spec/thinking_sphinx/index_spec.rb +24 -24
  98. data/spec/thinking_sphinx/masks/pagination_mask_spec.rb +20 -20
  99. data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +18 -18
  100. data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +22 -22
  101. data/spec/thinking_sphinx/middlewares/geographer_spec.rb +9 -9
  102. data/spec/thinking_sphinx/middlewares/glazier_spec.rb +4 -4
  103. data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +7 -7
  104. data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +53 -53
  105. data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +5 -5
  106. data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +15 -15
  107. data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +1 -1
  108. data/spec/thinking_sphinx/panes/distance_pane_spec.rb +4 -4
  109. data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +5 -5
  110. data/spec/thinking_sphinx/panes/weight_pane_spec.rb +1 -1
  111. data/spec/thinking_sphinx/rake_interface_spec.rb +66 -53
  112. data/spec/thinking_sphinx/real_time/attribute_spec.rb +13 -13
  113. data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +107 -23
  114. data/spec/thinking_sphinx/real_time/field_spec.rb +14 -14
  115. data/spec/thinking_sphinx/real_time/index_spec.rb +29 -30
  116. data/spec/thinking_sphinx/real_time/interpreter_spec.rb +30 -30
  117. data/spec/thinking_sphinx/scopes_spec.rb +5 -5
  118. data/spec/thinking_sphinx/search/glaze_spec.rb +15 -15
  119. data/spec/thinking_sphinx/search/query_spec.rb +10 -10
  120. data/spec/thinking_sphinx/search_spec.rb +28 -28
  121. data/spec/thinking_sphinx/wildcard_spec.rb +16 -11
  122. data/spec/thinking_sphinx_spec.rb +6 -6
  123. data/thinking-sphinx.gemspec +4 -4
  124. metadata +12 -9
@@ -25,7 +25,7 @@ describe ThinkingSphinx::Middlewares::StaleIdChecker do
25
25
  context[:results] << double('instance', :id => 24)
26
26
  context[:results] << double('instance', :id => 42)
27
27
 
28
- app.should_receive(:call)
28
+ expect(app).to receive(:call)
29
29
 
30
30
  middleware.call [context]
31
31
  end
@@ -37,11 +37,11 @@ describe ThinkingSphinx::Middlewares::StaleIdChecker do
37
37
  context[:results] << double('instance', :id => 24)
38
38
  context[:results] << nil
39
39
 
40
- lambda {
40
+ expect {
41
41
  middleware.call [context]
42
- }.should raise_error(ThinkingSphinx::Search::StaleIdsException) { |err|
43
- err.ids.should == [42]
44
- err.context.should == context
42
+ }.to raise_error(ThinkingSphinx::Search::StaleIdsException) { |err|
43
+ expect(err.ids).to eq([42])
44
+ expect(err.context).to eq(context)
45
45
  }
46
46
  end
47
47
  end
@@ -15,12 +15,12 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
15
15
 
16
16
  describe '#call' do
17
17
  before :each do
18
- context.stub :search => search
18
+ allow(context).to receive_messages :search => search
19
19
  end
20
20
 
21
21
  context 'one stale ids exception' do
22
22
  before :each do
23
- app.stub(:call) do
23
+ allow(app).to receive(:call) do
24
24
  @calls ||= 0
25
25
  @calls += 1
26
26
  raise ThinkingSphinx::Search::StaleIdsException.new([12], context) if @calls == 1
@@ -30,7 +30,7 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
30
30
  it "appends the ids to the without_ids filter" do
31
31
  middleware.call [context]
32
32
 
33
- search.options[:without_ids].should == [12]
33
+ expect(search.options[:without_ids]).to eq([12])
34
34
  end
35
35
 
36
36
  it "respects existing without_ids filters" do
@@ -38,13 +38,13 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
38
38
 
39
39
  middleware.call [context]
40
40
 
41
- search.options[:without_ids].should == [11, 12]
41
+ expect(search.options[:without_ids]).to eq([11, 12])
42
42
  end
43
43
  end
44
44
 
45
45
  context 'two stale ids exceptions' do
46
46
  before :each do
47
- app.stub(:call) do
47
+ allow(app).to receive(:call) do
48
48
  @calls ||= 0
49
49
  @calls += 1
50
50
  raise ThinkingSphinx::Search::StaleIdsException.new([12], context) if @calls == 1
@@ -55,7 +55,7 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
55
55
  it "appends the ids to the without_ids filter" do
56
56
  middleware.call [context]
57
57
 
58
- search.options[:without_ids].should == [12, 13]
58
+ expect(search.options[:without_ids]).to eq([12, 13])
59
59
  end
60
60
 
61
61
  it "respects existing without_ids filters" do
@@ -63,13 +63,13 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
63
63
 
64
64
  middleware.call [context]
65
65
 
66
- search.options[:without_ids].should == [11, 12, 13]
66
+ expect(search.options[:without_ids]).to eq([11, 12, 13])
67
67
  end
68
68
  end
69
69
 
70
70
  context 'three stale ids exceptions' do
71
71
  before :each do
72
- app.stub(:call) do
72
+ allow(app).to receive(:call) do
73
73
  @calls ||= 0
74
74
  @calls += 1
75
75
 
@@ -80,10 +80,10 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
80
80
  end
81
81
 
82
82
  it "raises the final stale ids exceptions" do
83
- lambda {
83
+ expect {
84
84
  middleware.call [context]
85
- }.should raise_error(ThinkingSphinx::Search::StaleIdsException) { |err|
86
- err.ids.should == [14]
85
+ }.to raise_error(ThinkingSphinx::Search::StaleIdsException) { |err|
86
+ expect(err.ids).to eq([14])
87
87
  }
88
88
  end
89
89
  end
@@ -92,8 +92,8 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
92
92
  let(:context2) { {:raw => [], :results => []} }
93
93
  let(:search2) { double('search2', :options => {}) }
94
94
  before :each do
95
- context2.stub :search => search2
96
- app.stub(:call) do
95
+ allow(context2).to receive_messages :search => search2
96
+ allow(app).to receive(:call) do
97
97
  @calls ||= 0
98
98
  @calls += 1
99
99
  raise ThinkingSphinx::Search::StaleIdsException.new([12], context2) if @calls == 1
@@ -102,8 +102,8 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
102
102
 
103
103
  it "appends the ids to the without_ids filter in the correct context" do
104
104
  middleware.call [context, context2]
105
- search.options[:without_ids].should == nil
106
- search2.options[:without_ids].should == [12]
105
+ expect(search.options[:without_ids]).to eq(nil)
106
+ expect(search2.options[:without_ids]).to eq([12])
107
107
  end
108
108
  end
109
109
 
@@ -15,7 +15,7 @@ describe ThinkingSphinx::Panes::AttributesPane do
15
15
  it "returns the object's sphinx attributes by default" do
16
16
  raw['foo'] = 24
17
17
 
18
- pane.sphinx_attributes.should == {'foo' => 24}
18
+ expect(pane.sphinx_attributes).to eq({'foo' => 24})
19
19
  end
20
20
  end
21
21
  end
@@ -15,13 +15,13 @@ describe ThinkingSphinx::Panes::DistancePane do
15
15
  it "returns the object's geodistance attribute by default" do
16
16
  raw['geodist'] = 123.45
17
17
 
18
- pane.distance.should == 123.45
18
+ expect(pane.distance).to eq(123.45)
19
19
  end
20
20
 
21
21
  it "converts string geodistances to floats" do
22
22
  raw['geodist'] = '123.450'
23
23
 
24
- pane.distance.should == 123.45
24
+ expect(pane.distance).to eq(123.45)
25
25
  end
26
26
  end
27
27
 
@@ -29,13 +29,13 @@ describe ThinkingSphinx::Panes::DistancePane do
29
29
  it "returns the object's geodistance attribute by default" do
30
30
  raw['geodist'] = 123.45
31
31
 
32
- pane.geodist.should == 123.45
32
+ expect(pane.geodist).to eq(123.45)
33
33
  end
34
34
 
35
35
  it "converts string geodistances to floats" do
36
36
  raw['geodist'] = '123.450'
37
37
 
38
- pane.geodist.should == 123.45
38
+ expect(pane.geodist).to eq(123.45)
39
39
  end
40
40
  end
41
41
  end
@@ -13,7 +13,7 @@ describe ThinkingSphinx::Panes::ExcerptsPane do
13
13
  let(:search) { double('search', :query => 'foo', :options => {}) }
14
14
 
15
15
  before :each do
16
- context.stub :search => search
16
+ allow(context).to receive_messages :search => search
17
17
  end
18
18
 
19
19
  describe '#excerpts' do
@@ -22,18 +22,18 @@ describe ThinkingSphinx::Panes::ExcerptsPane do
22
22
 
23
23
  before :each do
24
24
  stub_const 'ThinkingSphinx::Excerpter', double(:new => excerpter)
25
- ThinkingSphinx::Panes::ExcerptsPane::Excerpts.stub :new => excerpts
25
+ allow(ThinkingSphinx::Panes::ExcerptsPane::Excerpts).to receive_messages :new => excerpts
26
26
  end
27
27
 
28
28
  it "returns an excerpt glazing" do
29
- pane.excerpts.should == excerpts
29
+ expect(pane.excerpts).to eq(excerpts)
30
30
  end
31
31
 
32
32
  it "creates an excerpter with the first index and the query and conditions values" do
33
33
  context[:indices] = [double(:name => 'alpha'), double(:name => 'beta')]
34
34
  context.search.options[:conditions] = {:baz => 'bar'}
35
35
 
36
- ThinkingSphinx::Excerpter.should_receive(:new).
36
+ expect(ThinkingSphinx::Excerpter).to receive(:new).
37
37
  with('alpha', 'foo bar', anything).and_return(excerpter)
38
38
 
39
39
  pane.excerpts
@@ -42,7 +42,7 @@ describe ThinkingSphinx::Panes::ExcerptsPane do
42
42
  it "passes through excerpts options" do
43
43
  search.options[:excerpts] = {:before_match => 'foo'}
44
44
 
45
- ThinkingSphinx::Excerpter.should_receive(:new).
45
+ expect(ThinkingSphinx::Excerpter).to receive(:new).
46
46
  with(anything, anything, :before_match => 'foo').and_return(excerpter)
47
47
 
48
48
  pane.excerpts
@@ -14,7 +14,7 @@ describe ThinkingSphinx::Panes::WeightPane do
14
14
  it "returns the object's weight by default" do
15
15
  raw[ThinkingSphinx::SphinxQL.weight[:column]] = 101
16
16
 
17
- pane.weight.should == 101
17
+ expect(pane.weight).to eq(101)
18
18
  end
19
19
  end
20
20
  end
@@ -5,31 +5,31 @@ describe ThinkingSphinx::RakeInterface do
5
5
  let(:interface) { ThinkingSphinx::RakeInterface.new }
6
6
 
7
7
  before :each do
8
- ThinkingSphinx::Configuration.stub :instance => configuration
9
- interface.stub(:puts => nil)
8
+ allow(ThinkingSphinx::Configuration).to receive_messages :instance => configuration
9
+ allow(interface).to receive_messages(:puts => nil)
10
10
  end
11
11
 
12
12
  describe '#clear_all' do
13
13
  let(:controller) { double 'controller' }
14
14
 
15
15
  before :each do
16
- configuration.stub(
16
+ allow(configuration).to receive_messages(
17
17
  :indices_location => '/path/to/indices',
18
18
  :searchd => double(:binlog_path => '/path/to/binlog')
19
19
  )
20
20
 
21
- FileUtils.stub :rm_r => true
22
- File.stub :exists? => true
21
+ allow(FileUtils).to receive_messages :rm_r => true
22
+ allow(File).to receive_messages :exists? => true
23
23
  end
24
24
 
25
25
  it "removes the directory for the index files" do
26
- FileUtils.should_receive(:rm_r).with('/path/to/indices')
26
+ expect(FileUtils).to receive(:rm_r).with('/path/to/indices')
27
27
 
28
28
  interface.clear_all
29
29
  end
30
30
 
31
31
  it "removes the directory for the binlog files" do
32
- FileUtils.should_receive(:rm_r).with('/path/to/binlog')
32
+ expect(FileUtils).to receive(:rm_r).with('/path/to/binlog')
33
33
 
34
34
  interface.clear_all
35
35
  end
@@ -42,31 +42,32 @@ describe ThinkingSphinx::RakeInterface do
42
42
  }
43
43
 
44
44
  before :each do
45
- configuration.stub(
46
- :indices => [double(:type => 'plain'), index],
47
- :searchd => double(:binlog_path => '/path/to/binlog')
45
+ allow(configuration).to receive_messages(
46
+ :indices => [double(:type => 'plain'), index],
47
+ :searchd => double(:binlog_path => '/path/to/binlog'),
48
+ :preload_indices => true
48
49
  )
49
50
 
50
- Dir.stub :[] => ['foo.a', 'foo.b']
51
- FileUtils.stub :rm_r => true, :rm => true
52
- File.stub :exists? => true
51
+ allow(Dir).to receive_messages :[] => ['foo.a', 'foo.b']
52
+ allow(FileUtils).to receive_messages :rm_r => true, :rm => true
53
+ allow(File).to receive_messages :exists? => true
53
54
  end
54
55
 
55
56
  it 'finds each file for real-time indices' do
56
- Dir.should_receive(:[]).with('/path/to/my/index.*').and_return([])
57
+ expect(Dir).to receive(:[]).with('/path/to/my/index.*').and_return([])
57
58
 
58
59
  interface.clear_real_time
59
60
  end
60
61
 
61
62
  it "removes each file for real-time indices" do
62
- FileUtils.should_receive(:rm).with('foo.a')
63
- FileUtils.should_receive(:rm).with('foo.b')
63
+ expect(FileUtils).to receive(:rm).with('foo.a')
64
+ expect(FileUtils).to receive(:rm).with('foo.b')
64
65
 
65
66
  interface.clear_real_time
66
67
  end
67
68
 
68
69
  it "removes the directory for the binlog files" do
69
- FileUtils.should_receive(:rm_r).with('/path/to/binlog')
70
+ expect(FileUtils).to receive(:rm_r).with('/path/to/binlog')
70
71
 
71
72
  interface.clear_real_time
72
73
  end
@@ -76,20 +77,20 @@ describe ThinkingSphinx::RakeInterface do
76
77
  let(:controller) { double('controller') }
77
78
 
78
79
  before :each do
79
- configuration.stub(
80
+ allow(configuration).to receive_messages(
80
81
  :configuration_file => '/path/to/foo.conf',
81
82
  :render_to_file => true
82
83
  )
83
84
  end
84
85
 
85
86
  it "renders the configuration to a file" do
86
- configuration.should_receive(:render_to_file)
87
+ expect(configuration).to receive(:render_to_file)
87
88
 
88
89
  interface.configure
89
90
  end
90
91
 
91
92
  it "prints a message stating the file is being generated" do
92
- interface.should_receive(:puts).
93
+ expect(interface).to receive(:puts).
93
94
  with('Generating configuration to /path/to/foo.conf')
94
95
 
95
96
  interface.configure
@@ -100,30 +101,30 @@ describe ThinkingSphinx::RakeInterface do
100
101
  let(:controller) { double('controller', :index => true) }
101
102
 
102
103
  before :each do
103
- ThinkingSphinx.stub :before_index_hooks => []
104
- configuration.stub(
104
+ allow(ThinkingSphinx).to receive_messages :before_index_hooks => []
105
+ allow(configuration).to receive_messages(
105
106
  :configuration_file => '/path/to/foo.conf',
106
107
  :render_to_file => true,
107
108
  :indices_location => '/path/to/indices'
108
109
  )
109
110
 
110
- FileUtils.stub :mkdir_p => true
111
+ allow(FileUtils).to receive_messages :mkdir_p => true
111
112
  end
112
113
 
113
114
  it "renders the configuration to a file by default" do
114
- configuration.should_receive(:render_to_file)
115
+ expect(configuration).to receive(:render_to_file)
115
116
 
116
117
  interface.index
117
118
  end
118
119
 
119
120
  it "does not render the configuration if requested" do
120
- configuration.should_not_receive(:render_to_file)
121
+ expect(configuration).not_to receive(:render_to_file)
121
122
 
122
123
  interface.index false
123
124
  end
124
125
 
125
126
  it "creates the directory for the index files" do
126
- FileUtils.should_receive(:mkdir_p).with('/path/to/indices')
127
+ expect(FileUtils).to receive(:mkdir_p).with('/path/to/indices')
127
128
 
128
129
  interface.index
129
130
  end
@@ -134,66 +135,73 @@ describe ThinkingSphinx::RakeInterface do
134
135
 
135
136
  interface.index
136
137
 
137
- called.should be_true
138
+ expect(called).to be_truthy
138
139
  end
139
140
 
140
141
  it "indexes all indices verbosely" do
141
- controller.should_receive(:index).with(:verbose => true)
142
+ expect(controller).to receive(:index).with(:verbose => true)
142
143
 
143
144
  interface.index
144
145
  end
145
146
 
146
147
  it "does not index verbosely if requested" do
147
- controller.should_receive(:index).with(:verbose => false)
148
+ expect(controller).to receive(:index).with(:verbose => false)
148
149
 
149
150
  interface.index true, false
150
151
  end
151
152
  end
152
153
 
153
154
  describe '#start' do
154
- let(:controller) { double('controller', :start => true, :pid => 101) }
155
+ let(:controller) { double('controller', :start => result, :pid => 101) }
156
+ let(:result) { double 'result', :command => 'start', :status => 1,
157
+ :output => '' }
155
158
 
156
159
  before :each do
157
- controller.stub(:running?).and_return(false, true)
158
- configuration.stub :indices_location => 'my/index/files'
160
+ allow(controller).to receive(:running?).and_return(false, true)
161
+ allow(configuration).to receive_messages(
162
+ :indices_location => 'my/index/files',
163
+ :searchd => double(:log => '/path/to/log')
164
+ )
159
165
 
160
- FileUtils.stub :mkdir_p => true
166
+ allow(FileUtils).to receive_messages :mkdir_p => true
161
167
  end
162
168
 
163
169
  it "creates the index files directory" do
164
- FileUtils.should_receive(:mkdir_p).with('my/index/files')
170
+ expect(FileUtils).to receive(:mkdir_p).with('my/index/files')
165
171
 
166
172
  interface.start
167
173
  end
168
174
 
169
175
  it "starts the daemon" do
170
- controller.should_receive(:start)
176
+ expect(controller).to receive(:start)
171
177
 
172
178
  interface.start
173
179
  end
174
180
 
175
181
  it "raises an error if the daemon is already running" do
176
- controller.stub :running? => true
182
+ allow(controller).to receive_messages :running? => true
177
183
 
178
- lambda {
184
+ expect {
179
185
  interface.start
180
- }.should raise_error(RuntimeError)
186
+ }.to raise_error(ThinkingSphinx::SphinxAlreadyRunning)
181
187
  end
182
188
 
183
189
  it "prints a success message if the daemon has started" do
184
- controller.stub(:running?).and_return(false, true)
190
+ allow(controller).to receive(:running?).and_return(false, true)
185
191
 
186
- interface.should_receive(:puts).
192
+ expect(interface).to receive(:puts).
187
193
  with('Started searchd successfully (pid: 101).')
188
194
 
189
195
  interface.start
190
196
  end
191
197
 
192
198
  it "prints a failure message if the daemon does not start" do
193
- controller.stub(:running?).and_return(false, false)
199
+ allow(controller).to receive(:running?).and_return(false, false)
200
+ allow(interface).to receive(:exit)
194
201
 
195
- interface.should_receive(:puts).
196
- with('Failed to start searchd. Check the log files for more information.')
202
+ expect(interface).to receive(:puts) do |string|
203
+ expect(string).to match('The Sphinx start command failed')
204
+ end
197
205
 
198
206
  interface.start
199
207
  end
@@ -201,33 +209,38 @@ describe ThinkingSphinx::RakeInterface do
201
209
 
202
210
  describe '#stop' do
203
211
  let(:controller) { double('controller', :stop => true, :pid => 101) }
212
+ let(:result) { double 'result', :command => 'start', :status => 1,
213
+ :output => '' }
204
214
 
205
215
  before :each do
206
- controller.stub :running? => true
216
+ allow(controller).to receive(:running?).and_return(true, true, false)
207
217
  end
208
218
 
209
219
  it "prints a message if the daemon is not already running" do
210
- controller.stub :running? => false
220
+ allow(controller).to receive_messages :running? => false
211
221
 
212
- interface.should_receive(:puts).with('searchd is not currently running.')
222
+ expect(interface).to receive(:puts).with('searchd is not currently running.')
213
223
 
214
224
  interface.stop
215
225
  end
216
226
 
217
227
  it "stops the daemon" do
218
- controller.should_receive(:stop)
228
+ expect(controller).to receive(:stop)
219
229
 
220
230
  interface.stop
221
231
  end
222
232
 
223
233
  it "prints a message informing the daemon has stopped" do
224
- interface.should_receive(:puts).with('Stopped searchd daemon (pid: 101).')
234
+ expect(interface).to receive(:puts).with('Stopped searchd daemon (pid: 101).')
225
235
 
226
236
  interface.stop
227
237
  end
228
238
 
229
239
  it "should retry stopping the daemon until it stops" do
230
- controller.should_receive(:stop).twice.and_return(false, true)
240
+ allow(controller).to receive(:running?).
241
+ and_return(true, true, true, false)
242
+
243
+ expect(controller).to receive(:stop).twice
231
244
 
232
245
  interface.stop
233
246
  end
@@ -237,18 +250,18 @@ describe ThinkingSphinx::RakeInterface do
237
250
  let(:controller) { double('controller') }
238
251
 
239
252
  it "reports when the daemon is running" do
240
- controller.stub :running? => true
253
+ allow(controller).to receive_messages :running? => true
241
254
 
242
- interface.should_receive(:puts).
255
+ expect(interface).to receive(:puts).
243
256
  with('The Sphinx daemon searchd is currently running.')
244
257
 
245
258
  interface.status
246
259
  end
247
260
 
248
261
  it "reports when the daemon is not running" do
249
- controller.stub :running? => false
262
+ allow(controller).to receive_messages :running? => false
250
263
 
251
- interface.should_receive(:puts).
264
+ expect(interface).to receive(:puts).
252
265
  with('The Sphinx daemon searchd is not currently running.')
253
266
 
254
267
  interface.status