Flexible Searching with Solr and Sunspot

I just posted an article on RubySource.com titled Flexible Searching with Solr and Sunspot. It covers working Solr into a Rails app and massaging Solr to match searches on your content.

Happy searching!

Posted by Mike Pack on 03/07/2012 at 08:54AM

Tags: solr, sunspot, searching


Stubbing CONSTANTS with RSpec

There's not any great info out there about stubbing constants. In fact, you can't stub constants. What you can do is reinitialize them.

The following code is trouble because Ruby complains about reinitializing the constant:

it 'changes the constant' do
  MyClass::SOME_CONSTANT = [1,2,3]
  MyClass::SOME_CONSTANT.should == [1,2,3]
end

#=> warning: already initialized constant SOME_CONSTANT

The spec passes but I hate the warning message Ruby spits out. So here's how we can prevent this warning and achieve the same result:

it 'changes the constant' do
  MyClass.send(:remove_const, 'SOME_CONSTANT')
  MyClass::SOME_CONSTANT = [1,2,3]
  MyClass::SOME_CONSTANT.should == [1,2,3]
end

We explicitly remove the constant before reinitializing it. We use #send to access #remove_const because it's a private method. Happy stubbing!

Posted by Mike Pack on 02/21/2012 at 01:15PM

Tags: rspec, stubbing


SOA for the Little Guys

My article titled "SOA for the Little Guys" was just published on RubySource. It covers breaking apart a monolithic app into services with testing and Sinatra as the driving forces.

Give it a read!

SOA for the Little Guys

Posted by Mike Pack on 02/13/2012 at 10:04AM

Tags: architecture, soa, sinatra, ruby