Sha256: fb1061ceab3f54d219df9e48d2aa46beeedecec4bc7220b1dd4304d5af51f035
Contents?: true
Size: 1.92 KB
Versions: 3
Compression:
Stored size: 1.92 KB
Contents
# frozen_string_literal: true module Cucumber module Rails module Database CUSTOM_STRATEGY_INTERFACE = %w[before_js before_non_js].freeze class InvalidStrategy < ArgumentError; end class << self attr_accessor :autorun_database_cleaner def javascript_strategy=(args) strategy, *strategy_opts = args strategy_type = case strategy when Symbol map[strategy] || throw_invalid_strategy_error(strategy) when Class strategy end @strategy = strategy_type.new(*strategy_opts) validate_interface! end def default_strategy! self.javascript_strategy = :truncation self.autorun_database_cleaner = true end def before_js @strategy.before_js end def before_non_js @strategy.before_non_js end def after @strategy.after end private def map { truncation: TruncationStrategy, shared_connection: SharedConnectionStrategy, transaction: SharedConnectionStrategy, deletion: DeletionStrategy } end def throw_invalid_strategy_error(strategy) raise(InvalidStrategy, "The strategy '#{strategy}' is not understood. Please use one of #{mapped_keys}") end def mapped_keys map.keys.join(', ') end def validate_interface! return if CUSTOM_STRATEGY_INTERFACE.all? { |m| @strategy.respond_to?(m) } throw_invalid_strategy_interface_error end def throw_invalid_strategy_interface_error raise( ArgumentError, "Strategy must respond to all of: #{CUSTOM_STRATEGY_INTERFACE.map { |method| "##{method}" } * ' '} !" ) end end default_strategy! end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
cucumber-rails-2.4.0 | lib/cucumber/rails/database.rb |
cucumber-rails-2.3.0 | lib/cucumber/rails/database.rb |
cucumber-rails-2.2.0 | lib/cucumber/rails/database.rb |