module Scorpion::Rspec::Helper::Methods

Public Instance Methods

capture( name, contract ) click to toggle source

Captures an instance of the given `contract` and assigns it to `name` and return the same instance when the scorpion resovles any instance of the contract. @param [Symbol] name of the rspec method to assign. @param [Module] contract to hunt for.

# File lib/scorpion/rspec/helper.rb, line 74
def capture( name, contract )
  hunt( name, contract ) do
    scorpion.new contract
  end
end
capture!( name, contract ) click to toggle source

Captures an instance of the given `contract` and assigns it to `name` and return the same instance when the scorpion resovles any instance of the contract. @param [Symbol] name of the rspec method to assign. @param [Module] contract to hunt for.

# File lib/scorpion/rspec/helper.rb, line 85
def capture!( name, contract )
  hunt!( name, contract ) do
    scorpion.new contract
  end
end
hunt( name, contract, value = :unspecified, &block ) click to toggle source

Specify a specific hunting contract and prepare a `let` block of the same name.

# File lib/scorpion/rspec/helper.rb, line 46
def hunt( name, contract, value = :unspecified, &block )
  block ||= -> { value == :unspecified ? instance_double( contract ) : value }

  let( name, &block )

  before( :each ) do
    scorpion.prepare do |hunter|
      if value == :unspecified
        hunter.hunt_for contract do
          send( name )
        end
      else
        hunter.hunt_for contract, return: value
      end
    end
  end
end
hunt!( name, contract, value = :unspecified, &block ) click to toggle source
# File lib/scorpion/rspec/helper.rb, line 64
def hunt!( name, contract, value = :unspecified, &block )
  hunt name, contract, value, &block
  before(:each) { send name }
end
infest_nest( klass ) click to toggle source

Intercept calls to conceive_scorpion in classes that include {Scorpion::Rails::Nest} @param [Class] klass that includes {Scorpion::Rails::Nest} @return [void]

# File lib/scorpion/rspec/helper.rb, line 24
def infest_nest( klass )
  return unless klass < Scorpion::Rails::Nest

  before( :each ) do
    allow_any_instance_of( klass ).to receive( :conceive_scorpion )
      .and_wrap_original do |m|
        # When hunting for dependencies in controllers, jobs, etc. first
        # consider the dependencies defined in the specs.
        Scorpion::ChainHunter.new( scorpion, m.call )
      end
  end
end
scorpion( &block ) click to toggle source

Set up scorpion hunting rules for the spec.

# File lib/scorpion/rspec/helper.rb, line 38
def scorpion( &block )
  before( :each ) do
    scorpion.prepare &block
  end
end