Skip to content
This repository was archived by the owner on Apr 20, 2026. It is now read-only.
This repository was archived by the owner on Apr 20, 2026. It is now read-only.

Using arbitrary values to generate the golden files #14

Description

@CristhianMotoche

hspec-golden-aeson uses arbitrary instances to generate the golden files for the aeson instances. I think the main reason is to ensure the property (encode . decode) x == x. However, I think it can be helpful to use some arbitrary value instead setting one manually. For instance:

-- Module.hs
toHTML :: User -> Html
toHTML User{..} = ...

-- ModuleSpec.hs
describe "toHTML" $
   it "generates a golden file for a User" $
       let user = User {..}
         in defaultGolden "toHTML.User" (renderHTML $ toHTML user) 

It would be great to get the user automatically from a random example:

describe "toHTML" $
   it "generates a golden file for a User" $
         defaultGolden "toHTML.User" (renderHTML . toHTML) 

I don't think arbitrary is required for this. faker could be a nice option.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions