antonmi / espec

Elixir Behaviour Driven Development
Other
808 stars 62 forks source link

mix espec.init doesn't work in umbrella apps #307

Open alec-c4 opened 1 year ago

alec-c4 commented 1 year ago

Hi! I'm trying to start using espec in umbrella application. Because of there are no information in README, i've just done the following steps

1 - added espec to the deps section in main app, added preferred_cli_env 2 - added espec to the every mix.esx in apps folder

when I use mix espec.init in any app folder i see following message

** (Mix) The task "espec.init" could not be found

What's wrong? May I ask you to add in README file information how to use espec in umbrella apps?

antonmi commented 1 year ago

Hey @alec-c4 ! Please use specify the "test" env for the task MIX_ENV=test mix espec.init The task just creates the "spec_helper.exs" file.

ESpec.configure fn(config) ->
  config.before fn(tags) ->
    {:shared, hello: :world, tags: tags}
  end

  config.finally fn(_shared) ->
    :ok
  end
end

You need to run the task in each app in umbrella. Since all the apps need the file

alec-c4 commented 1 year ago

Yay! It works! Thanks a lot! May I ask you to update README with information how to use espec in umbrella apps? And one more question 'bout code organization - should I create espec-related stuff in every project or is it better to place spec-files in root or umbrella application?

alec-c4 commented 1 year ago

I've added espec for every app in apps directory, then created alias in umbrella's mix'exs

  defp aliases do
    [
      # run `mix setup` in all child apps
      setup: ["cmd mix setup"],
      lint: ["credo", "dialyzer"],
      test: ["cmd mix test", "cmd mix espec"]
    ]
  end

but i'm not sure that it is the best test running strategy

antonmi commented 1 year ago

It's better to have separate specs for each umbrella app