我是红宝石行业的新手,还想亲手做厨师。我已经写了一本关于postgresql社区食谱的包装器食谱,并希望使用测试厨房来测试它。下面是我写的spec.rb文件:
require 'serverspec'
require 'pg'
include Serverspec::Helper::Exec
include Serverspec::Helper::DetectOS
RSpec.configure do |c|
c.before :all do
c.path = '/sbin:/usr/sbin'
c.os = backend(Serverspec::Commands::Base).check_os
end
end
describe "Postgresql server" do
it "should connect to database" do
conn = PG::Connection.open(:dbname => "db",:user => "user1",:password => "password")
conn.status == "CONNECTION_OK"
end
end通过此测试,我希望检查用户和数据库是否已正确创建。然而,此测试无法解决"pg“的依赖。我应该在serverspec中的什么地方提到这个依赖呢?我已经使用kitchen verify [node name]来运行测试。
发布于 2014-03-01 00:35:04
在spec_helper.rb文件中需要gem之前,创建安装gem所需的Ruby代码(如果更有意义,也可以放在spec文件的顶部):
begin
Gem::Specification.find_by_name('pg')
rescue Gem::LoadError
require 'rubygems/dependency_installer'
Gem::DependencyInstaller.new(Gem::DependencyInstaller::DEFAULT_OPTIONS).install('pg')
end
require 'pg'https://stackoverflow.com/questions/22096732
复制相似问题