Skip to content

Commit

Permalink
style(StringLiterals): enforce double quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
cyril committed May 11, 2021
1 parent 753db86 commit c1d7adf
Show file tree
Hide file tree
Showing 27 changed files with 368 additions and 322 deletions.
13 changes: 7 additions & 6 deletions .brutal.yml
@@ -1,19 +1,20 @@
---
header: |
#!/usr/bin/env ruby
# frozen_string_literal: false
require 'simplecov'
require "simplecov"
::SimpleCov.command_name 'Brutal test suite'
::SimpleCov.command_name "Brutal test suite"
::SimpleCov.start
require './lib/spectus'
require "./lib/spectus"
self.class.include ::Spectus
subject: |
begin
it { 'foo'.%{challenge} }.%{level} %{matcher}
it { "foo".%{challenge} }.%{level} %{matcher}
rescue ::Spectus::Result::Fail => e
e
end
Expand All @@ -22,7 +23,7 @@ contexts:
challenge:
- "upcase"
- "itself"
- "gsub!('f', 'b')"
- 'gsub!("f", "b")'
- "boom"
- "empty?(4)"
level:
Expand All @@ -39,7 +40,7 @@ contexts:
matcher:
- "raise_exception(NoMethodError)"
- "raise_exception(ArgumentError)"
- "eql('foo')"
- 'eql("foo")'
- "equal(42)"

actuals:
Expand Down
3 changes: 3 additions & 0 deletions .github/config/rubocop_linter_action.yml
@@ -1,6 +1,9 @@
versions:
- rubocop-md
- rubocop-performance
- rubocop-rake
- rubocop-thread_safety

rubocop_fail_level: warning
check_scope: modified
base_branch: origin/main
2 changes: 1 addition & 1 deletion .github/workflows/rubocop.yml
Expand Up @@ -8,7 +8,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: RuboCop Linter Action
uses: andrewmcodes/rubocop-linter-action@v3.2.0
uses: andrewmcodes/rubocop-linter-action@v3.3.0

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27 changes: 22 additions & 5 deletions .rubocop.yml
@@ -1,14 +1,31 @@
require:
- rubocop-performance
- rubocop-thread_safety

inherit_from: .rubocop_todo.yml

AllCops:
NewCops: enable
TargetRubyVersion: 2.7

Exclude:
- test.rb

require:
- rubocop-md
- rubocop-performance
- rubocop-rake
- rubocop-thread_safety

# Enforcing double quotes reduces the times where you need to switch to Crystal.
Style/StringLiterals:
EnforcedStyle: single_quotes
EnforcedStyle: double_quotes

# We do not need to support Ruby 1.9, so this is good to use.
Style/SymbolArray:
Enabled: true

# Most readable form.
Layout/HashAlignment:
EnforcedHashRocketStyle: table
EnforcedColonStyle: table

# Check with yard instead.
Style/Documentation:
Enabled: false
26 changes: 18 additions & 8 deletions .rubocop_todo.yml
Expand Up @@ -6,14 +6,7 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'spectus.gemspec'

# Offense count: 51
# Offense count: 44
# Cop supports --auto-correct.
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
# SupportedHashRocketStyles: key, separator, table
Expand All @@ -24,6 +17,12 @@ Layout/HashAlignment:
- 'lib/spectus/expectation_target.rb'
- 'lib/spectus/requirement_level/base.rb'

# Offense count: 2
# Configuration parameters: CheckForMethodsWithNoSideEffects.
Lint/Void:
Exclude:
- 'README.md'

# Offense count: 2
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
Metrics/MethodLength:
Expand All @@ -33,3 +32,14 @@ Metrics/MethodLength:
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 8

# Offense count: 3
Style/MixinUsage:
Exclude:
- 'README.md'

