Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reworking Cucumber setup.

  • Loading branch information...
commit a3c70219e19674f1f0119d5bd1231e7d28131f30 1 parent 95f8c69
Pat Allan pat authored
2  .gitignore
View
@@ -3,6 +3,6 @@ pkg
coverage
*.tmproj
rdoc
-spec/fixtures/database.yml
+database.yml
tmp
*.gem
6 cucumber.yml
View
@@ -1,5 +1,5 @@
-default: "--require features/support/env.rb --require features/support/db/mysql.rb --require features/support/db/active_record.rb --require features/support/post_database.rb --require features/step_definitions/alpha_steps.rb --require features/step_definitions/beta_steps.rb --require features/step_definitions/common_steps.rb --require features/step_definitions/datetime_delta_steps.rb --require features/step_definitions/delayed_delta_indexing_steps.rb --require features/step_definitions/extensible_delta_indexing_steps.rb --require features/step_definitions/facet_steps.rb --require features/step_definitions/find_arguments_steps.rb --require features/step_definitions/gamma_steps.rb --require features/step_definitions/scope_steps.rb --require features/step_definitions/search_steps.rb --require features/step_definitions/sphinx_steps.rb"
+default: "--require features/support/env.rb --require features/step_definitions/alpha_steps.rb --require features/step_definitions/beta_steps.rb --require features/step_definitions/common_steps.rb --require features/step_definitions/datetime_delta_steps.rb --require features/step_definitions/delayed_delta_indexing_steps.rb --require features/step_definitions/extensible_delta_indexing_steps.rb --require features/step_definitions/facet_steps.rb --require features/step_definitions/find_arguments_steps.rb --require features/step_definitions/gamma_steps.rb --require features/step_definitions/scope_steps.rb --require features/step_definitions/search_steps.rb --require features/step_definitions/sphinx_steps.rb"
-mysql: "--require features/support/env.rb --require features/support/db/mysql.rb --require features/support/db/active_record.rb --require features/support/post_database.rb --require features/step_definitions/alpha_steps.rb --require features/step_definitions/beta_steps.rb --require features/step_definitions/common_steps.rb --require features/step_definitions/datetime_delta_steps.rb --require features/step_definitions/delayed_delta_indexing_steps.rb --require features/step_definitions/extensible_delta_indexing_steps.rb --require features/step_definitions/facet_steps.rb --require features/step_definitions/find_arguments_steps.rb --require features/step_definitions/gamma_steps.rb --require features/step_definitions/scope_steps.rb --require features/step_definitions/search_steps.rb --require features/step_definitions/sphinx_steps.rb features/alternate_primary_key.feature features/attribute_transformation.feature features/attribute_updates.feature features/datetime_deltas.feature features/delayed_delta_indexing.feature features/deleting_instances.feature features/direct_attributes.feature features/excerpts.feature features/extensible_delta_indexing.feature features/facets.feature features/facets_across_model.feature features/handling_edits.feature features/retry_stale_indexes.feature features/searching_across_models.feature features/searching_by_model.feature features/searching_with_find_arguments.feature features/sphinx_detection.feature features/sphinx_scopes.feature features/sti_searching.feature"
+mysql: "--require features/support/env.rb --require features/step_definitions/alpha_steps.rb --require features/step_definitions/beta_steps.rb --require features/step_definitions/common_steps.rb --require features/step_definitions/datetime_delta_steps.rb --require features/step_definitions/delayed_delta_indexing_steps.rb --require features/step_definitions/extensible_delta_indexing_steps.rb --require features/step_definitions/facet_steps.rb --require features/step_definitions/find_arguments_steps.rb --require features/step_definitions/gamma_steps.rb --require features/step_definitions/scope_steps.rb --require features/step_definitions/search_steps.rb --require features/step_definitions/sphinx_steps.rb features/alternate_primary_key.feature features/attribute_transformation.feature features/attribute_updates.feature features/datetime_deltas.feature features/delayed_delta_indexing.feature features/deleting_instances.feature features/direct_attributes.feature features/excerpts.feature features/extensible_delta_indexing.feature features/facets.feature features/facets_across_model.feature features/handling_edits.feature features/retry_stale_indexes.feature features/searching_across_models.feature features/searching_by_model.feature features/searching_with_find_arguments.feature features/sphinx_detection.feature features/sphinx_scopes.feature features/sti_searching.feature"
-postgresql: "--require features/support/env.rb --require features/support/db/postgresql.rb --require features/support/db/active_record.rb --require features/support/post_database.rb --require features/step_definitions/alpha_steps.rb --require features/step_definitions/beta_steps.rb --require features/step_definitions/common_steps.rb --require features/step_definitions/datetime_delta_steps.rb --require features/step_definitions/delayed_delta_indexing_steps.rb --require features/step_definitions/extensible_delta_indexing_steps.rb --require features/step_definitions/facet_steps.rb --require features/step_definitions/find_arguments_steps.rb --require features/step_definitions/gamma_steps.rb --require features/step_definitions/scope_steps.rb --require features/step_definitions/search_steps.rb --require features/step_definitions/sphinx_steps.rb features/alternate_primary_key.feature features/attribute_transformation.feature features/attribute_updates.feature features/datetime_deltas.feature features/delayed_delta_indexing.feature features/deleting_instances.feature features/direct_attributes.feature features/excerpts.feature features/extensible_delta_indexing.feature features/facets.feature features/facets_across_model.feature features/handling_edits.feature features/retry_stale_indexes.feature features/searching_across_models.feature features/searching_by_model.feature features/searching_with_find_arguments.feature features/sphinx_detection.feature features/sphinx_scopes.feature features/sti_searching.feature"
+postgresql: "--require features/support/env.rb --require features/step_definitions/alpha_steps.rb --require features/step_definitions/beta_steps.rb --require features/step_definitions/common_steps.rb --require features/step_definitions/datetime_delta_steps.rb --require features/step_definitions/delayed_delta_indexing_steps.rb --require features/step_definitions/extensible_delta_indexing_steps.rb --require features/step_definitions/facet_steps.rb --require features/step_definitions/find_arguments_steps.rb --require features/step_definitions/gamma_steps.rb --require features/step_definitions/scope_steps.rb --require features/step_definitions/search_steps.rb --require features/step_definitions/sphinx_steps.rb features/alternate_primary_key.feature features/attribute_transformation.feature features/attribute_updates.feature features/datetime_deltas.feature features/delayed_delta_indexing.feature features/deleting_instances.feature features/direct_attributes.feature features/excerpts.feature features/extensible_delta_indexing.feature features/facets.feature features/facets_across_model.feature features/handling_edits.feature features/retry_stale_indexes.feature features/searching_across_models.feature features/searching_by_model.feature features/searching_with_find_arguments.feature features/sphinx_detection.feature features/sphinx_scopes.feature features/sti_searching.feature"
17 features/a.rb
View
@@ -1,17 +0,0 @@
-# This file exists because Cucumber likes to auto-load all ruby files
-puts <<-MESSAGE
-Cucumber 0.1.12 defaults to loading all ruby files within the features folder
-alphabetically. This is annoying, because some files need to be loaded before
-others (and others perhaps not at all, given missing dependencies). Hence this
-place-holder imaginatively named 'a.rb', to force this message.
-
-A work-around is to use cucumber profiles. You will find the default profile in
-cucumber.yml should serve your needs fine, unless you add new step definitions.
-When you do that, you can regenerate the YAML file by running:
-rake cucumber_defaults
-
-And then run specific features as follows is slightly more verbose, but it
-works, whereas this doesn't.
-cucumber -p default features/something.feature
-MESSAGE
-exit 0
0  features/support/db/database.example.yml → features/support/database.example.yml
View
File renamed without changes
10 features/support/env.rb
View
@@ -3,4 +3,12 @@
require 'spec'
require 'fileutils'
require 'ginger'
-require 'will_paginate'
+require 'will_paginate'
+
+$:.unshift File.dirname(__FILE__) + '/../../lib'
+
+require 'thinking_sphinx'
+require 'cucumber/thinking_sphinx/internal_world'
+
+world = Cucumber::ThinkingSphinx::InternalWorld.new
+world.setup
19 features/support/z.rb
View
@@ -1,19 +0,0 @@
-# This file exists because Cucumber likes to auto-load all ruby files
-puts <<-MESSAGE
-Cucumber 0.1.13 defaults to loading all ruby files within the features folder,
-with something approaching reverse-alphabetical order, and preferring the
-features/support folder over everything else. This is annoying, because some
-files need to be loaded before others (and others perhaps not at all, given
-missing dependencies). Hence this place-holder imaginatively named 'z.rb', to
-force this message.
-
-A work-around is to use cucumber profiles. You will find the default profile in
-cucumber.yml should serve your needs fine, unless you add new step definitions.
-When you do that, you can regenerate the YAML file by running:
-rake cucumber_defaults
-
-And then run specific features as follows is slightly more verbose, but it
-works, whereas this doesn't.
-cucumber -p default features/something.feature
-MESSAGE
-exit 0
126 lib/cucumber/thinking_sphinx/internal_world.rb
View
@@ -0,0 +1,126 @@
+require 'cucumber/thinking_sphinx/sql_logger'
+
+module Cucumber
+ module ThinkingSphinx
+ class InternalWorld
+ attr_accessor :temporary_directory, :migrations_directory,
+ :models_directory, :fixtures_directory, :database_file
+ attr_accessor :adapter, :database, :username,
+ :password, :host
+
+ def initialize
+ @temporary_directory = "#{Dir.pwd}/tmp"
+ @migrations_directory = "features/support/db/migrations"
+ @models_directory = "features/support/models"
+ @fixtures_directory = "features/support/db/fixtures"
+ @database_file = "features/support/database.yml"
+
+ @adapter = 'mysql'
+ @database = 'thinking_sphinx'
+ @username = 'thinking_sphinx'
+ # @password = 'thinking_sphinx'
+ @host = 'localhost'
+ end
+
+ def setup
+ make_temporary_directory
+
+ configure_cleanup
+ configure_thinking_sphinx
+ configure_database
+ configure_active_record
+
+ prepare_data
+ setup_sphinx
+
+ self
+ end
+
+ private
+
+ def config
+ @config ||= ::ThinkingSphinx::Configuration.instance
+ end
+
+ def make_temporary_directory
+ FileUtils.mkdir_p temporary_directory
+ Dir["#{temporary_directory}/*"].each do |file|
+ FileUtils.rm_rf file
+ end
+ end
+
+ def configure_thinking_sphinx
+ config.config_file = "#{temporary_directory}/sphinx.conf"
+ config.searchd_log_file = "#{temporary_directory}/searchd.log"
+ config.query_log_file = "#{temporary_directory}/searchd.query.log"
+ config.pid_file = "#{temporary_directory}/searchd.pid"
+ config.searchd_file_path = "#{temporary_directory}/indexes/"
+
+ ::ThinkingSphinx.suppress_delta_output = true
+ end
+
+ def configure_cleanup
+ Kernel.at_exit do
+ ::ThinkingSphinx::Configuration.instance.controller.stop
+ sleep(0.5) # Ensure Sphinx has shut down completely
+ ActiveRecord::Base.logger.close
+ end
+ end
+
+ def configure_database
+ ActiveRecord::Base.establish_connection database_settings
+ end
+
+ def yaml_database_settings
+ return {} unless File.exist?(@database_file)
+
+ YAML.load open(@database_file)
+ end
+
+ def database_settings
+ yaml = yaml_database_settings
+ {
+ :adapter => @adapter,
+ :database => yaml['database'] || @database,
+ :username => yaml['username'] || @username,
+ :password => yaml['password'] || @password,
+ :host => yaml['host'] || @host
+ }
+ end
+
+ def configure_active_record
+ ActiveRecord::Base.logger = Logger.new(
+ open("#{temporary_directory}/active_record.log", "a")
+ )
+
+ ActiveRecord::Base.connection.class.send(
+ :include, Cucumber::ThinkingSphinx::SqlLogger
+ )
+ end
+
+ def prepare_data
+ ::ThinkingSphinx.deltas_enabled = false
+
+ load_files migrations_directory
+ load_files models_directory
+ load_files fixtures_directory
+
+ ::ThinkingSphinx.deltas_enabled = true
+ end
+
+ def load_files(path)
+ Dir["#{path}/*.rb"].each do |file|
+ require file.gsub(/\.rb$/, '')
+ end
+ end
+
+ def setup_sphinx
+ FileUtils.mkdir_p config.searchd_file_path
+
+ config.build
+ config.controller.index
+ config.controller.start
+ end
+ end
+ end
+end
20 lib/cucumber/thinking_sphinx/sql_logger.rb
View
@@ -0,0 +1,20 @@
+module Cucumber
+ module ThinkingSphinx
+ module SqlLogger
+ def self.included(base)
+ base.send :alias_method_chain, :execute, :query_record
+ end
+
+ IGNORED_SQL = [
+ /^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/,
+ /^SELECT @@ROWCOUNT/, /^SHOW FIELDS/
+ ]
+
+ def execute_with_query_record(sql, name = nil, &block)
+ $queries_executed ||= []
+ $queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r }
+ execute_without_query_record(sql, name, &block)
+ end
+ end
+ end
+end
5 lib/thinking_sphinx.rb
View
@@ -131,12 +131,13 @@ def self.suppress_delta_output?
def self.suppress_delta_output=(value)
@@suppress_delta_output = value
end
-
+
+ @@use_group_by_shortcut = nil
# Checks to see if MySQL will allow simplistic GROUP BY statements. If not,
# or if not using MySQL, this will return false.
#
def self.use_group_by_shortcut?
- !!(
+ @@use_group_by_shortcut ||= !!(
mysql? && ::ActiveRecord::Base.connection.select_all(
"SELECT @@global.sql_mode, @@session.sql_mode;"
).all? { |key,value| value.nil? || value[/ONLY_FULL_GROUP_BY/].nil? }
Please sign in to comment.
Something went wrong with that request. Please try again.