Sha256: b30fe04f98b0c3b226243080f4cdca1556b2b490718d14a61c81ed9725fe6ab9

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

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?(Spec)
        1
      else
        require 'rspec/version'
        RSpec::Version::STRING.to_i
      end
    end

    def active_record_version
      ActiveRecord::VERSION::MAJOR
    end

    def active_record_loaded?
      defined?(ActiveRecord)
    end

    def new_mock(*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 == 1
        Spec
      else
        RSpec
      end
    end

    def rspec_matcher_registry
      rspec_root.const_get(:Matchers)
    end

    def define_matcher(*args, &block)
      rspec_matcher_registry.define(*args, &block)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec_candy-0.4.0 lib/rspec_candy/switcher.rb