# Offense count: 1
# Cop supports --auto-correct.
Style/StringConcatenation:
Exclude:
- 'README.md'
1 change: 1 addition & 0 deletions .ruby-version
@@ -0,0 +1 @@
2.7.2
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -8,8 +8,8 @@ before_install:
script:
- bundle exec rake test
rvm:
- 2.6
- 2.7
- 3.0
- ruby-head
matrix:
allow_failures:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,5 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

gemspec
57 changes: 33 additions & 24 deletions Gemfile.lock
@@ -1,49 +1,56 @@
PATH
remote: .
specs:
spectus (3.1.2)
spectus (3.1.3)
defi (~> 2.0.4)
matchi (~> 2.0.0)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.1)
ast (2.4.2)
aw (0.1.11)
brutal (1.1.1)
defi (2.0.4)
aw (~> 0.1.10)
docile (1.3.2)
docile (1.3.5)
matchi (2.0.0)
parallel (1.19.2)
parser (2.7.1.4)
parallel (1.20.1)
parser (3.0.1.1)
ast (~> 2.4.1)
rainbow (3.0.0)
rake (13.0.1)
regexp_parser (1.7.1)
rexml (3.2.4)
rubocop (0.90.0)
rake (13.0.3)
regexp_parser (2.1.1)
rexml (3.2.5)
rubocop (1.14.0)
parallel (~> 1.10)
parser (>= 2.7.1.1)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.7)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 0.3.0, < 1.0)
rubocop-ast (>= 1.5.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.3.0)
parser (>= 2.7.1.4)
rubocop-performance (1.8.0)
rubocop (>= 0.87.0)
rubocop-thread_safety (0.4.1)
rubocop (>= 0.51.0)
ruby-progressbar (1.10.1)
simplecov (0.19.0)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.5.0)
parser (>= 3.0.1.1)
rubocop-md (1.0.1)
rubocop (>= 1.0)
rubocop-performance (1.11.3)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rake (0.5.1)
rubocop
rubocop-thread_safety (0.4.2)
rubocop (>= 0.53.0)
ruby-progressbar (1.11.0)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov-html (0.12.2)
unicode-display_width (1.7.0)
yard (0.9.25)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.3)
unicode-display_width (2.0.0)
yard (0.9.26)

PLATFORMS
ruby
Expand All @@ -52,7 +59,9 @@ DEPENDENCIES
brutal
bundler
rake
rubocop-md
rubocop-performance
rubocop-rake
rubocop-thread_safety
simplecov
spectus!
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014-2020 Cyril Kato
Copyright (c) 2014-2021 Cyril Kato

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 9 additions & 9 deletions README.md
Expand Up @@ -13,7 +13,7 @@
Add this line to your application's Gemfile:

```ruby
gem 'spectus'
gem "spectus"
```

And then execute:
Expand Down Expand Up @@ -59,8 +59,8 @@ Example of test without isolation:

```ruby
include Spectus
greeting = 'Hello, world!'
it { greeting.gsub!('world', 'Alice') }.MUST eql 'Hello, Alice!'
greeting = "Hello, world!"
it { greeting.gsub!("world", "Alice") }.MUST eql "Hello, Alice!"
# => Spectus::Result::Pass(actual: "Hello, Alice!", error: nil, expected: "Hello, Alice!", got: true, matcher: :eql, negate: false, level: :MUST, valid: true)
greeting # => "Hello, Alice!"
```
Expand All @@ -69,8 +69,8 @@ Example of test in isolation:

```ruby
include Spectus
greeting = 'Hello, world!'
it { greeting.gsub!('world', 'Alice') }.MUST! eql 'Hello, Alice!'
greeting = "Hello, world!"
it { greeting.gsub!("world", "Alice") }.MUST! eql "Hello, Alice!"
# => Spectus::Result::Pass(actual: "Hello, Alice!", error: nil, expected: "Hello, Alice!", got: true, matcher: :eql, negate: false, level: :MUST, valid: true)
greeting # => "Hello, world!"
```
Expand All @@ -88,7 +88,7 @@ include Spectus
Given the "`ルビー`" object, when it receives `valid_encoding?` method, then it **MUST** be `true`:

