spec/spec_helper.rb in hack_tree-0.1.0 vs spec/spec_helper.rb in hack_tree-0.1.1
- old
+ new
@@ -1,17 +1,34 @@
-require "pathname"
+# NOTE: I usually support `STANDALONE` mode in specs for Rails projects' components
+# to be able to test them without loading the environment. This project does not
+# depend on Rails *BUT* I still want a consistent RSpec file structure.
+# If this is confusing, feel free to propose something better. :)
-# Load stuff.
-[
- "lib/**/*.rb",
-].each do |fmask|
- Dir["./#{fmask}"].each do |fn|
- ##puts "-- req '#{fn}'"
- require fn
+# No Rails, we're always standalone... and free! :)
+STANDALONE = 1
+
+if STANDALONE
+ # Provide root path object.
+ module Standalone
+ eval <<-EOT
+ def self.root
+ # This is an absolute path, it's perfectly safe to do a `+` and then `require`.
+ Pathname("#{File.expand_path('../..', __FILE__)}")
+ end
+ EOT
end
+
+ # Load stuff.
+ [
+ "lib/hack_tree/**/*.rb",
+ ].each do |fmask|
+ Dir[Standalone.root + fmask].each do |fn|
+ require fn
+ end
+ end
end
-# TODO: When this becomes a gem, use gem instead of direct copy.
+# When this becomes a gem, use gem instead of direct copy.
module RSpec
module PrintOnFailure
module Helpers
# Output <tt>message</tt> before the failed tests in <tt>block</tt>. Useful when input and expected data
# are defined as collections.