Skip to content

Commit

Permalink
Disables FrozenStringLiteralComment rule (#840)
Browse files Browse the repository at this point in the history
* Disables FrozenStringLiteralComment rule

Why https://github.com/testdouble/standard#why-arent-frozen_string_literal-true-magic-comments-enforced

* Pass error message to constructor instead of overriding `#to_s`

`Exception#to_s` returns the given message,
we can pass the error message to constructor instead of overriding the method.

This will also fix the Rubocop offenses.

* Exclude files from MissingSuper
  • Loading branch information
PanosCodes authored Mar 20, 2023
1 parent 2fc6aca commit d5cd745
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 16 deletions.
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ Style/Documentation:
- spec/lib/validators/array_validator_spec.rb
- spec/dummy/**/*.rb

Style/FrozenStringLiteralComment:
Enabled: false

Naming/BlockForwarding:
EnforcedStyle: explicit
BlockForwardingName: block

Lint/MissingSuper:
Exclude:
- 'lib/apipie/errors.rb'
- 'lib/apipie/response_description_adapter.rb'
- 'lib/apipie/validator.rb'
18 changes: 2 additions & 16 deletions lib/apipie/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,13 @@ def to_s

class ResponseDoesNotMatchSwaggerSchema < Error
def initialize(controller_name, method_name, response_code, error_messages, schema, returned_object)
@controller_name = controller_name
@method_name = method_name
@response_code = response_code
@error_messages = error_messages
@schema = schema
@returned_object = returned_object
end

def to_s
"Response does not match swagger schema (#{@controller_name}##{@method_name} #{@response_code}): #{@error_messages}\nSchema: #{JSON(@schema)}\nReturned object: #{@returned_object}"
super("Response does not match swagger schema (#{controller_name}##{method_name} #{response_code}): #{error_messages}\nSchema: #{JSON(schema)}\nReturned object: #{returned_object}")
end
end

class NoDocumentedMethod < Error
def initialize(controller_name, method_name)
@method_name = method_name
@controller_name = controller_name
end

def to_s
"There is no documented method #{@controller_name}##{@method_name}"
super("There is no documented method #{controller_name}##{method_name}")
end
end
end
17 changes: 17 additions & 0 deletions spec/lib/apipie/no_documented_method_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

describe Apipie::NoDocumentedMethod do
let(:error) { described_class.new(controller_name, method_name) }
let(:controller_name) { 'UserController' }
let(:method_name) { 'index' }

describe '#to_s' do
subject { error.to_s }

let(:error_message) do
"There is no documented method #{controller_name}##{method_name}"
end

it { is_expected.to eq(error_message) }
end
end
35 changes: 35 additions & 0 deletions spec/lib/apipie/response_does_not_match_swagger_schema_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'

describe Apipie::ResponseDoesNotMatchSwaggerSchema do
let(:error) do
described_class.new(
controller_name,
method_name,
response_code,
error_messages,
schema,
returned_object
)
end

let(:controller_name) { 'UserController' }
let(:method_name) { 'index' }
let(:response_code) { 200 }
let(:error_messages) { [] }
let(:schema) { {} }
let(:returned_object) { {} }

describe '#to_s' do
subject { error.to_s }

let(:error_message) do
<<~HEREDOC.chomp
Response does not match swagger schema (#{controller_name}##{method_name} #{response_code}): #{error_messages}
Schema: #{JSON(schema)}
Returned object: #{returned_object}
HEREDOC
end

it { is_expected.to eq(error_message) }
end
end

0 comments on commit d5cd745

Please sign in to comment.