Remember Using contracts.ruby With RSpec ?
RSpec mocks violate all
:class contracts because
false for mock. That post describes 2 possible solutions:
allow(my_double).to receive(:is_a?).with(MyClass).and_return(true), or
contracts-rspecgem, that patches
Since custom validators have finally landed here:
now you can just override
:class validator to accept all RSpec mocks:
1 2 3 4 5 6 7
Now, RSpec mocks will not violate all the
More information can be found here: Providing your own custom validators.
Additionally this refactoring enabled valuable speed optimization for complex contracts - validators for them will be evaluated only once and memoized.
- Previous part
- contracts.ruby: https://github.com/egonSchiele/contracts.ruby
- contracts.ruby chat: https://gitter.im/egonSchiele/contracts.ruby
- Mentioned PR: https://github.com/egonSchiele/contracts.ruby/pull/159
- Introduction to contracts.ruby
- Great contracts.ruby tutorial
- Full fledged documentation PR: see here staging docs: https://relishapp.com/contracts-staging/contracts-ruby/docs
If you have any questions, suggestions or just want to chat about how contracts.ruby is awesome, you can ping me on twitter @tdd_fellow. If you have any issues using contracts.ruby you can create issues on corresponding github project. Pull requests are welcome!
Comments on hackernews.
Happy coding! @tdd_fellow on twitter.