Hello,

I'm looking to write a library that adds property-based testing to RSpec,
in the style of QuickCheck[1].

The particular difficulties of this integration is that there there are a
number of repeated tests, these tests being generated or cut short on the
fly, as opposed to being all being generated in advance.

For example, when testing that a sorting function works correctly (eg.
[3,1,2].my_sort == [1,2,3]), I'd generate 100 tests with different arrays
of items in ever-increasing sizes. If one of the tests were to fail, I'd
want to stop running further tests, and then swap over to a separate
"shrinking" phase where I generate further tests with the failing output
until I can get the smallest input I can generate to fail the example.

The test runs could look like (each line being an input, and an output of a
test run with its result):

  Initial run (up to 100 attempts):
  [] == [], Passed
  [1] == [1], Passed
  [2,1] == [1,2], Passed
  [2,1,9,4,5,5,6,7] == [1,2,4,5,6,7,9], Failed! Stopping here; no further
data generation to be done.

  Shrinking failed value...
  [2,1,9,4,5,5,6] == [1,2,4,5,6,9], Failed
  [2,1,9,4,5,5] == [1,2,4,5,9], Failed
  [2,1,9,4,5] == [1,2,4,5,9], Passed

  Failed, with smallest known failing value: [2,1,9,4,5,5]

To do the above with RSpec means being able to, in either an around() block
or in an example itself, add further examples to an example group to run,
on the fly. This doesn't appear to be possible. Even directly monkeying
with an example.example_group.examples list is already too late; nothing
picks up the change.

I've had the suggestion of having the ExampleGroup examples be an iterator
instead of a plain list. Would I be on the right track there, or does
anyone have any other suggestions?

(I'm particularly interested in an RSpec integration so as to take
advantage of the existing test integrations people have, eg. database
resets for ActiveRecord models, Capybara Rack-based tests, etc. There are
other Quickcheck ports/adaptations (eg. Rantly[2], Rubycheck[3],
Queencheck[4]), yet none of them have this RSpec lifecycle integration; the
only thing that *does* is Generative[5], which just replicates single
examples a certain number of times, with none of the early-stop or
shrinking smarts that I'm trying to implement.)

Thanks,
Rob

1. https://www.fpcomplete.com/user/pbv/an-introduction-to-quickcheck-testing
2. https://github.com/hayeah/rantly
3. https://github.com/mcandre/rubycheck
4. https://github.com/rosylilly/QueenCheck
5. https://github.com/justincampbell/generative

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/CALx9tg3ixVUQOrnu6yCdpr1TSWQhNRW_ohOJn8p0X0LCPNCE0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to