Skip to content

Commit

Permalink
Merge pull request #24 from samuelgiles/vscode
Browse files Browse the repository at this point in the history
Get CI working after ownership change
  • Loading branch information
samuelgiles authored Mar 11, 2023
2 parents a2dadc3 + 916e00a commit c376fb3
Show file tree
Hide file tree
Showing 79 changed files with 147,306 additions and 27,758 deletions.
5 changes: 5 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Ruby",
"image": "mcr.microsoft.com/devcontainers/ruby:0-3.1",
"postCreateCommand": "bin/setup"
}
92 changes: 21 additions & 71 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,24 @@
---
name: Continuous Integration
env:
SLACK_CHANNEL_ID: C0317P7C9C2
on:
push:
branches-ignore:
- refs/tags/*_staging
- refs/tags/*_production

on: push

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-20.04
test:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.1']
steps:
- name: Checkout branch
# Pin to v3.1.0 SHA
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Cache gems
# Pin to 3.0.11 SHA
uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7
with:
path: vendor/bundle
key: "${{ runner.OS }}-gem-cache-${{ hashFiles('**/*.gemspec')
}}"
restore-keys: "${{ runner.OS }}-gem-cache-\n"
# Pin to the v18 SHA
- uses: "cachix/install-nix-action@daddc62a2e67d1decb56e028c9fa68344b9b7c2a"
with:
extra_nix_config: |
post-build-hook = /etc/nix/upload-to-cache.sh
substituters = https://cache.nixos.org/
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
nix_path: nixpkgs=channel:nixos-22.05
install_url: https://releases.nixos.org/nix/nix-2.7.0/install
- name: Run CI through nix-shell
env:
GEMFURY_DEPLOY_TOKEN: ${{ secrets.GEMFURY_DEPLOY_TOKEN }}
run: nix-shell --run "chmod 755 ./run_ci.sh && ./run_ci.sh"
- name: Post to Slack if build fails
if: failure() && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/stable')
# Pin to the v1.23.0 SHA
uses: slackapi/slack-github-action@007b2c3c751a190b6f0f040e47ed024deaa72844
env:
SLACK_BOT_TOKEN: "${{ secrets.BELLROY_SLACK_TOKEN }}"
with:
channel-id: "${{ env.SLACK_CHANNEL_ID }}"
payload: |
{
"text": "* ${{ github.repository }} BUILD FAILURE*",
"attachments": [
{
"fallback": "Failure summary",
"color": "ff0000",
"fields": [
{
"title": "Branch",
"value": "${{ steps.extract_branch.outputs.branch}}"
},
{
"title": "Who broke it",
"value": "${{ github.actor }}"
},
{
"title": "Build output",
"value": "https://github.com/${{ github.repository }}/commit/${{ github.sha }}/checks",
"short": false
}
]
}
]
}
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: Run RSpec tests
run: bin/rspec
- name: Check for Rubocop offenses
run: bin/rubocop --format github
76 changes: 16 additions & 60 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,66 +1,22 @@
---
Documentation:
Enabled: false
Rails:
Enabled: true
inherit_gem:
rubocop-shopify: rubocop.yml
require: rubocop-rspec

AllCops:
Include:
- app/**/*.rb
- lib/**/*.rb
- spec/**/*.rb
Exclude:
- app/assets/**/*
- bin/**/*
- client/node_modules/**/*
- config/**/*
- coverage/**/*
- data/**/*
- db/**/*
- db_*/**/*
- dw/**/*
- log/**/*
- phrase/**/*
- public/**/*
- tmp/**/*
- vendor/**/*
TargetRubyVersion: 2.5
Metrics/LineLength:
Max: 100
Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented
Style/PercentLiteralDelimiters:
PreferredDelimiters:
"%w": "[]"
RSpec/ExampleLength:
Enabled: false
Max: 10
RSpec/MultipleExpectations:
Enabled: false
Max: 10
RSpec/NestedGroups:
Enabled: false
Max: 10
RSpec/MessageExpectation:
NewCops: disable
SuggestExtensions: false

RSpec/LeakyConstantDeclaration:
Enabled: false
RSpec/MissingExampleGroupArgument:
Enabled: false
require:
- rubocop-performance
- rubocop-rspec
- test_prof/rubocop
Metrics/BlockLength:
Enabled: false
RSpec/MessageSpies:
Enabled: false
RSpec/ExpectInHook:

RSpec/ExampleLength:
Enabled: false
RSpec/AggregateFailures:
Enabled: true
Include:
- spec/**/*.rb
Rails/InverseOf:

RSpec/NamedSubject:
Enabled: false
Rails/Present:

