Skip to content

Commit

Permalink
Add ruby and tooling: RSpec, Rubocop, Overcommit, Guard, .gitignore,
Browse files Browse the repository at this point in the history
.editorconfig
  • Loading branch information
colszowka committed Oct 8, 2017
1 parent 6857095 commit bd1c9ce
Show file tree
Hide file tree
Showing 12 changed files with 450 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# http://EditorConfig.org
root = true

[*]
# Unix-style newlines
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

# Default indentation
indent_style = space
indent_size = 2

# Set default charset
charset = utf-8
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage
tmp
40 changes: 40 additions & 0 deletions .overcommit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# extend the default configuration defined in:
# https://github.com/brigade/overcommit/blob/master/config/default.yml
#
# At the topmost level of this YAML file is a key representing type of hook
# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
# customize each hook, such as whether to only run it on certain files (via
# `include`), whether to only display output if it fails (via `quiet`), etc.
#
# For a complete list of hooks, see:
# https://github.com/brigade/overcommit/tree/master/lib/overcommit/hook
#
# For a complete list of options that you can use to customize hooks, see:
# https://github.com/brigade/overcommit#configuration
#
PostCheckout:
BundleInstall:
enabled: true

PostMerge:
BundleInstall:
enabled: true

PostRewrite:
BundleInstall:
enabled: true

PreCommit:
BundleCheck:
enabled: true
LocalPathsInGemfile:
enabled: true
RuboCop:
enabled: true
YamlSyntax:
enabled: true

PrePush:
RSpec:
enabled: true

4 changes: 4 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--color
--format documentation
--order rand
--require spec_helper
3 changes: 3 additions & 0 deletions .rubocop
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--display-cop-names
--display-style-guide
--extra-details
47 changes: 47 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# Our adjustments to rubocop default code policies.
#
# See http://rubocop.readthedocs.io/en/latest/ for detailed configuration options documentation

# Additional cops for working with RSpec. See https://github.com/backus/rubocop-rspec
require: rubocop-rspec

AllCops:
Exclude:
- 'tmp/**/*.rb'

Metrics/BlockLength:
Exclude:
# The default guard-rspec config fails this, but it's ok.
- 'Guardfile'
- 'spec/**/*_spec.rb'

# Big screens are common :)
Metrics/LineLength:
Max: 120

# We use RSpec as a format linter, so no specific classes under test neccessarily :)
RSpec/DescribeClass:
Enabled: false

# Prefer to use the up-front message expectations
RSpec/MessageSpies:
Enabled: false

# Prefer structure over small indentation
RSpec/NestedGroups:
Max: 5

Style/Documentation:
Enabled: false

# Prefer to create "real" booleans using double negation
Style/DoubleNegation:
Enabled: false

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/TrailingCommaInLiteral:
EnforcedStyleForMultiline: comma

1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.4.2
3 changes: 3 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SimpleCov.start do
minimum_coverage 100
end
21 changes: 21 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

source "https://rubygems.org"

ruby File.read(File.join(__dir__, ".ruby-version")).strip

group :test do
gem "rspec"
gem "simplecov"
end

group :development do
gem "guard-bundler"
gem "guard-rspec"
gem "guard-rubocop"

gem "overcommit"

gem "rubocop"
gem "rubocop-rspec"
end
111 changes: 111 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.3.0)
childprocess (0.8.0)
ffi (~> 1.0, >= 1.0.11)
coderay (1.1.2)
diff-lcs (1.3)
docile (1.1.5)
ffi (1.9.18)
formatador (0.2.5)
guard (2.14.1)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (~> 1.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-bundler (2.1.0)
bundler (~> 1.0)
guard (~> 2.2)
guard-compat (~> 1.1)
guard-compat (1.2.1)
guard-rspec (4.7.3)
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
guard-rubocop (1.3.0)
guard (~> 2.0)
rubocop (~> 0.20)
iniparse (1.4.4)
json (2.1.0)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
lumberjack (1.0.12)
method_source (0.9.0)
nenv (0.3.0)
notiffany (0.1.1)
nenv (~> 0.1)
shellany (~> 0.0)
overcommit (0.41.0)
childprocess (~> 0.6, >= 0.6.3)
iniparse (~> 1.4)
parallel (1.12.0)
parser (2.4.0.0)
ast (~> 2.2)
powerpack (0.1.1)
pry (0.11.1)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rainbow (2.2.2)
rake
rake (12.1.0)
rb-fsevent (0.10.2)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-core (3.6.0)
rspec-support (~> 3.6.0)
rspec-expectations (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
rubocop (0.50.0)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
rubocop-rspec (1.18.0)
rubocop (>= 0.50.0)
ruby-progressbar (1.9.0)
ruby_dep (1.5.0)
shellany (0.0.1)
simplecov (0.15.1)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
thor (0.20.0)
unicode-display_width (1.3.0)

PLATFORMS
ruby

DEPENDENCIES
guard-bundler
guard-rspec
guard-rubocop
overcommit
rspec
rubocop
rubocop-rspec
simplecov

RUBY VERSION
ruby 2.4.2p198

BUNDLED WITH
1.15.4
101 changes: 101 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# frozen_string_literal: true

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}

## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
# $ mkdir config
# $ mv Guardfile config/
# $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"

guard :bundler do
require "guard/bundler"
require "guard/bundler/verify"
helper = Guard::Bundler::Verify.new

files = ["Gemfile"]
files += Dir["*.gemspec"] if files.any? { |f| helper.uses_gemspec?(f) }

# Assume files are symlinked from somewhere
files.each { |file| watch(helper.real_path(file)) }
end

# Note: The cmd option is now required due to the increasing number of ways
# rspec may be run, below are examples of the most common uses.
# * bundler: 'bundle exec rspec'
# * bundler binstubs: 'bin/rspec'
# * spring: 'bin/rspec' (This will use spring if running and you have
# installed the spring binstubs per the docs)
# * zeus: 'zeus rspec' (requires the server to be started separately)
# * 'just' rspec: 'rspec'

guard :rspec, cmd: "bundle exec rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)

# Feel free to open issues for suggestions and improvements

# RSpec files
rspec = dsl.rspec
watch(rspec.spec_helper) { rspec.spec_dir }
watch(rspec.spec_support) { rspec.spec_dir }
watch(rspec.spec_files)

# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)

# Rails files
rails = dsl.rails(view_extensions: %w[erb haml slim])
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)

watch(rails.controllers) do |m|
[
rspec.spec.call("routing/#{m[1]}_routing"),
rspec.spec.call("controllers/#{m[1]}_controller"),
rspec.spec.call("acceptance/#{m[1]}"),
]
end

# Rails config changes
watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }

# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }

# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
end
end

rubocop_cli_args = []

if ENV["AUTOCORRECT"]
puts "*" * 80, "Rubocop auto-correct mode enabled", "*" * 80
rubocop_cli_args << "--auto-correct"
else
puts "*" * 80
puts "You can set Rubocop to auto-correct fixable offenses by setting ENV['AUTOCORRECT']"
puts "e.g. `$ AUTOCORRECT=yesplease guard`"
puts "*" * 80
end

guard :rubocop, run_on_start: true, cli: rubocop_cli_args.join(" ") do
watch(/.+\.rb$/)
watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
end
Loading

0 comments on commit bd1c9ce

Please sign in to comment.