sunspot_rails gem - Errno:: ECONNREFUSED (Connection refused - connect (2))
Have you started the Solr server?
rake sunspot:solr:start
If not than start the solr server first
And If yes than try
rake sunspot:solr:run
Hope this will help .
connection rejected from solr in Rspec
Your before(:all)
probably just isn't giving Solr enough time to start.
That said, you'll probably want to think hard about just what you're asking your specs to verify here. You can go a long way with mocking out calls to Solr with a library like Fakeweb.
Pivotal Labs also has a library called sunspot_matchers that can capture more fine-grained assertions about the searches you're invoking.
If you are going for real integration specs against Solr, I advise just keeping a test Solr running while you work. A tool like Foreman can help manage your Solr proceses. I might use a Procfile
like the following:
solr_dev: rake sunspot:solr:run RAILS_ENV=development
solr_test: rake sunspot:solr:run RAILS_ENV=test
(Development is, of course, the default environment if no RAILS_ENV is otherwise provided to foreman start
)
Finally, if you want to start Solr within your specs, you're already on the right track. Just toss a sleep
in there with enough time to let Solr fully boot itself before your specs start running. Don't be surprised if that introduces a bit of unpredictable failure into your spec suite when the system is under load.
[Edit: Quick and dirty before :all
which uses Sunspot.remove_all
to poll for availability.]
before :all do
`sunspot-solr start`
begin
Sunspot.remove_all!
rescue Errno::ECONNREFUSED
sleep 1 && retry
end
end
rails RSolr::Error::ConnectionRefused: Connection refused error
I've forgot to run the command
rake sunspot:solr:run
Hope that helps someone new with sunspot/solr such as myself
Related Topics
Is Assignment in a Conditional Clause Good Ruby Style
Rails - Paperclip Validating Attachment Size When It Shouldn't Be
Where to Insert Rack::Deflater in the Rack
Machinist VS Factorygirl - Pros and Cons
How to Select the Longest String from a Ruby Array
Marking an Unused Block Variable
Trouble on Rendering a Template Passing a Local Variable
Differencebetween 'Size' and 'Length' Methods
Breaking Ruby Module Across Several Files
How to Dynamically Call Accessor Methods in Ruby
Where Does Ruby Keep Track of Its Open File Descriptors
Differences Between Literals and Constructors? ([] VS Array.New and {} VS Hash.New)
How to Get Words Frequency in Efficient Way with Ruby
Ruby - Array.Join Versus String Concatenation (Efficiency)