Each `describe` / `context` creates a class, each test is an instance. You can create (with your own DSL) a module thats mixed into the class to provide the functionality you want.
I’d be creating each additional hook as a non memoized method, then having a `propcheck` or similar DSL which is invoked with test that calls these methods each time the block is invoked. Apologies for the delayed response, under a pile of mail atm! Cheers Jon Rowe --------------------------- [email protected] jonrowe.co.uk On 30 June 2019 at 09:11, Wiebe-Marten Wijnja wrote: > All right, I am currently considering an alternate approach, in which someone > can > > > Rspec.describe MyFancyStuff do > > ... > > # In any (nested or not) ExampleGroup: > > require 'prop_check/rspec' > > extend PropCheck::RSpec > > ... > end > > to bring not only `forall` into scope, but also override > `before/after/around` to handle one extra context, which I have tentatively > called `:each_prop_check_iteration`. > > The thing I am currently struggling with however, is how to correctly keep > track of the blocks that someone wants to add as hooks, and then to call them > correctly from within an example context > > (Or, to be precise: From within a block within an `it "description" do ... > end`) > At first I attempted adding instance methods, which did not work because each > example runs its own instance. > Then I attempted working with class-methods on the ExampleGroup, which did > not work because by default when an example runs it prevents methods that are > not part of the `ExampleGroup` class itself from being run, raising a > WrongScopeError (see e.g. > github.com/rspec/rspec-core/blob/2a62a644b52536d44a7969b5c5b69077a35687ca/lib/rspec/core/example_group.rb#L730 > > (https://github.com/rspec/rspec-core/blob/2a62a644b52536d44a7969b5c5b69077a35687ca/lib/rspec/core/example_group.rb#L730)). > > Then I tried adding it to the `metadata`, but you do not have access to it > from within a running example unless you have full control over the block > that `it` is being called with (the only way to access the example's metadata > is if you specify a parameter to the block you pass to `it`). > > > What would be the way to accomplish this? > > > On Saturday, June 29, 2019 at 3:23:08 PM UTC+2, Jon Rowe wrote: -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/rspec/dejalu-217-a5565581-0c8c-4723-abca-e288ac639b4c%40jonrowe.co.uk.
