acquia / drupal-spec-tool

A tool for specifying Drupal architecture details and generating automated tests for them.
GNU General Public License v2.0
149 stars 36 forks source link

Skip unexpected elements #52

Open lems3 opened 3 years ago

lems3 commented 3 years ago

Hi,

We'd like to use the Acquia Spec tool to help us validate that a set of common configuration across multiple of our sites (in our multisites setup) follows our best practice guideline, OR are aligned with what should be expected from those sites so our custom themes works properly.

But, we also want to keep some flexibility on each site so they can have some elements specific to them, usually in the form of content types or medias.

From what I understand from the current status of the spec tool and the behat test, we would get an error if one site have an extra elements that is not part of the test.

We'd like to be able to skip that. Adding the spec tool to every site and for every features does not always have a huge value for us.

Is it currently possible ? Or, how could this could be achieved ?

TravisCarden commented 3 years ago

Hi, @lems3! If I understand correctly, you basically want the ability to test for a common baseline of configuration so that tests fail if that baseline is different but pass if there are just additional items added to it.

First of all, you are correct: the Drupal Spec Tool currently provides no out-of-the-box ability to achieve what you're asking for. However, it can be done--without having to wait for the Drupal Spec Tool to change at all upstream, in fact...

You see, the Behat features of the Spec Tool merely provide "steps" (e.g., "@Then exactly the following fields should exist") that can be mixed and matched like any others. The spreadsheet happens to generate default features for you, but like any framework, you can customize your implementation how you like. In this case, you can create your own steps to achieve your unique functionality. For example, you could create some kind of "@Then at least the following fields should exist" step and use whichever approach (or both) was appropriate for a given site.

I won't say it's easy getting started with Behat--at least that hasn't been my experience. The documentation's not great, in my opinion. But you can look at the Spec Tool for guidance and inspiration (esp. src/Context/ContentModelContext.php). Hopefully that gets you started.

lems3 commented 3 years ago

Hi @TravisCarden,

Exactly!

With the research that we have done up to now, we think that the best approach would be to create a separate module that either extend the current Spec Tool or duplicate code in it. This way, it would be easier to eventually move this feature in the Spec Tool if it's something that would feel like a good element to add to it.

But before going too far in this, we wanted to confirm is our assumptions were right with the current state of the Spec Tool, and if it's something that would make sense.

We will dig into this and circle back here once we get something up.

TravisCarden commented 3 years ago

By the way, @lems3, I just added a little documentation on how to cleanly supplement or override out-of-the-box behavior that may help you: https://github.com/acquia/drupal-spec-tool#customization