lib/rspec_candy/switcher.rb in rspec_candy-0.3.1 vs lib/rspec_candy/switcher.rb in rspec_candy-0.4.0

- old
+ new

@@ -1,36 +1,48 @@ module RSpecCandy module Switcher extend self + # def rspec_version + # if defined?(RSpec::Core) + # :rspec2 + # elsif defined?(Spec) + # :rspec1 + # else + # raise 'Cannot determine RSpec version' + # end + # end + def rspec_version - if defined?(RSpec::Core) - :rspec2 - elsif defined?(Spec) - :rspec1 + if defined?(Spec) + 1 else - raise 'Cannot determine RSpec version' + require 'rspec/version' + RSpec::Version::STRING.to_i end end - def rails_version - if Rails.version.to_i < 3 - :rails2 - else - :rails3 - end + def active_record_version + ActiveRecord::VERSION::MAJOR end - def rails_loaded? - defined?(Rails) + def active_record_loaded? + defined?(ActiveRecord) end def new_mock(*args) - rspec_root.const_get(:Mocks).const_get(:Mock).new(*args) + case rspec_version + when 1 + Spec::Mocks::Mock.new(*args) + when 2 + RSpec::Mocks::Mock.new(*args) + else + RSpec::Mocks::Double.new(*args) + end end def rspec_root - if rspec_version == :rspec1 + if rspec_version == 1 Spec else RSpec end end