Class: RSpecConsole::RSpecState

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-console/rspec_state.rb

Class Method Summary collapse

Class Method Details

.config_cacheObject



39
40
41
# File 'lib/rspec-console/rspec_state.rb', line 39

def config_cache
  @config_cache ||= RSpecConsole::ConfigCache.new
end

.obsolete_rspec?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/rspec-console/rspec_state.rb', line 43

def obsolete_rspec?
  Gem.loaded_specs['rspec-core'].version < Gem::Version.new('2.10.0')
end

.resetObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rspec-console/rspec_state.rb', line 4

def reset
  require 'rspec/core'
  raise 'Please use RSpec 2.10.0 or later' if obsolete_rspec?

  ::RSpec::Core::Configuration.class_eval { define_method(:command) { 'rspec' } }
  ::RSpec::Core::Runner.disable_autorun!
  ::RSpec.reset

  if config_cache.has_recorded_config?
    config_cache.replay_configuration
  else
    config_cache.record_configuration(&rspec_configuration)
  end
end

.rspec_configurationObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rspec-console/rspec_state.rb', line 19

def rspec_configuration
  proc do
    ::RSpec.configure do |config|
      config.color_enabled = true if config.respond_to?(:color_enabled=)
      config.color         = true if config.respond_to?(:color=)
    end

    $LOAD_PATH << './spec'
    try_load('spec_helper')
    try_load('rails_helper')
  end
end

.try_load(file) ⇒ Object



32
33
34
35
36
37
# File 'lib/rspec-console/rspec_state.rb', line 32

def try_load(file)
  begin
    require file
  rescue LoadError
  end
end