Sha256: 851f5f591f2be9bd7126834e04df04e3e4a7e0ce467e8ddb366682b88ba536dc

Contents?: true

Size: 1.84 KB

Versions: 8

Compression:

Stored size: 1.84 KB

Contents

require 'rspec/core'
require 'autotest/rspec2'

Dir['./spec/support/**/*.rb'].map {|f| require f}

class NullObject
  def method_missing(method, *args, &block)
    # ignore
  end
end

def sandboxed(&block)
  begin
    @orig_config = RSpec.configuration
    @orig_world  = RSpec.world
    new_config = RSpec::Core::Configuration.new
    new_config.include(RSpec::Matchers)
    new_world  = RSpec::Core::World.new(new_config)
    RSpec.instance_variable_set(:@configuration, new_config)
    RSpec.instance_variable_set(:@world, new_world)
    object = Object.new
    object.extend(RSpec::Core::ObjectExtensions)
    object.extend(RSpec::Core::SharedExampleGroup)

    (class << RSpec::Core::ExampleGroup; self; end).class_eval do
      alias_method :orig_run, :run
      def run(reporter=nil)
        @orig_mock_space = RSpec::Mocks::space
        RSpec::Mocks::space = RSpec::Mocks::Space.new
        orig_run(reporter || NullObject.new)
      ensure
        RSpec::Mocks::space = @orig_mock_space
      end
    end

    object.instance_eval(&block)
  ensure
    (class << RSpec::Core::ExampleGroup; self; end).class_eval do
      remove_method :run
      alias_method :run, :orig_run
      remove_method :orig_run
    end

    RSpec.instance_variable_set(:@configuration, @orig_config)
    RSpec.instance_variable_set(:@world, @orig_world)
  end
end

def in_editor?
  ENV.has_key?('TM_MODE') || ENV.has_key?('EMACS') || ENV.has_key?('VIM')
end

RSpec.configure do |c|
  c.color_enabled = !in_editor?
  c.filter_run :focused => true
  c.run_all_when_everything_filtered = true
  c.filter_run_excluding :ruby => lambda {|version|
    case version.to_s
    when "!jruby"
      RUBY_ENGINE != "jruby"
    when /^> (.*)/
      !(RUBY_VERSION.to_s > $1)
    else
      !(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
    end
  }
  c.around do |example|
    sandboxed { example.run }
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
vim-jar-0.1.2.0001 bundler/ruby/1.8/gems/rspec-core-2.1.0/spec/spec_helper.rb
vim-jar-0.1.2 bundler/ruby/1.8/gems/rspec-core-2.1.0/spec/spec_helper.rb
vim-jar-0.1.1 bundler/ruby/1.8/gems/rspec-core-2.1.0/spec/spec_helper.rb
vim-jar-0.1.0 bundler/ruby/1.8/gems/rspec-core-2.1.0/spec/spec_helper.rb
vim-jar-0.0.3 bundler/ruby/1.8/gems/rspec-core-2.1.0/spec/spec_helper.rb
vim-jar-0.0.2 bundler/ruby/1.8/gems/rspec-core-2.1.0/spec/spec_helper.rb
vim-jar-0.0.1 bundler/ruby/1.8/gems/rspec-core-2.1.0/spec/spec_helper.rb
rspec-core-2.1.0 spec/spec_helper.rb