RSpec/MultipleExpectations:
Enabled: false
Rails/TimeZone:

RSpec/VerifiedDoubles:
Enabled: false
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Rubocop offenses resolved

## 1.9.1

- Support `T.nilable(T.class_of(...))` among others (thanks [@deecewan](https://github.com/deecewan))
Expand Down
27 changes: 15 additions & 12 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
source 'https://rubygems.org'
# frozen_string_literal: true

source "https://rubygems.org"

# Specify your gem's dependencies in rspec-sorbet.gemspec
gemspec

group :development, :test do
gem 'guard-livereload', require: false
gem 'guard-rspec'
gem 'pry-byebug'
gem 'rb-fsevent', require: false
gem 'rspec'
gem 'rubocop-rspec'
gem 'rubocop'
gem 'stackprof'
gem 'tapioca'
gem "guard-livereload", require: false
gem "guard-rspec"
gem "pry-byebug"
gem "rb-fsevent", require: false
gem "rspec"
gem "rubocop-rspec"
gem "rubocop-shopify"
gem "rubocop"
gem "stackprof"
gem "tapioca"
end

group :test do
gem 'ffaker'
gem 'simplecov'
gem "ffaker"
gem "rspec-github", require: false
end
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![rspec-sorbet](https://user-images.githubusercontent.com/2643026/63100456-02c12c00-bf6f-11e9-8430-630a27bc6e42.png)

# RSpec Sorbet [![Gem Version](https://badge.fury.io/rb/rspec-sorbet.svg)](https://badge.fury.io/rb/rspec-sorbet) ![CI Badge](https://github.com/tricycle/rspec-sorbet/workflows/Continuous%20Integration/badge.svg)
# RSpec Sorbet [![Gem Version](https://badge.fury.io/rb/rspec-sorbet.svg)](https://badge.fury.io/rb/rspec-sorbet) ![CI Badge](https://github.com/samuelgiles/rspec-sorbet/workflows/Continuous%20Integration/badge.svg)

A small gem consisting of helpers for using Sorbet & RSpec together.

Expand All @@ -19,7 +19,7 @@ require 'rspec/sorbet'

Out of the box if you're using `instance_double`, `class_double` or `object_double` in your specs you'll encounter errors such as the following:

```
```ruby
TypeError:
Parameter 'my_parameter': Expected type MyObject, got type RSpec::Mocks::InstanceVerifyingDouble with value #<InstanceDouble(MyObject) (anonymous)>
Caller: /Users/samuelgiles/Documents/Projects/Clients/Bellroy/bellroy/spec/lib/checkout/use_cases/my_use_case.rb:9
Expand All @@ -33,7 +33,7 @@ RSpec::Sorbet.allow_doubles!

### `eq` matcher usage with `T::Struct`'s

Using the [`eq` matcher](https://www.rubydoc.info/github/rspec/rspec-expectations/RSpec%2FMatchers:eq) to compare [`T::Struct`'s](https://sorbet.org/docs/tstruct) might not behave as you'd expect whereby two separate instances of the same struct class with identical attributes are not `==` out of the box. The standalone [sorbet-struct-comparable](https://github.com/tricycle/sorbet-struct-comparable) gem may be of interest if you are looking for a simple attribute based comparison that will help make the `eq` matcher behave as you expect.
Using the [`eq` matcher](https://www.rubydoc.info/github/rspec/rspec-expectations/RSpec%2FMatchers:eq) to compare [`T::Struct`'s](https://sorbet.org/docs/tstruct) might not behave as you'd expect whereby two separate instances of the same struct class with identical attributes are not `==` out of the box. The standalone [sorbet-struct-comparable](https://github.com/samuelgiles/sorbet-struct-comparable) gem may be of interest if you are looking for a simple attribute based comparison that will help make the `eq` matcher behave as you expect.

### Specifying a custom validation handler

Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
7 changes: 4 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'rspec/sorbet'
require "bundler/setup"
require "rspec/sorbet"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand All @@ -10,5 +11,5 @@ require 'rspec/sorbet'
# require "pry"
# Pry.start

require 'irb'
require "irb"
IRB.start(__FILE__)
27 changes: 27 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rspec-core", "rspec")
27 changes: 27 additions & 0 deletions bin/rubocop
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rubocop' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rubocop", "rubocop")
2 changes: 0 additions & 2 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
6 changes: 4 additions & 2 deletions bin/tapioca
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
ENV["BUNDLE_GEMFILE"] ||= File.expand_path(
"../../Gemfile",
Pathname.new(__FILE__).realpath,
)

bundle_binstub = File.expand_path("../bundle", __FILE__)

Expand Down
Loading

0 comments on commit c376fb3

Please sign in to comment.