summaryrefslogtreecommitdiff
path: root/spec/lib/puppet_spec/database.rb
diff options
context:
space:
mode:
authorAshley Penney <ashley.penney@puppetlabs.com>2014-03-18 12:34:40 -0400
committerAshley Penney <ashley.penney@puppetlabs.com>2014-03-18 12:34:40 -0400
commitfec943f441f0c6ab8d6b685091d3418ec0e265b4 (patch)
tree144aed26b9fb50790708c5b221afdeb32bc03186 /spec/lib/puppet_spec/database.rb
parent326a8fd801ecba11005189c10ca8749872ef6577 (diff)
parent9aa28f1c100d7703aa1bb9fbe2bcf02bf781b486 (diff)
downloadpuppet-stdlib-fec943f441f0c6ab8d6b685091d3418ec0e265b4.tar.gz
puppet-stdlib-fec943f441f0c6ab8d6b685091d3418ec0e265b4.tar.bz2
Merge pull request #231 from apenney/32-testing
Numerous changes to update testing gems.
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