spec/spec_helpers.rb in assaf-buildr-1.3.3 vs spec/spec_helpers.rb in assaf-buildr-1.3.4
- old
+ new
@@ -17,20 +17,36 @@
# This file gets loaded twice when running 'spec spec/*' and not with pleasent results,
# so ignore the second attempt to load it.
unless defined?(SpecHelpers)
require 'rubygems'
- $LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__)), File.expand_path('../addon', File.dirname(__FILE__))
+
+ # For testing we use the gem requirements specified on the buildr.gemspec
+ spec = Gem::Specification.load(File.expand_path('../buildr.gemspec', File.dirname(__FILE__)))
+ spec.dependencies.each { |dep| gem dep.name, dep.version_requirements.to_s }
+
+ # Make sure to load from these paths first, we don't want to load any
+ # code from Gem library.
+ $LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__)),
+ File.expand_path('../addon', File.dirname(__FILE__))
+
+ # Buildr uses autoload extensively, but autoload when running specs creates
+ # a problem -- we sandbox $LOADED_FEATURES, so we endup autoloading the same
+ # module twice. This turns autoload into a require, which is not the right
+ # thing, but will do for now.
+ def autoload(symbol, path)
+ require path
+ end
require 'buildr'
require File.expand_path('sandbox', File.dirname(__FILE__))
module SpecHelpers
include Checks::Matchers
- [:info, :warn, :error].each do |severity|
+ [:info, :warn, :error, :puts].each do |severity|
::Object.class_eval do
define_method severity do |message|
$messages ||= {}
($messages[severity] ||= []) << message
end
@@ -72,11 +88,11 @@
# lambda { info 'ze test' }.should show_info(/ze test/)
def show_info(message)
MessageWithSeverityMatcher.new :info, message
end
- # Tests if a warning was issued. You can use a string or regular expression.
+ # Test if a warning was shown. You can use a string or regular expression.
#
# For example:
# lambda { warn 'ze test' }.should show_warning(/ze test/)
def show_warning(message)
MessageWithSeverityMatcher.new :warn, message
@@ -88,9 +104,16 @@
# lambda { error 'ze test' }.should show_error(/ze test/)
def show_error(message)
MessageWithSeverityMatcher.new :error, message
end
+ # Test if any message was shown (puts). You can use a string or regular expression.
+ #
+ # For example:
+ # lambda { puts 'ze test' }.should show(/ze test/)
+ def show(message)
+ MessageWithSeverityMatcher.new :puts, message
+ end
class ::Rake::Task
alias :execute_without_a_record :execute
def execute(args)
$executed ||= []