betamaxteam / betamax

Betamax is a tool for mocking external HTTP resources such as web services and REST APIs in your tests. The project was inspired by the VCR library for Ruby.
http://betamax.software
Apache License 2.0
470 stars 131 forks source link

Add Support for Setting Tape Path Per-Integration Test #215

Closed solvingj closed 7 years ago

solvingj commented 8 years ago

In my opinion, a single shared taperoot for all tests seems to pose a few problems. If possible / feasible, I suggest adding an annotation element for tape path that is relative to the taperoot, with an override option. In my use case, I want the tapes organized into a subfolder structure that mimics my package/source structure. If that seems a common enough use case, perhaps that could simply be a global strategy option.

Could anyone comment on how difficult this would be to achieve?

solvingj commented 8 years ago

Well, I didn't think this was possible, but it works. I've added this to my base test class and it apparently resolves to the package name of the derived class. Not nearly as messy as I thought. If someone wants to add similar logic as a native "tape filing strategy", feel free, but this workaround is pretty elegant and works fine for me.

    @Shared
    File tapesBaseDir = new File('src/integTest/resources/betamax/tapes')
    @Shared
    Configuration configuration = Configuration.builder()
        .defaultMode(READ_WRITE)
        .tapeRoot(new File(tapesBaseDir, getClass().package.name.replace('.','/')))
        .sslEnabled(true)
        .build()
    @Rule
    RecorderRule recorder = new RecorderRule(configuration)
cowboygneox commented 7 years ago

Moving this to Trello: https://trello.com/c/ZMJ5U6Xd