testingisdocumenting/webtau

personas: nesting the same persona should be allowed

Closed this issue · 7 comments

I think we should allow this:

def john = Persona('John')

john {
  john {
    http.post(...)
  }
}

Obviously nesting that explicitly is pointless. However, some utility functions could well operate in the context of an explicit persona and their calls wrap calls to that function with the same persona for double checking and making things more obvious.

Happy to discuss this here prior to implementing though :)

it may help to see an example of where you think it is useful

Assume A is a persona then something like this:

def testResource = createLazyResource("a resource") {
  A {
    def id = http.post(...) {
      blah.should == foo
      return id
    }
    return Resource(id)
  }
}

scenario("...") {
  A {
    def testId = testResource.id
    http.get(testId)
  }
}

Typically the contents of the createResource call might be in a different file so it's useful to wrap any access to it/the resource in the persona you'd expect them to be under, just to make it super obvious. It'll also then fail with a very obvious error message if the helper is using a different persona.

Struggling to create a better/more realistic example without having to reveal lots of details of our real test :)

As it is, in such situations, I have to always put the def testId = testResource.id outside the persona block.

Right. I think I don’t see a good workaround by using lazy resource. Lazy resource becomes restricted in your example and always requires be used within that specific persona scope.

The only workaround I can suggest is to start explicitly creating a resource in the dedicated scenario and then save created if to cache using
def createdId = cache.value(“myId”) and call set get.

The main rationale behind cache is to be able to run a scenario without rerunning the create scenario during development or debugging of a test or an app. The value will be picked up from a disk on rerun from REPL or IDE

I'm not looking for a workaround, the code I have (with the testResource.id outside the persona block) works fine. But I'd like to just have it in the block and hence the ability to activate the currently active persona.

Maybe an analogy will help. If persona was a lock, I'm just looking to make it reentrant :)

Ha. I was actually writing that it looks like a reentrant lock :) ok go for it