Skip to content
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
10 changes: 10 additions & 0 deletions .github/workflows/danger-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: danger comment
on:
workflow_run:
workflows: [Danger]
types: [completed]

jobs:
comment:
uses: numbata/danger-pr-comment/.github/workflows/danger-comment.yml@main
secrets: inherit
23 changes: 7 additions & 16 deletions .github/workflows/danger.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
---
name: danger

on:
pull_request:
types: [opened, reopened, edited, synchronize]

jobs:
danger:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
bundler-cache: true
- name: Run Danger
run: |
# the personal token is public, this is ok, base64 encode to avoid tripping Github
TOKEN=$(echo -n Z2hwX0xNQ3VmanBFeTBvYkZVTWh6NVNqVFFBOEUxU25abzBqRUVuaAo= | base64 --decode)
DANGER_GITHUB_API_TOKEN=$TOKEN bundle exec danger --verbose
uses: numbata/danger-pr-comment/.github/workflows/danger-run.yml@main
secrets: inherit
with:
ruby-version: '3.1'
bundler-cache: true
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.entry.ruby }}
- run: bundle install --jobs=3 --retry=3 --path=vendor/bundle
- run: bundle install --jobs=3 --retry=3
- run: bundle exec rake spec
continue-on-error: ${{ matrix.entry.allowed-failure }}
- name: Specs for when the i18n gem is not available
Expand Down
34 changes: 29 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
require:
- rubocop-rake
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.7
NewCops: enable
Expand All @@ -15,7 +11,7 @@ Metrics/BlockLength:
RSpec/SpecFilePathFormat:
Enabled: false

RSpec/FilePath:
Style/LineLength:
Enabled: false

Style/HashEachMethods:
Expand All @@ -27,4 +23,32 @@ Style/HashTransformKeys:
Style/HashTransformValues:
Enabled: true

Naming/FileName:
Enabled: false

Style/Documentation:
Enabled: false

Naming/MethodParameterName:
Enabled: false

RSpec/NestedGroups:
Enabled: false

RSpec/ExampleLength:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false

Lint/ConstantDefinitionInBlock:
Enabled: false

RSpec/LeakyConstantDeclaration:
Enabled: false

inherit_from: .rubocop_todo.yml

plugins:
- rubocop-rake
- rubocop-rspec
67 changes: 1 addition & 66 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,7 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-02-14 01:34:25 UTC using RuboCop version 1.45.1.
# on 2025-12-30 16:44:41 UTC using RuboCop version 1.82.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 4
# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
Lint/ConstantDefinitionInBlock:
Exclude:
- 'spec/ruby-enum/enum_spec.rb'

# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Naming/FileName:
Exclude:
- 'lib/ruby-enum.rb'

# Offense count: 6
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
Naming/MethodParameterName:
Exclude:
- 'lib/ruby-enum/enum.rb'

# Offense count: 3
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 11

# Offense count: 4
RSpec/LeakyConstantDeclaration:
Exclude:
- 'spec/ruby-enum/enum_spec.rb'

# Offense count: 6
RSpec/MultipleExpectations:
Max: 11

# Offense count: 18
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
# SupportedStyles: always, named_only
RSpec/NamedSubject:
Exclude:
- 'spec/ruby-enum/enum_spec.rb'

# Offense count: 1
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 4

# Offense count: 4
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/ruby-enum/enum.rb'
- 'lib/ruby-enum/errors/base.rb'
- 'lib/ruby-enum/errors/uninitialized_constant_error.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 148
2 changes: 2 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true

danger.import_dangerfile(gem: 'danger-pr-comment')

changelog.check!
toc.check!
9 changes: 5 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ gem 'rake'

group :development, :test do
gem 'danger'
gem 'danger-changelog', '0.6.1'
gem 'danger-toc', '0.2.0'
gem 'rspec', '~> 3.0'
gem 'rubocop', '~> 1.0'
gem 'danger-changelog'
gem 'danger-pr-comment'
gem 'danger-toc'
gem 'rspec'
gem 'rubocop', '1.82.1'
gem 'rubocop-rake'
gem 'rubocop-rspec'
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby-enum/errors/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def compose_message(key, attributes = {})
"\nSummary:\n #{@summary}" + "\nResolution:\n #{@resolution}"
end

private

BASE_KEY = 'ruby.enum.errors.messages' # :nodoc:

private

# Given the key of the specific error and the options hash, translate the
# message.
#
Expand Down
69 changes: 35 additions & 34 deletions spec/ruby-enum/enum/case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,56 @@

require 'spec_helper'

RSpec.describe Ruby::Enum::Case do
test_enum =
Class.new do
include Ruby::Enum
include Ruby::Enum::Case

define :RED, :red
define :GREEN, :green
define :BLUE, :blue
end
module Case
class Colors
include Ruby::Enum
include Ruby::Enum::Case

define :RED, :red
define :GREEN, :green
define :BLUE, :blue
end
end

RSpec.describe Ruby::Enum::Case do
describe '.case' do
context 'when all cases are defined' do
subject { test_enum.case(test_enum::RED, cases) }
subject { Case::Colors.case(Case::Colors::RED, cases) }

let(:cases) do
{
[test_enum::RED, test_enum::GREEN] => -> { 'red or green' },
test_enum::BLUE => -> { 'blue' }
[Case::Colors::RED, Case::Colors::GREEN] => -> { 'red or green' },
Case::Colors::BLUE => -> { 'blue' }
}
end

it { is_expected.to eq('red or green') }

context 'when the value is nil' do
subject { test_enum.case(nil, cases) }
subject { Case::Colors.case(nil, cases) }

it { is_expected.to be_nil }
end

context 'when the value is empty' do
subject { test_enum.case('', cases) }
subject { Case::Colors.case('', cases) }

it { is_expected.to be_nil }
end

context 'when the value is the value of the enum' do
subject { test_enum.case(:red, cases) }
subject { Case::Colors.case(:red, cases) }

it { is_expected.to eq('red or green') }
end

context 'when the value is used inside the lambda' do
subject { test_enum.case(test_enum::RED, cases) }
subject { Case::Colors.case(Case::Colors::RED, cases) }

let(:cases) do
{
[test_enum::RED, test_enum::GREEN] => ->(color) { "is #{color}" },
test_enum::BLUE => -> { 'blue' }
[Case::Colors::RED, Case::Colors::GREEN] => ->(color) { "is #{color}" },
Case::Colors::BLUE => -> { 'blue' }
}
end

Expand All @@ -60,12 +61,12 @@

context 'when there are mutliple matches' do
subject do
test_enum.case(
test_enum::RED,
Case::Colors.case(
Case::Colors::RED,
{
[test_enum::RED, test_enum::GREEN] => -> { 'red or green' },
test_enum::RED => -> { 'red' },
test_enum::BLUE => -> { 'blue' }
[Case::Colors::RED, Case::Colors::GREEN] => -> { 'red or green' },
Case::Colors::RED => -> { 'red' },
Case::Colors::BLUE => -> { 'blue' }
}
)
end
Expand All @@ -76,9 +77,9 @@
context 'when not all cases are defined' do
it 'raises an error' do
expect do
test_enum.case(
test_enum::RED,
{ [test_enum::RED, test_enum::GREEN] => -> { 'red or green' } }
Case::Colors.case(
Case::Colors::RED,
{ [Case::Colors::RED, Case::Colors::GREEN] => -> { 'red or green' } }
)
end.to raise_error(Ruby::Enum::Case::ClassMethods::NotAllCasesHandledError)
end
Expand All @@ -87,10 +88,10 @@
context 'when not all cases are defined but :else is specified (default case)' do
it 'does not raise an error' do
expect do
result = test_enum.case(
test_enum::BLUE,
result = Case::Colors.case(
Case::Colors::BLUE,
{
[test_enum::RED, test_enum::GREEN] => -> { 'red or green' },
[Case::Colors::RED, Case::Colors::GREEN] => -> { 'red or green' },
else: -> { 'blue' }
}
)
Expand All @@ -103,11 +104,11 @@
context 'when a superfluous case is defined' do
it 'raises an error' do
expect do
test_enum.case(
test_enum::RED,
Case::Colors.case(
Case::Colors::RED,
{
[test_enum::RED, test_enum::GREEN] => -> { 'red or green' },
test_enum::BLUE => -> { 'blue' },
[Case::Colors::RED, Case::Colors::GREEN] => -> { 'red or green' },
Case::Colors::BLUE => -> { 'blue' },
:something => -> { 'green' }
}
)
Expand Down
Loading
Loading