Skip to content

Instantly share code, notes, and snippets.

@uzyexe
Created November 25, 2016 12:32
Show Gist options
  • Save uzyexe/e4eb80fc1ac577cb1bea7e7b7621f751 to your computer and use it in GitHub Desktop.
Save uzyexe/e4eb80fc1ac577cb1bea7e7b7621f751 to your computer and use it in GitHub Desktop.
ServerSpec Rakefile sample
require 'rake'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
desc 'Run all tests on CircleCI'
task circleci: [:style]
desc 'Run all style checks'
task style: 'style:ruby'
desc 'Install rubygems'
task :bundle do
sh 'gem install bundler'
sh 'bundle --path vendor/bundle --binstubs .bundle/bin'
end
desc 'Install rubygems and third-paty Chef cookbooks'
task init: [:bundle]
desc 'Run serverspec to all hosts'
task serverspec: 'serverspec:all'
namespace :serverspec do
targets = []
Dir.glob('./spec/*').each do |dir|
next unless File.directory?(dir)
target = File.basename(dir)
target = "_#{target}" if target == "default"
targets << target
end
task :all => targets
task :default => :all
targets.each do |target|
original_target = target == "_default" ? target[1..-1] : target
desc "Run serverspec tests to #{original_target}"
RSpec::Core::RakeTask.new(target.to_sym) do |t|
ENV['TARGET_HOST'] = original_target
t.pattern = "spec/#{original_target}/*_spec.rb"
end
end
end
namespace :style do
desc 'Run Ruby style checks'
RuboCop::RakeTask.new(:ruby) do |t|
t.patterns = %w(
Rakefile
spec
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment