spec/spec_helper.rb in rubypython-0.3.2 vs spec/spec_helper.rb in rubypython-0.5.0
- old
+ new
@@ -1,49 +1,65 @@
begin
require 'rspec'
- require 'ffi'
rescue LoadError
require 'rubygems' unless ENV['NO_RUBYGEMS']
- gem 'rspec'
require 'rspec'
- require 'ffi'
end
-$:.unshift(File.dirname(__FILE__) + '/../lib')
+dir = File.dirname(__FILE__)
+
+$:.unshift(File.join(dir, '..', 'lib'))
require 'rubypython'
module TestConstants
- #REDEFINE THESE SO THEY ARE VISIBILE
- AString = "STRING"
- AnInt = 1
- AChar = 'a'
- AFloat = 1.0
- AnArray = [AnInt, AChar, AFloat, AString]
- ASym = :sym
- AHash = {
- AnInt => AnInt,
- AChar.to_sym => AChar,
- ASym => AFloat,
- AString => AString
- }
- AConvertedHash = Hash[*AHash.map do |k, v|
- key = k.is_a?(Symbol)? k.to_s : k
- [key,v]
- end.flatten]
+ AString = "STRING"
+ AStringWithNULLs = "STRING\0WITH\0NULLS"
+ AnInt = 1
+ AChar = 'a'
+ AFloat = 1.0
+ AnArray = [AnInt, AChar, AFloat, AString]
+ ASym = :sym
+ AHash = {
+ AnInt => AnInt,
+ AChar.to_sym => AChar,
+ ASym => AFloat,
+ AString => AString
+ }
+ AConvertedHash = Hash[*AHash.map do |k, v|
+ key = k.is_a?(Symbol) ? k.to_s : k
+ [key, v]
+ end.flatten]
+ AProc = Proc.new { |a1, a2| a1 + a2 }
+ def self.a_method(a1, a2)
+ a1 + a2
+ end
+ AMethod = method(:a_method)
+end
- AProc = Proc.new { |a1, a2| a1 + a2 }
+def run_python_command(cmd)
+ %x(python -c '#{cmd}').chomp
+end
- def self.a_method(a1, a2)
- a1 + a2
+RSpec.configure do |config|
+ if RUBY_VERSION < '1.9.2'
+ config.filter_run_excluding :ruby_version => '1.9'
+ end
+
+ config.before(:all) do
+ class RubyPython::RubyPyProxy
+ [:should, :should_not, :class].each { |m| reveal(m) }
end
+ end
- AMethod = method(:a_method)
+ config.before(:all, :self_start => nil) do
+ RubyPython.start
-end
+ @sys = RubyPython.import 'sys'
+ @sys.path.append File.join(dir, 'python_helpers')
+ @objects = RubyPython.import 'objects'
+ @basics = RubyPython.import 'basics'
+ end
-def run_python_command(cmd)
- IO.popen("python -c '#{cmd}'") { |f| f.gets.chomp}
-end
-
-class RubyPython::RubyPyProxy
- [:should, :should_not, :class].each { |m| reveal(m) }
+ config.after(:all) do
+ RubyPython.stop
+ end
end