DefactoSoftware / test_selector

Elixir library to help selecting the right elements in your tests.
MIT License
14 stars 2 forks source link

Option to disable output for all test helpers (e.g. in production) #17

Open sn3p opened 6 years ago

sn3p commented 6 years ago

This way we can output/use the helpers in development and test environments, but hide them in production.

Thoughts on this?

jessedijkstra commented 6 years ago

You mean to not show the test helpers in the code when running in production?

If that is so, it could easily be achieved because we're already using a macro to initialize the test helper.

This is not real code:

use TestSelector.HTML.Helpers(enable: !ENV["production"])
def test_selector when !options[:enable], do: ""

def test_selector when options[:enable] do
        __MODULE__
        |> Module.split()
        |> List.last()
        |> (&List.insert_at([], 0, &1)).()
        |> Enum.join("-")
        |> String.trim_trailing("View")
        |> String.trim_trailing("Cell")
        |> String.downcase()
        |> Kernel.<>("-#{test_selector_hash()}")
end
sn3p commented 6 years ago

You mean to not show the test helpers in the code when running in production?

Yes exactly that :)

It could easily be achieved because we're already using a macro to initialize the test helper.

Sounds good, will give that a shot soon.

jessedijkstra commented 6 years ago

@sn3p gotta work that macro magic though 🐰 so unwrap the options variables etc. See how ex_cell uses the opts variable: https://github.com/DefactoSoftware/ex_cell/blob/master/lib/ex_cell/base.ex