Closed shdblowers closed 6 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
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.
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?
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 😄
Yes, we're lacking better documentation actually. Perhaps we should consider making a github site and write out some good documentation.
Hi @mgwidmann, sorry for taking so long. Yes, this is the feature I was looking for.
So, I think this issue now becomes this:
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
There is no need for a custom directory for global features, as you can define test file with global steps where ever you want (as long as it is in compile path). For reference please see current test case (for now).
improved documentation will fallow
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.