module Scorpion::Rspec::Helper::Methods
Public Instance Methods
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
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
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
# 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
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
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