适配器未设置:默认。你忘了设置吗?

时间:2015-05-13 12:08:15

标签: ruby postgresql sinatra datamapper

我在Rspec中执行测试时遇到同样的错误。 DataMapper :: RepositoryNotSetupError:未设置适配器:默认值。你忘了设置吗?我不明白这个错误,因为我已经在Datamapper网页中设置了Datamapper。我告诉你我的代码

vip_client-spec.rb

require 'spec_helper'
require 'data_mapper'
require 'dm-postgres-adapter'
require File.join(File.dirname(__FILE__), '..', '..', 'models', 'vip_client.rb')

describe VipClient do
  before {
    DataMapper.finalize.auto_upgrade!
  }
  describe "#insert_into_database" do
    it "inserts clients into database from an array of hashes" do
      list_clients = [
       {name: "David", birthday: "13-12-1985", email: "daviddsrperiodismo@gmail.com"},
       {name: "Javier", birthday: "05-05-1985", email: "javier@gmail.com"}
      ]
      VipClient.insert_into_database(list_clients)
      expect(VipClient.all.count).to eq(2)
    end
  end
end

vip_client.rb

class VipClient
  include ::DataMapper::Resource
  property :id, Serial
  property :name, Text
  property :birthday, Date
  property :email, Text  

  def self.insert_into_database(list_clients)
  end

end

app.rb

require 'sinatra'
require 'data_mapper'
require 'roo'
require 'pony'

# HELPERS
require './helpers/code'
require './helpers/check_birthday_users'
require './helpers/excel_parser'

# MODELS
require './models/vip_client.rb'
require './models/invitations.rb'

include Code
include CheckUsers

DataMapper.setup(:default, 'postgres://david:123456@localhost/usersmareta')
DataMapper.finalize.auto_upgrade!

我的宝石文件就是这个

source "https://rubygems.org"

gem 'sinatra'
gem 'pg'
gem 'roo'
gem 'data_mapper'
gem 'dm-postgres-adapter'
gem 'pony'

group :development, :test do
  gem 'rack-test'
  gem 'rspec'
end

正如我所说的那样。当我做rspec时,控制台给了我这个:

Failure/Error: DataMapper.finalize.auto_upgrade!
     DataMapper::RepositoryNotSetupError:
       Adapter not set: default. Did you forget to setup?

0 个答案:

没有答案