Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rubocop fixes #196

Merged
merged 1 commit into from
Jul 12, 2017
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
8 changes: 7 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ref: default config
# Ref: default config, with minor tweaks
# https://github.com/bbatsov/rubocop/blob/master/config/default.yml
AllCops:
Include:
Expand All @@ -11,3 +11,9 @@ AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
ExtraDetails: true

# Rationale: defalt approach forces us to indent multiline `foo = if bar` statements in an unreasonable way.
Lint/EndAlignment:
EnforcedStyleAlignWith: variable

inherit_from: .rubocop_todo.yml
102 changes: 102 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-07-12 09:10:37 +0300 using RuboCop version 0.49.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: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
Layout/IndentHeredoc:
Exclude:
- 'lib/rack/test/utils.rb'
- 'rack-test.gemspec'

# Offense count: 2
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
Exclude:
- 'lib/rack/test.rb'

# Offense count: 9
Metrics/AbcSize:
Max: 58

# Offense count: 20
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 455

# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 166

# Offense count: 5
Metrics/CyclomaticComplexity:
Max: 13

# Offense count: 75
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 171

# Offense count: 6
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 45

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 124

# Offense count: 3
Metrics/PerceivedComplexity:
Max: 16

# Offense count: 1
Security/Eval:
Exclude:
- 'Thorfile'

# Offense count: 1
Style/CaseEquality:
Exclude:
- 'lib/rack/test.rb'

# Offense count: 4
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'Thorfile'
- 'lib/rack/test.rb'

# Offense count: 2
Style/IdenticalConditionalBranches:
Exclude:
- 'spec/rack/test/multipart_spec.rb'

# Offense count: 1
Style/IfInsideElse:
Exclude:
- 'lib/rack/test/utils.rb'

# Offense count: 2
Style/MethodMissing:
Exclude:
- 'lib/rack/test/mock_digest_request.rb'
- 'lib/rack/test/uploaded_file.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Exclude:
- 'lib/rack/test/cookie_jar.rb'
19 changes: 9 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
require "rubygems"

require 'rubygems'

require 'rspec/core'
require "rspec/core/rake_task"
require 'rspec/core/rake_task'

task default: :spec
task default: %i[spec rubocop]

RSpec::Core::RakeTask.new do |t|
t.pattern = "spec/**/*_spec.rb"
t.ruby_opts = "-w"
t.pattern = 'spec/**/*_spec.rb'
t.ruby_opts = '-w'
end

require 'rubocop/rake_task'
Expand All @@ -23,14 +22,14 @@ RuboCop::RakeTask.new
# t.rcov_opts = ['-x spec']
# end

desc "Generate RDoc"
desc 'Generate RDoc'
task :docs do
FileUtils.rm_rf("doc")
require "rack/test/version"
FileUtils.rm_rf('doc')
require 'rack/test/version'
sh "rdoc --title 'Rack::Test #{Rack::Test::VERSION} API Documentation'"
end

desc 'Removes trailing whitespace'
task :whitespace do
sh %{find . -name '*.rb' -exec sed -i 's/ *$//g' {} \\;}
sh %(find . -name '*.rb' -exec sed -i 's/ *$//g' {} \\;)
end
18 changes: 9 additions & 9 deletions Thorfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module GemHelpers
def read_gemspec
@read_gemspec ||= eval(File.read("rack-test.gemspec"))
@read_gemspec ||= eval(File.read('rack-test.gemspec'))
end

def sh(command)
Expand All @@ -12,19 +12,19 @@ end
class Default < Thor
include GemHelpers

desc "build", "Build a rack-test gem"
desc 'build', 'Build a rack-test gem'
def build
sh "gem build rack-test.gemspec"
FileUtils.mkdir_p "pkg"
FileUtils.mv read_gemspec.file_name, "pkg"
sh 'gem build rack-test.gemspec'
FileUtils.mkdir_p 'pkg'
FileUtils.mv read_gemspec.file_name, 'pkg'
end

desc "install", "Install the latest built gem"
desc 'install', 'Install the latest built gem'
def install
sh "gem install --local pkg/#{read_gemspec.file_name}"
end

desc "release", "Release the current branch to GitHub and RubyGems.org"
desc 'release', 'Release the current branch to GitHub and RubyGems.org'
def release
build
Release.new.tag
Expand All @@ -35,14 +35,14 @@ end
class Release < Thor
include GemHelpers

desc "tag", "Tag the gem on the origin server"
desc 'tag', 'Tag the gem on the origin server'
def tag
release_tag = "v#{read_gemspec.version}"
sh "git tag -a #{release_tag} -m 'Tagging #{release_tag}'"
sh "git push origin #{release_tag}"
end

desc "gem", "Push the gem to RubyGems.org"
desc 'gem', 'Push the gem to RubyGems.org'
def gem
sh "gem push pkg/#{read_gemspec.file_name}"
end
Expand Down
15 changes: 6 additions & 9 deletions lib/rack/mock_session.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module Rack

class MockSession # :nodoc:
attr_writer :cookie_jar
attr_reader :default_host
Expand All @@ -25,16 +24,16 @@ def set_cookie(cookie, uri = nil)
end

def request(uri, env)
env["HTTP_COOKIE"] ||= cookie_jar.for(uri)
env['HTTP_COOKIE'] ||= cookie_jar.for(uri)
@last_request = Rack::Request.new(env)
status, headers, body = @app.call(@last_request.env)

@last_response = MockResponse.new(status, headers, body, env["rack.errors"].flush)
@last_response = MockResponse.new(status, headers, body, env['rack.errors'].flush)
body.close if body.respond_to?(:close)

cookie_jar.merge(last_response.headers["Set-Cookie"], uri)
cookie_jar.merge(last_response.headers['Set-Cookie'], uri)

@after_request.each { |hook| hook.call }
@after_request.each(&:call)

if @last_response.respond_to?(:finish)
@last_response.finish
Expand All @@ -46,21 +45,19 @@ def request(uri, env)
# Return the last request issued in the session. Raises an error if no
# requests have been sent yet.
def last_request
raise Rack::Test::Error.new("No request yet. Request a page first.") unless @last_request
raise Rack::Test::Error, 'No request yet. Request a page first.' unless @last_request
@last_request
end

# Return the last response received in the session. Raises an error if
# no requests have been sent yet.
def last_response
raise Rack::Test::Error.new("No response yet. Request a page first.") unless @last_response
raise Rack::Test::Error, 'No response yet. Request a page first.' unless @last_response
@last_response
end

def cookie_jar
@cookie_jar ||= Rack::Test::CookieJar.new([], @default_host)
end

end

end
Loading