Sha256: 5b80600ccbbd6fece09f4de7eb7903053a19d8c84cc070d5faa893a01e0f7d1f
Contents?: true
Size: 1.58 KB
Versions: 1
Compression:
Stored size: 1.58 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. == 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ae-1.1.0 | demo/05_expect.qed |