Module: Slack::Mixins::Object
- Defined in:
- lib/slack.rb
Instance Method Summary collapse
-
#check(&check) ⇒ Object
This method creates a new ‘Speck::Check` utilizing a passed block.
Instance Method Details
#check(&check) ⇒ Object
This method creates a new ‘Speck::Check` utilizing a passed block.
It expects a block (returning ‘true` or `false`) to be passed. The block will be passed the receiver, so you can run comparators on it, or whatever else you like.
The intention is that this method be used to quickly check that particular methods return values as expected. For instance, the following would be used to check that MyClass#initialize properly assigns its argument to the ‘thingie` attribute:
MyClass.new(an_object).check {|my| my.thingie == an_object }
The new ‘Check` instance is automatically documented with the contents of the line of Ruby that produced the receiver of this method. – TODO: Speck Object#check TODO: Remove the `->self` functionality, and implement Mixins::Truthy
for TrueClass/FalseClass/NilClass
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/slack.rb', line 33 def check &check check = ->(_){self} unless block_given? # TODO: Should we allow specks in the root environment? Could be useful # for quick checks… raise Exception::NoEnvironment unless Speck.current # TODO: Implement documenting the `Check` using a preceding comment, # if present. # TODO: Move this into its own methods deeper in the library, and # clean it up. file, line, _ = Kernel::caller.first.split(':') source = File.open(file).readlines[line.to_i - 1] source.strip! source = source.partition(".check").first # TODO: Get rid of the "(…)" around the resulting string. # TODO: Implement multi–line source documenting. Speck::Check.new(->(){ check[self] }, source) .tap {|check| Speck.current.checks << check } end |