Module: RSpec::SleepingKingStudios::Contract
- Defined in:
- lib/rspec/sleeping_king_studios/contract.rb
Overview
A Contract wraps RSpec functionality for sharing and reusability.
An RSpec::SleepingKingStudios::Contract integrates with the .include_contract class method to share and reuse RSpec examples and configuration. The major advantage a Contract object provides over using a Proc is documentation - tools such as YARD do not gracefully handle bare lambdas, while the functionality and requirements of a Contract can be specified using standard patterns, such as documenting the parameters passed to a contract using the #apply method.
Instance Method Summary collapse
-
#apply(example_group, *arguments, **keywords) { ... } ⇒ Object
Adds the contract to the given example group.
- #contract(&block) ⇒ Object
-
#to_proc ⇒ Proc?
The contract implementation for the class.
Instance Method Details
#apply(example_group, *arguments, **keywords) { ... } ⇒ Object
Adds the contract to the given example group.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/rspec/sleeping_king_studios/contract.rb', line 118 def apply(example_group, *arguments, **keywords, &block) concern = RSpec::SleepingKingStudios::Concerns::IncludeContract concern.define_contract_method( context: example_group, contract: self, name: tools.str.underscore(name).gsub('::', '_') ) do |method_name| if keywords.empty? example_group.send(method_name, *arguments, &block) else example_group.send(method_name, *arguments, **keywords, &block) end end end |
#contract ⇒ Proc? #contract {|*arguments, **keywords, &block| ... } ⇒ Object
148 149 150 151 152 |
# File 'lib/rspec/sleeping_king_studios/contract.rb', line 148 def contract(&block) return @contract = block if block_given? @contract end |
#to_proc ⇒ Proc?
Returns the contract implementation for the class.
155 156 157 |
# File 'lib/rspec/sleeping_king_studios/contract.rb', line 155 def to_proc @contract end |