Search code examples
ruby-on-railscucumberguard

Guardfile for running single cucumber feature in subdirectory?


I have my features organized in subfolders, like this:

app/
  features/
     users/
       feature1.feature
       feature2.feature

But everytime I save a feature, Guard runs all my features (not just the one that was edited). How can I change it to only run the one that was saved?

Here's my Guardfile for Cucumber:

guard 'cucumber', :cli => "--drb --require features/support --require features/step_definitions" do
  watch(%r{features/.+\.feature})
  watch(%r{features/support/.+})          { 'features' }
  watch(%r{features/step_definitions/(.+)_steps\.rb}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
end

Solution

  • Aph, the answer was right there in the documentation:

    It's very important that you understand how Cucumber gets configured, because it's often the origin of strange behavior of guard-cucumber.

    Cucumber uses cucumber.yml for defining profiles of specific run configurations. When you pass configurations through the :cli option but don't include a specific profile with --profile, then the configurations from the default profile are also used.

    For example, when you're using the default cucumber.yml generated by cucumber-rails, then the default profile forces guard-cucumber to always run all features, because it appends the features folder.

    Configure Cucumber solely from Guard

    If you want to configure Cucumber from Guard solely, then you should pass --no-profile to the :cli option.

    So, passing in --no-profile for the :cli option works now, and I'm getting normal behavior.

    Shame on me for not reading the docs!