```ruby
it { 'ルビー'.valid_encoding? }.MUST be_true
it { "ルビー".valid_encoding? }.MUST be_true
# => Spectus::Result::Pass(actual: true, error: nil, expected: nil, got: true, matcher: :be_true, negate: false, level: :MUST, valid: true)
```

Expand All @@ -99,7 +99,7 @@ The result of the test shows that the spec passed.
Given the "`foo`" object, when it receives `length` method, then it **MUST NOT** raise the `NoMethodError` exception:

```ruby
it { 'foo'.length }.MUST_NOT raise_exception NoMethodError
it { "foo".length }.MUST_NOT raise_exception NoMethodError
# => Spectus::Result::Pass(actual: 3, error: nil, expected: NoMethodError, got: true, matcher: :raise_exception, negate: true, level: :MUST, valid: true)
```

Expand All @@ -122,7 +122,7 @@ However, because there isn't any exception, the result of the test shows that th
Given the "`1`" object, when it receives `+(1)` method, then it **SHOULD NOT** return the "`11`" value:

```ruby
it { '1' + 1 }.SHOULD_NOT eql '11'
it { "1" + 1 }.SHOULD_NOT eql "11"
# raise Spectus::Result::Fail(actual: nil, error: #<TypeError: no implicit conversion of Integer into String>, expected: "11", got: nil, matcher: :eql, negate: true, level: :SHOULD, valid: false)
```

Expand All @@ -133,7 +133,7 @@ There was a `TypeError` exception, the result of the test shows that the spec fa
Given the "`foo`" object, when it receives `blank?` method, then it **MAY** be `false`:

```ruby
it { 'foo'.blank? }.MAY be_false
it { "foo".blank? }.MAY be_false
# => Spectus::Result::Pass(actual: nil, error: #<NoMethodError: undefined method `blank?' for "foo":String>, expected: nil, got: nil, matcher: :be_false, negate: false, level: :MAY, valid: false)
```

Expand Down
24 changes: 10 additions & 14 deletions Rakefile
@@ -1,23 +1,19 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rake/testtask'
require 'rubocop/rake_task'

RuboCop::RakeTask.new
require "bundler/gem_tasks"
require "rake/testtask"
require "rubocop/rake_task"
require "yard"

Rake::TestTask.new do |t|
t.pattern = 'test.rb'
t.pattern = "test.rb"
t.verbose = true
t.warning = true
end

namespace :test do
task :coverage do
ENV['COVERAGE'] = 'true'
Rake::Task['test'].invoke
end
end
RuboCop::RakeTask.new
YARD::Rake::YardocTask.new

Dir["tasks/**/*.rake"].each { |t| load t }

task(:doc_stats) { ruby '-S yard stats' }
task default: %i[test doc_stats rubocop]
task default: %i[yard brutal rubocop:auto_correct test]
2 changes: 1 addition & 1 deletion VERSION.semver
@@ -1 +1 @@
3.1.2
3.1.3
6 changes: 3 additions & 3 deletions bin/console
@@ -1,8 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'spectus'
require 'irb'
require "bundler/setup"
require "spectus"
require "irb"

IRB.start
4 changes: 2 additions & 2 deletions lib/spectus.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'matchi/helper'
require "matchi/helper"

# Namespace for the Spectus library.
#
Expand All @@ -23,4 +23,4 @@ def it(&input)
end
end

require_relative File.join('spectus', 'expectation_target')
require_relative File.join("spectus", "expectation_target")
2 changes: 1 addition & 1 deletion lib/spectus/exam.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'defi'
require "defi"

module Spectus
# This class evaluate the expectation with the passed block.
Expand Down

0 comments on commit c1d7adf

Please sign in to comment.