require "rubocop/rake_task"
require_relative "support/run"

namespace :cucumber do
  desc "Run the suite without @wip'd scenarios"
  task :all do
    run = Support::Run.new
    run.options = %w(
      --strict
      --format json --expand --out logs/cucumber.json
      --tags ~@wip
    )
    run.execute

    raise "[rake] cucumber failed!" unless run.passed?
    puts "[rake] cucumber passed!"
  end

  desc "Evaluate features without executing"
  task :dry_run do
    run = Support::Run.new
    run.options = %w(
      --dry-run
      --strict
      --format progress
      --tags ~@wip
    )
    run.execute

    raise "[rake] cucumber failed!" unless run.passed?
    puts "[rake] cucumber passed!"
  end

  desc "Check for linting style errors with Rubocop"
  RuboCop::RakeTask.new(:rubocop) do |task|
    # Abort rake on failure
    task.fail_on_error = true
  end

  desc "Run PR tests and linters"
  task pr: [:dry_run, :rubocop]
end

namespace :ci do
  desc "Setup CI workspace"
  task :init do
    rm_rf "logs"
    mkdir_p "logs"
  end

  desc "Run entire suite on Jenkins"
  task all: [:init, "cucumber:all"]

  desc "Run PR tests and linters on Jenkins"
  task pr: "cucumber:pr"
end
