Skip to content

Commit

Permalink
Merge pull request #182 from watermarkchurch/coverage
Browse files Browse the repository at this point in the history
coverage
  • Loading branch information
gburgett committed Aug 26, 2019
2 parents 34096c7 + 7515dcb commit ec1d992
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 12 deletions.
7 changes: 0 additions & 7 deletions .simplecov

This file was deleted.

3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -22,6 +22,9 @@ install:
script:
- export COVERALLS_PARALLEL=true
- bin/bundle exec rspec --format documentation --order rand
# only run coverage on the wcc-contentful gem
- bundle exec rake coverage
- bundle exec rake coverage:coveralls
jobs:
include:
- stage: lint
Expand Down
51 changes: 46 additions & 5 deletions Rakefile
Expand Up @@ -7,18 +7,21 @@ require 'active_support/inflector'
require_relative 'wcc-contentful/lib/wcc/contentful/version'
version = WCC::Contentful::VERSION


GEMS = [
'wcc-contentful',
'wcc-contentful-app',
'wcc-contentful-graphql'
]
].freeze

GEMS.each do |name|
namespace name do
Dir.chdir(name) do
Bundler::GemHelper.install_tasks
end

task :coverage do
system('rspec', chdir: name)
end
end
end

Expand Down Expand Up @@ -56,13 +59,51 @@ namespace :bump do
end

desc "Create tag and build and push all gems\n" \
"To prevent publishing in RubyGems use `gem_push=no rake release`"
'To prevent publishing in RubyGems use `gem_push=no rake release`'
task release: [:check].concat(GEMS.map { |g| "#{g}:release" })
desc "Build #{GEMS.join(',')} into the pkg directory."
task build: GEMS.map { |g| "#{g}:build" }
task install: GEMS.map { |g| "#{g}:install" }
task "install:local" => GEMS.map { |g| "#{g}:install:local" }
task 'install:local' => GEMS.map { |g| "#{g}:install:local" }

def to_const(gem)
gem.split('-').map(&:titleize).join('::').gsub('Wcc', 'WCC').constantize
end
end

namespace :coverage do
task :aggregate do
require 'simplecov'

# https://github.com/colszowka/simplecov/issues/219#issuecomment-377991535
results =
GEMS.map { |g| "#{g}/coverage/.resultset.json" }.map do |result_file_name|
puts "Processing #{result_file_name}"
SimpleCov::Result.from_hash(JSON.parse(File.read(result_file_name)))
end
merged_result = SimpleCov::ResultMerger.merge_results(*results)
FileUtils.mkdir_p('./coverage')
File.write('./coverage/.resultset.json', JSON.pretty_generate(merged_result.to_hash))
end

task html: 'coverage:aggregate' do
require 'simplecov'

result = SimpleCov::Result.from_hash(JSON.parse(File.read('./coverage/.resultset.json')))
formatter = SimpleCov::Formatter::HTMLFormatter.new
formatter.format(result)

system('open ./coverage/index.html')
end

task coveralls: 'coverage:aggregate' do
require 'simplecov'
require 'coveralls'

result = SimpleCov::Result.from_hash(JSON.parse(File.read('./coverage/.resultset.json')))
formatter = Coveralls::SimpleCov::Formatter.new
formatter.format(result)
end
end

task coverage: [*GEMS.map { |g| "#{g}:coverage" }, 'coverage:aggregate'] do
end
6 changes: 6 additions & 0 deletions wcc-contentful-app/spec/spec_helper.rb
Expand Up @@ -2,6 +2,12 @@

require 'simplecov'

SimpleCov.start do
root File.expand_path('../..', __dir__)
add_filter '/spec/'
coverage_dir "#{File.expand_path('..', __dir__)}/coverage"
end

require 'bundler/setup'
require 'dotenv/load'
require 'wcc/contentful'
Expand Down
6 changes: 6 additions & 0 deletions wcc-contentful-graphql/spec/spec_helper.rb
Expand Up @@ -2,6 +2,12 @@

require 'simplecov'

SimpleCov.start do
root File.expand_path('../..', __dir__)
add_filter '/spec/'
coverage_dir "#{File.expand_path('..', __dir__)}/coverage"
end

require 'bundler/setup'
require 'dotenv/load'
require 'wcc/contentful'
Expand Down
6 changes: 6 additions & 0 deletions wcc-contentful/spec/spec_helper.rb
Expand Up @@ -2,6 +2,12 @@

require 'simplecov'

SimpleCov.start do
root File.expand_path('../..', __dir__)
add_filter '/spec/'
coverage_dir "#{File.expand_path('..', __dir__)}/coverage"
end

require 'bundler/setup'
require 'dotenv/load'
require 'wcc/contentful'
Expand Down

0 comments on commit ec1d992

Please sign in to comment.