Sha256: 8a138da1acefbda3885009c0421585bbb6a53845027854e5b33b2b87367fa2c6
Contents?: true
Size: 1.6 KB
Versions: 2
Compression:
Stored size: 1.6 KB
Contents
= Expect Method Expect is another optional assertion nomenclature available for use in your tests or specifications. Inspired by Jay Fields' Expectations library, it provides convenient syntax for creating exception and case equality assertions. require 'ae/expect' == Underlying Comparison Expect uses #=== for comparison. So providing an argument and a block to #expect we can test for a somewhat broader range of compassion than #assert. For example we can test for a subclass. expect Numeric do 3 end Assertion.assert.raised? do expect Numeric do "3" end end == Exception Expectation If the comparator is an Exception class or a instance of an Exception class, then #expect will check to see if the block raises that kind of exception. expect StandardError do some_undefined_method end expect Assertion do expect(nil) end This is an important distinction to note because it means #expect can not be used if verify instances of Exception classes. Assertion.assert.raised? do expect Exception do Exception.new end end == Regex Expectations That #expect entails #=== also means we can check for Regexp matches. expect /x/ do "oooxooo" end == Expected Method We can use #expected to make the receiver the object of expectation. x = "dummy" /x/.expected do "x" end == Function without Block Without a block, the receiver is compared to the argument. x.expect String == Functor, or Higher Order Function Like #assert, #expect can be used used as a *fluid* notation. 10.expect == 10 In which case it works just like #assert.
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ae-1.2.3 | qed/05_expect.rdoc |
ae-1.2 | test/demos/05_expect.rdoc |