First I went with Mat's solution. I'm already using Mocha so it was
easy. The original code has some typo, here's the right version.
def setup
[:index, :commit].each { |method| Sunspot.stubs(method) }
end
Unfortunately this is a partial solution. That's because my code also
calls :remove and I didn't want to end up stubbing each
Sunspot.methods all the time.
So I decided to follow a different approach. Sunspot module is
extremely well coded and all methods rely on the session instance.
Just mock the session object and you're done.
Here's the result http://gist.github.com/229940
The code is quite tied to a Rails app. Having it coded in the main
Sunspot library won't require all the metaprogramming used to
intercept standard Sunspot calls.
I can create a patch, if you find it useful.
Regards,
-- Simone
On Jul 22, 5:04 pm, cyx <cyx.uc...@gmail.com> wrote:
> Ok thanks!
>
> Yep, hmm i'll probably alias the 2 methods you mentioned in the
> meantime since most of my tests will hit solr and it'd be a slight
> pain to add stub calls to the majority of my tests.
>
> But yeah, thanks at least I know which methods to disable now!
>
> On Jul 22, 10:50 pm, "Matthew A. Brown" <mat.a.br...@gmail.com> wrote:
>
> > Hi,
>
> > The simplest thing is probably to use a mocking framework like Mocha
> > or RSpec's built-in mocking to stub out the calls to Sunspot's index -
> > something like this
>
> > class SomeTest < ActiveSupport::TestCase
> > def setup
> > [:index, :commit].each { |method| Sunspot.stub(:method) }
> > end
> > end
>
> > The stub will only last for the duration of thetest, so you'd just