stackbuilders / hspec-golden

Golden tests with Hspec
MIT License
26 stars 8 forks source link

Using arbitrary values to generate the golden files #14

Open CristhianMotoche opened 4 years ago

CristhianMotoche commented 4 years ago

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.