Forum: RSpec [Cucumber] Cucumber and acts_as_xapian

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3880f04333bf8375b44cd6aa135406c7?d=identicon&s=25 Bart Zonneveld (Guest)
on 2009-02-02 13:06
(Received via mailing list)
Hey list,

Anyone have experience with acts_as_xapian and Cucumber? I'm
struggling with updating xapian's index, to actually "find" fluff
that has been indexed..
In a scenario, I'm adding a bunch of articles, and in the actual
search step, I run:

When "I search for \"$query\"" do |query|
   %x[rake RAILS_ENV=test xapian:update_index]
   fill_in "Search", :with => query
   click_button 'Search'
end

At this point in the scenario, I can see there are articles in the
database. But if I try to query the articles using xapian after the
update_index rake task has run, I don't see any results.
Could this have to do with transactional fixtures or something?
Really stuck here, because I obviously don't want to stub these
searches, and I do want to test them.

thanks,
bartz
C694a032be7518a0d704318895f8fe1d?d=identicon&s=25 Ben Mabey (mabes)
on 2009-02-02 17:33
(Received via mailing list)
Bart Zonneveld wrote:
>   fill_in "Search", :with => query
>   click_button 'Search'
> end
>
> At this point in the scenario, I can see there are articles in the
> database. But if I try to query the articles using xapian after the
> update_index rake task has run, I don't see any results.
> Could this have to do with transactional fixtures or something? Really
> stuck here, because I obviously don't want to stub these searches, and
> I do want to test them.

Yeah, I would say this is due to the transactions.  Try disabling the
transactions and cleaning up the DB yourself (i.e. truncating all the
tables) in the Before hooks.

-Ben
942a74b1b71ca62234ae690b44699ebc?d=identicon&s=25 unknown (Guest)
on 2009-02-02 18:17
(Received via mailing list)
A question for edumacational purposes here: Instead of disabling
transactions, would it be effective to include all the steps of
inserting the record and running the search, inside one scenario?

Given [the record is added to the database"
When [I search for it]
Then [I should find it]

If this can't work, then something is confusing me.  I haven't gotten
into integration testing yet, but I would like to be armed with some
level of understanding going in.

Randy



----- Original Message ----
3880f04333bf8375b44cd6aa135406c7?d=identicon&s=25 Bart Zonneveld (Guest)
on 2009-02-02 20:42
(Received via mailing list)
On 2 feb 2009, at 18:15, r_j_h_box-sf@yahoo.com wrote:

>
> A question for edumacational purposes here: Instead of disabling
> transactions, would it be effective to include all the steps of
> inserting the record and running the search, inside one scenario?

That is exactly what I am doing in my full scenario, but I omitted
those steps for brevity :)

> If this can't work, then something is confusing me.  I haven't
> gotten into integration testing yet, but I would like to be armed
> with some level of understanding going in.

See here for some examples:
http://github.com/aslakhellesoy/cucumber/tree/mast...
Plenty more on the cucumber wikis @ github.

cheers,
bartz
3880f04333bf8375b44cd6aa135406c7?d=identicon&s=25 Bart Zonneveld (Guest)
on 2009-02-02 21:30
(Received via mailing list)
On 2 feb 2009, at 17:00, Ben Mabey wrote:

>>  %x[rake RAILS_ENV=test xapian:update_index]
>
> Yeah, I would say this is due to the transactions.  Try disabling
> the transactions and cleaning up the DB yourself (i.e. truncating
> all the tables) in the Before hooks.

Aye, it was, spot on Ben.

thanks!
bartz
C694a032be7518a0d704318895f8fe1d?d=identicon&s=25 Ben Mabey (mabes)
on 2009-02-02 23:07
(Received via mailing list)
r_j_h_box-sf@yahoo.com wrote:
> A question for edumacational purposes here: Instead of disabling transactions, would it 
be effective to include all the steps of inserting the record and running the search, 
inside one scenario?
>
> Given [the record is added to the database"
> When [I search for it]
> Then [I should find it]
>
> If this can't work, then something is confusing me.  I haven't gotten into integration 
testing yet, but I would like to be armed with some level of understanding going in.
>
> Randy
>


Your intuition is correct.  It should work assuming that all of the DB
calls happen in the same transaction and therefor the same process.
However, the problem that I think Bart is facing is that while all of
this is taking place in the same scenario it is not all taking place in
the same process.  If you notice he is piping a call out to a rake task:

%x[rake RAILS_ENV=test xapian:update_index]

That rake task is not going to be able to see the items that the Given
has created because those INSERTs are being wrapped into a transaction
that will be rolled back at the end of the scenario.  For this reason
the use of transactions need to be avoided so the separate processes are
operating on the same data within the DB.  I wrote about this on the
wiki in the troubleshooting page in the context of selenium- the root
problem is the same in both cases.

HTH,
Ben
This topic is locked and can not be replied to.