Skip to content

Instantly share code, notes, and snippets.

@urbanautomaton
Created November 20, 2011 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urbanautomaton/1380180 to your computer and use it in GitHub Desktop.
Save urbanautomaton/1380180 to your computer and use it in GitHub Desktop.
@search
Scenario: List products
Given the system has the following products:
| id | name |
| 1 | Acme Flaming Hammer |
| 2 | Adidas Patented Truss |
| 3 | Corby Trouser Press |
And I authenticate as admin
And I send and accept XML
And the search index is updated
When I send a GET request for "/products"
Then the response should be "200"
And the XML response should be a "products" array with 3 "product" elements
expected: 3
got: 0 (using ==) (RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/api_steps.rb:44:in `/^the XML response should be a "([^\"]*)" array with (\d+) "([^\"]*)" elements$/'
features/api/v1/product.feature:19:in `And the XML response should be a "products" array with 3 "product" elements'
class Product < ActiveRecord::Base
# ...
define_index do
indexes name, :sortable => true
end
# ...
end
Given 'the search index is updated' do
# Update all indexes
ThinkingSphinx::Test.index
sleep(0.25) # Wait for Sphinx to catch up
end
Given /^the search index for (\w+)s is updated$/ do |model|
# Update specific indexes
ThinkingSphinx::Test.index "#{model}_core"
sleep(0.25) # Wait for Sphinx to catch up
end
require 'cucumber/thinking_sphinx/external_world'
Cucumber::ThinkingSphinx::ExternalWorld.new
Cucumber::Rails::World.use_transactional_fixtures = false
Before('@search') do
DatabaseCleaner.strategy = :truncation
end
Before('~@search') do
DatabaseCleaner.strategy = :transaction
end
Before do
DatabaseCleaner.start
end
After do
DatabaseCleaner.clean
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment