Module: Scorpion::Rspec::Helper::Methods
- Defined in:
- lib/scorpion/rspec/helper.rb
Instance Method Summary collapse
-
#capture(name, contract) ⇒ Object
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.
-
#capture!(name, contract) ⇒ Object
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.
-
#hunt(name, contract, value = :unspecified, &block) ⇒ Object
Specify a specific hunting contract and prepare a ‘let` block of the same name.
- #hunt!(name, contract, value = :unspecified, &block) ⇒ Object
-
#infest_nest(klass) ⇒ void
Intercept calls to conceive_scorpion in classes that include Scorpion::Rails::Nest.
-
#scorpion(&block) ⇒ Object
Set up scorpion hunting rules for the spec.
Instance Method Details
#capture(name, contract) ⇒ Object
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.
74 75 76 77 78 |
# File 'lib/scorpion/rspec/helper.rb', line 74 def capture( name, contract ) hunt( name, contract ) do scorpion.new contract end end |
#capture!(name, contract) ⇒ Object
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.
85 86 87 88 89 |
# 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) ⇒ Object
Specify a specific hunting contract and prepare a ‘let` block of the same name.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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) ⇒ Object
64 65 66 67 |
# 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) ⇒ void
This method returns an undefined value.
Intercept calls to conceive_scorpion in classes that include Scorpion::Rails::Nest
24 25 26 27 28 29 30 31 32 33 34 35 |
# 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) ⇒ Object
Set up scorpion hunting rules for the spec.
38 39 40 41 42 |
# File 'lib/scorpion/rspec/helper.rb', line 38 def scorpion( &block ) before( :each ) do scorpion.prepare &block end end |