Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add behavior tests to CI #239

Merged
merged 9 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ jobs:
- ruby: "2.6"
- ruby: "2.7"
- ruby: "3.0"
coverage: "yes"
codecov: "yes"
neomilium marked this conversation as resolved.
Show resolved Hide resolved
env:
COVERAGE: ${{ matrix.coverage }}
CODECOV: ${{ matrix.codecov }}
steps:
- uses: actions/checkout@v2
- name: Install Ruby ${{ matrix.ruby }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run tests
- name: Run unit tests
run: bundle exec rake spec
- name: Run behavior tests
run: bundle exec cucumber
- name: Build gem
run: gem build *.gemspec
46 changes: 46 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
SimpleCov.start do
if ENV['SIMPLECOV_ROOT']
SimpleCov.root(ENV['SIMPLECOV_ROOT'])

filters.clear # This will remove the :root_filter and :bundler_filter that come via simplecov's defaults

# Because simplecov filters everything outside of the SimpleCov.root
# This should be added, cf.
# https://github.com/colszowka/simplecov#default-root-filter-and-coverage-for-things-outside-of-it
add_filter do |src|
!(src.filename =~ /^#{SimpleCov.root}/)
end
end

add_group 'Source code', 'lib'

add_group 'Unit tests', 'spec'

add_group 'Behavior tests', 'features'
add_filter '/features/support/env.rb'

enable_coverage :branch

# do not track vendored files
add_filter '/vendor'
add_filter '/.vendor'

# exclude anything that is not in lib, spec or features directories
add_filter do |src|
!(src.filename =~ /^#{SimpleCov.root}\/(lib|spec|features)/)
end

track_files '**/*.rb'
end

if ENV['CODECOV']
require 'simplecov-console'
require 'codecov'

SimpleCov.formatters = [
SimpleCov::Formatter::Console,
SimpleCov::Formatter::Codecov,
]
end

# vim: filetype=ruby
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ group :release do
gem 'github_changelog_generator', :require => false
end

group :coverage, optional: ENV['COVERAGE']!='yes' do
group :coverage, optional: ENV['CODECOV']!='yes' do
gem 'simplecov-console', :require => false
gem 'codecov', :require => false
end
16 changes: 16 additions & 0 deletions bin/msync
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env ruby

if ENV['COVERAGE']
# This block allow us to grab code coverage when running this script.
#
# Note: This environment variable (ie. COVERAGE) is set in Cucumber/Aruba configuration to collect reports
simplecov_root = File.expand_path File.join(File.dirname(__FILE__), '..')

# When running with aruba simplecov was using /tmp/aruba as the root folder.
# This is to force using the project folder
ENV['SIMPLECOV_ROOT'] = simplecov_root
require 'simplecov'

# https://github.com/simplecov-ruby/simplecov/issues/234
# As described in the issue, every process must have an unique name:
SimpleCov.command_name "#{File.basename $PROGRAM_NAME} (pid: #{Process.pid})"
end

lib = File.expand_path('../../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Expand Down
7 changes: 7 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
require 'simplecov'

SimpleCov.command_name 'Cucumber'

require 'aruba/cucumber'

require_relative '../../spec/helpers/faker'
Expand All @@ -6,4 +10,7 @@

Before do
@aruba_timeout_seconds = 5

# This enables coverage when aruba runs `msync` executable (cf. `bin/msync`)
set_environment_variable('COVERAGE', '1')
end
1 change: 1 addition & 0 deletions modulesync.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'rubocop', '~> 0.50.0'
spec.add_development_dependency 'cucumber'
spec.add_development_dependency 'simplecov'

spec.add_runtime_dependency 'git', '~>1.7'
spec.add_runtime_dependency 'gitlab', '~>4.0'
Expand Down
24 changes: 1 addition & 23 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
begin
require 'simplecov'
require 'simplecov-console'
require 'codecov'
rescue LoadError
else
SimpleCov.start do
track_files 'lib/**/*.rb'

add_filter '/spec'

enable_coverage :branch

# do not track vendored files
add_filter '/vendor'
add_filter '/.vendor'
end

SimpleCov.formatters = [
SimpleCov::Formatter::Console,
SimpleCov::Formatter::Codecov,
]
end
require 'simplecov'

require 'modulesync'
2 changes: 1 addition & 1 deletion spec/unit/modulesync/git_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
RSpec.shared_examples 'hostname_extractor' do |url, hostname|
context "with '#{url}' URL" do
subject { ModuleSync::GitService.extract_hostname(url) }
it "should extract '#{hostname}' as hostname" do
it "should extract #{hostname.nil? ? 'nil' : "'#{hostname}'"} as hostname" do
expect(subject).to eq(hostname)
end
end
Expand Down