Module: AwesomeSpawn::SpecHelper

Defined in:
lib/awesome_spawn/spec_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.disable_spawning(config, file_path: nil) ⇒ Object

Disable spawning for specs

Examples:

Disable spawning for all specs

RSpec.configure do |config|
  AwesomeSpawn::SpecHelper.disable_spawning(config)
end

Disable spawning for specs in a specific path

RSpec.configure do |config|
  AwesomeSpawn::SpecHelper.disable_spawning(config, file_path: "spec/models")
end

Parameters:

  • config (RSpec::Core::Configuration)

    RSpec configuration

  • file_path (String) (defaults to: nil)

    Restrict the disabling to a specific set of specs in the given path



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/awesome_spawn/spec_helper.rb', line 19

def self.disable_spawning(config, file_path: nil)
  if file_path
    config.(:file_path => file_path) do ||
      [:uses_awesome_spawn] = true
    end
    config.include AwesomeSpawn::SpecHelper, :uses_awesome_spawn => true
    config.before(:each, :uses_awesome_spawn) { disable_spawning }
  else
    config.include AwesomeSpawn::SpecHelper
    config.before { disable_spawning }
  end
  config
end

Instance Method Details

#disable_spawningObject



33
34
35
36
# File 'lib/awesome_spawn/spec_helper.rb', line 33

def disable_spawning
  allow(Open3).to receive(:capture3)
    .and_raise("Spawning is not permitted in specs.  Please change your spec to use expectations/stubs.")
end

#enable_spawningObject



38
39
40
# File 'lib/awesome_spawn/spec_helper.rb', line 38

def enable_spawning
  allow(Open3).to receive(:capture3).and_call_original
end

#stub_bad_run(command, options = {}) ⇒ Object



46
47
48
# File 'lib/awesome_spawn/spec_helper.rb', line 46

def stub_bad_run(command, options = {})
  stub_run(:bad, :run, command, options)
end

#stub_bad_run!(command, options = {}) ⇒ Object



54
55
56
# File 'lib/awesome_spawn/spec_helper.rb', line 54

def stub_bad_run!(command, options = {})
  stub_run(:bad, :run!, command, options)
end

#stub_good_run(command, options = {}) ⇒ Object



42
43
44
# File 'lib/awesome_spawn/spec_helper.rb', line 42

def stub_good_run(command, options = {})
  stub_run(:good, :run, command, options)
end

#stub_good_run!(command, options = {}) ⇒ Object



50
51
52
# File 'lib/awesome_spawn/spec_helper.rb', line 50

def stub_good_run!(command, options = {})
  stub_run(:good, :run!, command, options)
end