spec/spec_helper.rb in itrigga-net_helper-0.2.0 vs spec/spec_helper.rb in itrigga-net_helper-0.3.0
- old
+ new
@@ -1,23 +1,61 @@
-require 'rubygems'
-require 'bundler'
-begin
- Bundler.setup(:default, :development)
-rescue Bundler::BundlerError => e
- $stderr.puts e.message
- $stderr.puts "Run `bundle install` to install missing gems"
- exit e.status_code
-end
-require 'test/unit'
-require 'rspec'
+# require 'rubygems'
+# require 'bundler'
+# begin
+# Bundler.setup(:default, :development)
+# rescue Bundler::BundlerError => e
+# $stderr.puts e.message
+# $stderr.puts "Run `bundle install` to install missing gems"
+# exit e.status_code
+# end
+# require 'test/unit'
+# require 'rspec'
+#
+# $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+# $LOAD_PATH.unshift(File.dirname(__FILE__))
+#
+# require 'itrigga/core_ext'
+# require 'itrigga/net_helper'
+#
+# Dir.chdir(File.join(File.dirname(__FILE__), '..'))
+#
+# RSpec.configure do |config|
+# # some (optional) config here
+# end
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
+RAILS_ENV = "test"
-require 'itrigga/core_ext'
require 'itrigga/net_helper'
-Dir.chdir(File.join(File.dirname(__FILE__), '..'))
+# Requires supporting files with custom matchers and macros, etc,
+# in ./support/ and its subdirectories.
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
-RSpec.configure do |config|
- # some (optional) config here
-end
\ No newline at end of file
+
+# taken from http://digitaldumptruck.jotabout.com/?p=551
+# allows dynamic re-definition of constants, returning them to previous state after the test
+# also kills those pesky warnings about 'Constant XXX already defined'
+def with_constants(constants, &block)
+ saved_constants = {}
+ constants.each do |constant, val|
+ saved_constants[ constant ] = Object.const_get( constant )
+ Kernel::silence_warnings { Object.const_set( constant, val ) }
+ end
+
+ begin
+ block.call
+ ensure
+ constants.each do |constant, val|
+ Kernel::silence_warnings { Object.const_set( constant, saved_constants[ constant ] ) }
+ end
+ end
+end
+
+# taken from activesupport/lib/active_support/core_ext/kernel/reporting.rb
+def silence_warnings
+ old_verbose, $VERBOSE = $VERBOSE, nil
+ yield
+ ensure
+ $VERBOSE = old_verbose
+end