scope(groups: %w(specs))

directories %w(spec lib config features man)

watch ("config/Guardfile") { UI.info "Exiting guard because config changed"; exit 0 }

group :specs, halt_on_fail: true do
  guard :rspec, cmd: "bundle exec rspec", failed_mode: :keep do
    require "guard/rspec/dsl"
    dsl = Guard::RSpec::Dsl.new(self)

    # Feel free to open issues for suggestions and improvements

    # RSpec files
    rspec = dsl.rspec
    watch(rspec.spec_helper) { rspec.spec_dir }
    watch(rspec.spec_support) { rspec.spec_dir }
    watch(rspec.spec_files)

    # Ruby files
    ruby = dsl.ruby
    dsl.watch_spec_files_for(ruby.lib_files)

    #  watch("lib/guard/notifier.rb")           { "spec/guard/notifiers" }
    #  watch("lib/guard/interactor.rb")         { "spec/guard/commands" }
    #  watch(%r{^lib/guard/(guard|plugin).rb$}) { "spec/guard/plugin" }
  end

  guard :rubocop, all_on_start: false, cli: "--rails -c .rubocop.yml" do
    watch(%r{.+\.rb$}) { |m| m[0] }
    watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
  end

  guard "cucumber", keep_failed: true, all_on_start: false, cmd_additional_args: '--profile guard' do
    watch(%r{^features/.+\.feature$})
    watch(%r{^features/support/.+$})          { "features" }
    watch(%r{^features/step_definitions/(.+)_steps\.rb$}) do |m|
      Dir[File.join("**/#{m[1]}.feature")][0] || "features"
    end
  end
end

if !defined?(JRUBY_VERSION)
  if ENV["CI"] != "true"
    group :docs do
      guard :ronn do
        watch(%r{^man/.+\.ronn?$})
      end
    end
  end
end
