<%- assert_locals gem -%> <%- service = gem.services.first -%> <%= render partial: "shared/header" -%> require "bundler/setup" require "bundler/gem_tasks" require "rubocop/rake_task" RuboCop::RakeTask.new require "rake/testtask" desc "Run tests." Rake::TestTask.new do |t| t.libs << "test" t.test_files = FileList["test/**/*_test.rb"] t.warning = false end namespace :test do desc "Runs tests with coverage." task :coverage do require "simplecov" SimpleCov.start do command_name "<%= gem.name %>" track_files "lib/**/*.rb" add_filter "test/" end Rake::Task[:test].invoke end end desc "Runs the smoke tests." Rake::TestTask.new :smoke_test do |t| t.test_files = FileList["acceptance/**/*smoke_test.rb"] t.warning = false end namespace :smoke_test do desc "Runs smoke tests with coverage." task :coverage do require "simplecov" SimpleCov.start do command_name "<%= gem.name %>" track_files "lib/**/*.rb" add_filter "test/" end Rake::Task[:smoke_test].invoke end end # Acceptance tests desc "Run the <%= gem.name %> acceptance tests." task :acceptance, :project, :keyfile do |t, args| <%- if service && !gem.generic_endpoint? -%> project = args[:project] project ||= ENV["<%= gem.env_prefix %>_TEST_PROJECT"] || ENV["GCLOUD_TEST_PROJECT"] keyfile = args[:keyfile] keyfile ||= ENV["<%= gem.env_prefix %>_TEST_KEYFILE"] || ENV["GCLOUD_TEST_KEYFILE"] if keyfile keyfile = File.read keyfile else keyfile ||= ENV["<%= gem.env_prefix %>_TEST_KEYFILE_JSON"] || ENV["GCLOUD_TEST_KEYFILE_JSON"] end if project.nil? || keyfile.nil? fail "You must provide a project and keyfile. e.g. rake acceptance[test123, /path/to/keyfile.json] or <%= gem.env_prefix %>_TEST_PROJECT=test123 <%= gem.env_prefix %>_TEST_KEYFILE=/path/to/keyfile.json rake acceptance" end require "<%= service.credentials_require %>" <%= service.credentials_name_full %>.env_vars.each do |path| ENV[path] = nil end ENV["<%= gem.env_prefix %>_PROJECT"] = project ENV["<%= gem.env_prefix %>_TEST_PROJECT"] = project ENV["<%= gem.env_prefix %>_KEYFILE_JSON"] = keyfile <%- end -%> Rake::Task["acceptance:run"].invoke end namespace :acceptance do task :run do if File.directory? "acceptance" Rake::Task[:smoke_test].invoke else puts "The <%= gem.name %> gem has no acceptance tests." end end desc "Run acceptance tests with coverage." task :coverage do end desc "Run acceptance cleanup." task :cleanup do end end require "yard" require "yard/rake/yardoc_task" YARD::Rake::YardocTask.new do |y| <%- if gem.yard_strict? -%> y.options << "--fail-on-warning" <%- end -%> end desc "Run yard-doctest example tests." task :doctest do puts "The <%= gem.name %> gem does not have doctest tests." end desc "Run the CI build" task :ci do header "BUILDING <%= gem.name %>" header "<%= gem.name %> rubocop", "*" Rake::Task[:rubocop].invoke header "<%= gem.name %> yard", "*" Rake::Task[:yard].invoke header "<%= gem.name %> test", "*" Rake::Task[:test].invoke end namespace :ci do desc "Run the CI build, with smoke tests." task :smoke_test do Rake::Task[:ci].invoke header "<%= gem.name %> smoke_test", "*" Rake::Task[:smoke_test].invoke end desc "Run the CI build, with acceptance tests." task :acceptance do Rake::Task[:ci].invoke header "<%= gem.name %> acceptance", "*" Rake::Task[:acceptance].invoke end task :a do # This is a handy shortcut to save typing Rake::Task["ci:acceptance"].invoke end end task default: :test def header str, token = "#" line_length = str.length + 8 puts "" puts token * line_length puts "#{token * 3} #{str} #{token * 3}" puts token * line_length puts "" end