Module: Fsr

Defined in:
lib/fsr.rb,
lib/fsr/version.rb

Overview

Run RSpec fast by avoiding full app boot

“‘rb

listener = Fsr.listen(
  ['spec/controllers/task_controller_spec.rb'],
  load: ['app/controllers/task_controller.rb']
)

listener.start
listener.stop

“‘

Defined Under Namespace

Classes: Runner

Constant Summary collapse

VERSION =
'0.1.6'

Class Method Summary collapse

Class Method Details

.listen(run, load: [], listen: [ "#{`pwd`.strip}/app", "#{`pwd`.strip}/lib", "#{`pwd`.strip}/spec" ].select { |dir| Dir.exist?(dir) }) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fsr.rb', line 21

def self.listen(
  run,
  load: [],
  listen:
    [
      "#{`pwd`.strip}/app",
      "#{`pwd`.strip}/lib",
      "#{`pwd`.strip}/spec"
    ].select { |dir| Dir.exist?(dir) }
)
  Listen.to(*listen) do |modified, added|
    files = [modified, added].compact.flatten if load.empty?
    Fsr::Runner.new(run, load: files).run
  end
end

.sandboxedObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fsr.rb', line 37

def self.sandboxed
  orig_world   = RSpec.world
  orig_example = RSpec.current_example
  RSpec.world  = RSpec::Core::World.new(RSpec.configuration)

  yield
ensure
  RSpec.world           = orig_world
  RSpec.current_example = orig_example
  RSpec.clear_examples
end