[rspec-users] How to dummy a DB adapter?

James Byrne lists at ruby-forum.com
Wed Mar 11 14:02:56 EDT 2009

I am writing a library module to handle certain StatementInvalid type AR
exceptions.  I wish to catch the case where the db adapter in use is not
supported by the module.  I would like to test this situation and have
only a vague idea as to how to proceed.

My exception handling method selects the parsing method based on the
adapter_name value.

  def hll_ar_exception(exception)
    raise exception unless exception.class.to_s ==
    acan =  self.connection.adapter_name
    case acan
    when 'MySQL'
    when 'PostgreSQL'
    when 'SQLite'
      Rails::logger.warn("Adapter #{acan} not supported by
      raise exception

I am thinking about simply opening SQLiteAdapter and overriding the
adapter_name method to some arbitrary value for the test.  However, it
occurs to me that there are probably better ways to do what I am trying
to accomplish so I welcome any suggestions on how to proceed.
Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list