cabbage-ex / cabbage

Story BDD tool for executing elixir in ExUnit
MIT License
141 stars 33 forks source link

Feature similar to import steps #24

Closed shdblowers closed 5 years ago

shdblowers commented 7 years ago

Hi Matt,

Using Cabbage today and was thinking it would be nice to sort my scenarios into different modules, akin to how white bread does it with the import_steps_from macro.

Is this something that can be done with Cabbage?

If so, I think that should be put in the readme.

If not, I think that would be a really useful feature to add.

mgwidmann commented 7 years ago

So yeah, the readme could use some better examples... But what is done with the Cabbage.GlobalFeatures module during testing should do something similar I believe. The only downside is you have to put it into the test/support folder so it gets compiled first. If you put all your steps for example into there, you could make almost empty feature modules which just import the shared steps that feature requires...

I'm not sure if thats the question you were asking, so let me know if I missed something

shdblowers commented 7 years ago

Sounds like Cabbage.GlobalFeatures does something similar but not what I was looking for.

I'll give an example. Lots (but not all) of my tests involve asserting certain HTTP status codes are returned from API calls.

What I would like to do is create a HttpStatusCodeTest module that has all the steps I want so I can test HTTP status codes in one place. This module does not have a corresponding feature file.

Then, I will have another module, e.g. RegistrationTest which wants to assert that 201 is returned after a successful registration. What I want to do is to import HttpStatusCodeTest into RegistrationTest so that I can make use of its defined steps.

The problem with Cabbage.GlobalFeatures is the same as defining all your functions on the global namespace, collisions and being able to access those steps from test files you didn't want them in.

mgwidmann commented 7 years ago

The point of Cabbage.GlobalFeatures was to show you how to make exactly what you've described as far as I can tell...

# test/support/http_status_code_features.ex
defmodule MyApp.HttpStatusCodeTest do
  use Cabbage.Feature

  defthen ~r/It returns a status (?<number>\d+)/, _, _ do
    assert 1 = 1 # your check for status codes here
  end
end

# test/features/some_feature.exs
defmodule MyApp.SomeFeature do
  use Cabbage.Feature, file: "some_feature.feature"

  import_feature MyApp.HttpStatusCodeTest

  # Given, when, and, thens specific to this feature
  defgiven ~r/.../, _, _ do
  end
end

What about this doesn't work for what you're trying to do?

shdblowers commented 7 years ago

Ah ok, its much more clearer now with a code example. It looks like what I am looking for, will get back to you after I give it a go 😄

mgwidmann commented 7 years ago

Yes, we're lacking better documentation actually. Perhaps we should consider making a github site and write out some good documentation.

shdblowers commented 7 years ago

Hi @mgwidmann, sorry for taking so long. Yes, this is the feature I was looking for.

So, I think this issue now becomes this:

mgwidmann commented 7 years ago

I've started a project for hosting more in depth documentation, but have yet to fill it in 😆 https://github.com/cabbage-ex/cabbage-ex.github.io

revati commented 5 years ago