ruby on rails - Mock Sequel connections to Oracle database -


i'm trying test rails application connects remote oracle database using sequel gem. since user needs logged in in order use site, i'm using webmock. however, because webmock stops requests outside sources, error sequel::databaseconnectionerror: ocierror: ora-12541: tns:no listener every time run tests. how mock database connection? should try else instead?

i'm not sure code provide, here snippets may relate possible solutions:

database_connection.rb:

class databaseconnection   @@db = nil    def self.get_db     @@db ||= sequel.connect(settings.db.main.to_hash)   end    def self.db_query(query)     get_db[query]   end end 

in spec_helper.rb:

require 'webmock/rspec'  webmock.disable_net_connect!(allow_localhost: true)  rspec.configure |config|   config.before(:each)     stub_request(:post, "/path/to/third/party").       with(:body => "request body").       to_return(:status => 200, :body => "", :headers => {})   end    # ... rest of code end 

relevant gems gemfile:

gem 'rails', '4.0.2' gem 'ruby-oci8', git: 'https://github.com/kubo/ruby-oci8.git' group :development, :test   gem 'rspec-rails', '~> 3.2.0' end  group :test   gem 'webmock' # 1.21.0   gem 'capybara' # 2.4.4 end 

sequel ships mock adapter purpose:

@@db ||= sequel.connect('mock://oracle') 

see documentation details how use mocked database:

http://sequel.jeremyevans.net/rdoc-adapters/classes/sequel/mock/database.html http://sequel.jeremyevans.net/rdoc-adapters/classes/sequel/mock/dataset.html


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -