Skip to content

Commit

Permalink
Run RSpec specs and features as part of build (#133)
Browse files Browse the repository at this point in the history
* Import things from personal boilerplate

* Add some very simple initial specs
  • Loading branch information
apiology committed Jan 2, 2020
1 parent fd54cf4 commit eb69446
Show file tree
Hide file tree
Showing 17 changed files with 173 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,6 @@
/Gemfile.lock
*~
/pkg
/coverage/.resultset.json
/coverage/assets/
/coverage/index.html
50 changes: 35 additions & 15 deletions .rubocop.yml
@@ -1,27 +1,17 @@
# I like trailing commas in maps. They let me insert new elements and
# I like trailing commas in hashes. They let me insert new elements and
# see them as one line in a diff, not two.
Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma

Style/StringLiterals:
EnforcedStyle: single_quotes
SupportedStyles:
- single_quotes
- double_quotes
ConsistentQuotesInMultiline: true

# I use keyword arguments for a poor man's dependency injection to cut
# down on the magic in my tests.
Metrics/ParameterLists:
CountKeywordArgs: false

Style/Encoding:
Enabled: false

# If i'm using one function name and returning the contents of an
# If I'm using one function name and returning the contents of an
# attribute, that's OK. The alternative would be this, which I find
# confusing and often not really what I mean:
#
Expand All @@ -31,7 +21,7 @@ Style/TrivialAccessors:
ExactNameMatch: true

#
# Add 'X XX' to the standard list
# Add 'XX X' to the standard list
#
Style/CommentAnnotation:
Keywords:
Expand All @@ -40,17 +30,47 @@ Style/CommentAnnotation:
- "FIXM\
E"
- "OPTIMIZ\
E"
E"
- "HAC\
K"
K"
- "REVIE\
W"
- "XX\
X"

# https://stackoverflow.com/questions/40934345/rubocop-25-line-block-size-and-rspec-tests
Metrics/BlockLength:
# Exclude DSLs
Exclude:
- 'Rakefile'
- '*.gemspec'
- '**/*.rake'
- 'spec/**/*.rb'
- 'feature/**/*.rb'

# http://www.betterspecs.org/#single
#
# > in tests that are not isolated (e.g. ones that integrate with a
# > DB, an external webservice, or end-to-end-tests), you take a
# > massive performance hit to do the same setup over and over again,
# > just to set a different expectation in each test. In these sorts
# > of slower tests, I think it's fine to specify more than one
# > isolated behavior.
RSpec/MultipleExpectations:
Exclude:
- 'feature/**/*.rb'

Style/StringLiterals:
EnforcedStyle: single_quotes
SupportedStyles:
- single_quotes
- double_quotes
ConsistentQuotesInMultiline: true

AllCops:
TargetRubyVersion: 2.4


require:
- rubocop-rspec
- rubocop-minitest
Expand Down
8 changes: 8 additions & 0 deletions Makefile
@@ -1,3 +1,5 @@
.PHONY: spec feature

all: localtest

localtest:
Expand All @@ -6,6 +8,12 @@ localtest:
test:
@bundle exec rake test

feature:
@bundle exec rake feature

spec:
@bundle exec rake spec

rubocop:
@bundle exec rake rubocop

Expand Down
38 changes: 38 additions & 0 deletions feature/feature_helper.rb
@@ -0,0 +1,38 @@
# frozen_string_literal: true

require 'open3'

# Add the bin directory, to allow testing of gem executables as if the gem is
# already installed.
root_dir = RSpec::Core::RubyProject.root
exec_dir = File.join(File::SEPARATOR, root_dir, 'bin')
ENV['PATH'] = [exec_dir, ENV['PATH']].join(File::PATH_SEPARATOR)

# Courtesy of:
# https://raw.github.com/cupakromer/tao-of-tdd/master/adder/spec/support/
# capture_exec.rb
def exec_io(*cmd)
cmd = cmd.flatten
env = {
# Avoid spurious deprecation warnings in things which are out of
# our control
'RUBYOPT' => '-W0',
}
all_out, _exit_code = Open3.capture2e(env, *cmd)

all_out
end

RSpec.configure do |config|
config.filter_run_excluding :wip
config.run_all_when_everything_filtered = true
config.order = 'random'
config.alias_it_should_behave_like_to :has_behavior
config.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:'
end

def let_double(*doubles)
doubles.each do |double_sym|
let(double_sym) { double(double_sym.to_s) }
end
end
10 changes: 10 additions & 0 deletions feature/quality/quality_checker_spec.rb
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require_relative '../feature_helper'
require 'quality/quality_checker'

describe Quality::QualityChecker do
it 'has an example feature spec' do
expect(exec_io('echo test')).to eq("test\n")
end
end
2 changes: 2 additions & 0 deletions lib/quality/tools/bigfiles.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require_relative '../tool'

module Quality
module Tools
# Adds 'bigfiles' tool support to quality gem
Expand Down
2 changes: 1 addition & 1 deletion metrics/punchlist_high_water_mark
@@ -1 +1 @@
6
10
5 changes: 1 addition & 4 deletions quality.gemspec
@@ -1,4 +1,3 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true

# ; -*-Ruby-*-
Expand Down Expand Up @@ -71,13 +70,11 @@ Gem::Specification.new do |s|
# Workaround for
# https://github.com/bundler/bundler/issues/3401
s.add_development_dependency('minitest', ['~> 5'])
# https://github.com/apiology/quality/issues/121
# https://github.com/freerange/mocha/issues/436
s.add_development_dependency('mocha')
s.add_development_dependency('pronto')
s.add_development_dependency('pronto-flake8')
s.add_development_dependency('pronto-punchlist')
s.add_development_dependency('pronto-reek')
s.add_development_dependency('pronto-rubocop')
s.add_development_dependency('rake', ['!= 10.4.2'])
s.add_development_dependency('rspec')
end
4 changes: 4 additions & 0 deletions rakelib/ci.rake
@@ -0,0 +1,4 @@
# frozen_string_literal: true

desc 'Run tasks to be done during a continuous integration (CI) build'
task ci: :localtest
3 changes: 2 additions & 1 deletion rakelib/clear_metrics.rake
Expand Up @@ -3,6 +3,7 @@
desc 'Rebaseline quality thresholds to last commit'
task :clear_metrics do |_t|
puts Time.now
ret = system('git checkout coverage/.last_run.json *_high_water_mark')
ret =
system('git checkout coverage/.last_run.json metrics/*_high_water_mark')
raise unless ret
end
2 changes: 1 addition & 1 deletion rakelib/default.rake
@@ -1,4 +1,4 @@
# frozen_string_literal: true

desc 'Standard build'
task default: [:localtest]
task default: :localtest
9 changes: 9 additions & 0 deletions rakelib/feature.rake
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require 'rspec/core/rake_task'

desc 'Run features'
RSpec::Core::RakeTask.new(:feature) do |task|
task.pattern = 'feature/**/*_spec.rb'
task.rspec_opts = '--format doc --default-path feature'
end
2 changes: 1 addition & 1 deletion rakelib/localtest.rake
@@ -1,4 +1,4 @@
# frozen_string_literal: true

desc 'Standard build when running on a workstation'
task localtest: %i[clear_metrics test quality]
task localtest: %i[clear_metrics spec test feature quality]
27 changes: 20 additions & 7 deletions rakelib/quality.rake
Expand Up @@ -2,12 +2,25 @@

require 'quality/rake/task'

Quality::Rake::Task.new do |task|
task.exclude_files = [
'etc/scalastyle_config.xml', 'ChangeLog.md', 'Dockerfile', 'Gemfile.lock'
]
# cane deprecated in favor of rubocop, reek rarely actionable
task.skip_tools = %w[reek cane]
task.output_dir = 'metrics'
task.punchlist_regexp = 'XX' \
'X|TOD' \
'O|FIXM' \
'E|OPTIMIZ' \
'E|HAC' \
'K|REVIE' \
'W|LATE' \
'R|FIXI' \
'T|xi' \
't '
# task.verbose = true
end

desc 'Verify and report on code quality issues'
task quality: %i[pronto update_bundle_audit]

Quality::Rake::Task.new do |t|
t.exclude_files = ['etc/scalastyle_config.xml', 'ChangeLog.md', 'Dockerfile']
t.minimum_threshold = { bigfiles: 300 }
t.skip_tools = ['reek']
# t.verbose = true
end
9 changes: 9 additions & 0 deletions rakelib/spec.rake
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require 'rspec/core/rake_task'

desc 'Run specs'
RSpec::Core::RakeTask.new(:spec) do |task|
task.pattern = 'spec/**/*_spec.rb'
task.rspec_opts = '--format doc'
end
14 changes: 14 additions & 0 deletions spec/quality/tools/bigfiles_spec.rb
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require_relative '../../spec_helper'
require 'quality/tools/bigfiles'
require 'quality/runner'

describe Quality::Tools::Bigfiles do
let(:runner) { instance_double(Quality::Runner) }
let(:bigfiles) { described_class.new(runner) }

it 'can be created' do
expect(bigfiles).not_to be(nil)
end
end
15 changes: 15 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'simplecov'

SimpleCov.start do
# this dir used by TravisCI
add_filter 'vendor'
end

RSpec.configure do |config|
config.order = 'random'
config.expect_with :rspec do |c|
c.syntax = :expect
end
end

0 comments on commit eb69446

Please sign in to comment.