stackbuilders / hspec-golden

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

Look up for a way to get the information from the test description to name the snapshot #43

Closed CristhianMotoche closed 1 year ago

CristhianMotoche commented 1 year ago

In order to stop requesting the users for a name for the golden files, it would be great to get that information from the test itself. I already requested some information about it in the hspec repository. My goal is to make the golden test need less config and maybe at some point have more cool features related to snapshot testing like the ones from Jest.

sol commented 1 year ago

In order to stop requesting the users for a name for the golden files, it would be great to get that information from the test itself. I already requested some information about it in the hspec repository. My goal is to make the golden test need less config and maybe at some point have more cool features related to snapshot testing like the ones from Jest.

I think this can be implemented without any changes to Hspec. Try something along the lines of:

golden :: String -> IO String -> Spec
golden description action = do
  path <- (++ [description]) <$> getSpecDescriptionPath
  it description $ do
    action >>= defaultGolden (intercalate '-' path)
CristhianMotoche commented 1 year ago

Indeed, that seems like a very easy approach. Thanks a lot @sol !