require 'rubygems'

begin
  require 'cucumber'
  require 'cucumber/rake/task'
  testsuite_name = ENV['TESTSUITE']
  testcase_report_name = ENV['TESTCASE_REPORT_NAME']
  report_path = "Reports/#{testsuite_name}"
  local_opts = [ "--color", "--no-source","CONFIG_NAME=local"]
  server_opts = [ "--color", "--no-source","CONFIG_NAME=server"]
  junit_opts = ["--format junit", "--out #{report_path}", "--format json --out #{report_path}/#{testcase_report_name}.json"]
  namespace :ITMS_DEBUG do
    Cucumber::Rake::Task.new(:local, "Debug on local environment") do |t|
      t.cucumber_opts = [*local_opts, "ITMS_DEBUG=true"]
    end
    Cucumber::Rake::Task.new(:server, "Debug on cloud browser") do |t|
      t.cucumber_opts = [*server_opts, "ITMS_DEBUG=true"]
    end
  end
  namespace :EXECUTE do
    Cucumber::Rake::Task.new(:local, "Execute on local environment") do |t|
      t.cucumber_opts = [*local_opts, *junit_opts, "EXECUTE=true"]
    end
    Cucumber::Rake::Task.new(:server, "Execute on cloud browser") do |t|
      t.cucumber_opts = [*server_opts, *junit_opts, "EXECUTE=true"]
    end
  end
rescue LoadError
  desc 'Cucumber rake task not available'
  task :features do
    abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
  end
end
