Skip to content

Instantly share code, notes, and snippets.

@ajsharma
Last active July 5, 2016 23:35
Show Gist options
  • Save ajsharma/5165123e964162fa278e7a23e59e0af1 to your computer and use it in GitHub Desktop.
Save ajsharma/5165123e964162fa278e7a23e59e0af1 to your computer and use it in GitHub Desktop.
Simple rake script to run failed specs from CircleCi on your computer
group :development do
gem 'circleci', require: false
end
namespace :spec do
desc <<-DESC
Run specs that failed for a CircleCi build
Uses bin/rspec as driver
Can be run as `bin/rake spec:circle_ci[build_id]`
DESC
task :circle_ci, [ :circle_ci_build_id ] do |task, task_args|
require 'circleci' # Cuz we dont wanna pollute the rest of the stack
CircleCi.configure do |config|
config.token = ENV['CIRCLE_CI_API_TOKEN']
end
# The CircleCi gem add webmock into env.development, which blocks
# remote calls when in development
# So...don't run this as part of a test suite
WebMock.disable!
response = CircleCi::Build.tests(
'my_github_organization',
'my_github_repo',
task_args[ :circle_ci_build_id ]
)
tests = response.body[ "tests" ]
files = tests.select{ |test| test["result"] == "failure" }
.map{ |test| test[ "file" ] }
sh "bin/rspec #{ files.to_a.join ' ' }"
end
end
@ajsharma
Copy link
Author

ajsharma commented Apr 15, 2016

So simple, thanks to the https://github.com/mtchavez/circleci gem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment