summaryrefslogtreecommitdiff
path: root/spec/lib/puppet_spec/database.rb
diff options
context:
space:
mode:
authorHunter Haugen <hunter@puppetlabs.com>2014-03-18 16:16:00 -0700
committerHunter Haugen <hunter@puppetlabs.com>2014-03-18 16:16:00 -0700
commit904f1a003e790ba2afaf3452ecda9805e87d80d0 (patch)
tree93407d68868c37af5d597d33134ba5a16e919a21 /spec/lib/puppet_spec/database.rb
parentdb00ce660520abfdc110d1ed0dd10bfbc708e256 (diff)
parentfec943f441f0c6ab8d6b685091d3418ec0e265b4 (diff)
downloadpuppet-stdlib-904f1a003e790ba2afaf3452ecda9805e87d80d0.tar.gz
puppet-stdlib-904f1a003e790ba2afaf3452ecda9805e87d80d0.tar.bz2
Merge branch '3.2.x' into 3.x
Diffstat (limited to 'spec/lib/puppet_spec/database.rb')
-rw-r--r--spec/lib/puppet_spec/database.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/lib/puppet_spec/database.rb b/spec/lib/puppet_spec/database.rb
new file mode 100644
index 0000000..069ca15
--- /dev/null
+++ b/spec/lib/puppet_spec/database.rb
@@ -0,0 +1,29 @@
+# This just makes some nice things available at global scope, and for setup of
+# tests to use a real fake database, rather than a fake stubs-that-don't-work
+# version of the same. Fun times.
+def sqlite?
+ if $sqlite.nil?
+ begin
+ require 'sqlite3'
+ $sqlite = true
+ rescue LoadError
+ $sqlite = false
+ end
+ end
+ $sqlite
+end
+
+def can_use_scratch_database?
+ sqlite? and Puppet.features.rails?
+end
+
+
+# This is expected to be called in your `before :each` block, and will get you
+# ready to roll with a serious database and all. Cleanup is handled
+# automatically for you. Nothing to do there.
+def setup_scratch_database
+ Puppet[:dbadapter] = 'sqlite3'
+ Puppet[:dblocation] = ':memory:'
+ Puppet[:railslog] = PuppetSpec::Files.tmpfile('storeconfigs.log')
+ Puppet::Rails.init
+end