Skip to content

Commit

Permalink
chore: Layout/BlockEndNewline, Layout/MultilineBlockLayout (#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
olleolleolle committed Feb 25, 2019
1 parent cbbce86 commit d579431
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
30 changes: 7 additions & 23 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-02-25 23:40:42 +0100 using RuboCop version 0.65.0.
# on 2019-02-25 23:59:49 +0100 using RuboCop version 0.65.0.
# 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: 2
# Cop supports --auto-correct.
Layout/BlockEndNewline:
Exclude:
- 'spec/faraday/request/multipart_spec.rb'

# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
Expand Down Expand Up @@ -76,12 +70,6 @@ Layout/IndentHash:
Exclude:
- 'spec/support/streaming_response_checker.rb'

# Offense count: 2
# Cop supports --auto-correct.
Layout/MultilineBlockLayout:
Exclude:
- 'spec/faraday/request/multipart_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
Layout/RescueEnsureAlignment:
Expand Down Expand Up @@ -365,7 +353,7 @@ Style/AndOr:
- 'test/adapters/em_http_test.rb'
- 'test/helper.rb'

# Offense count: 15
# Offense count: 13
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
Expand All @@ -381,7 +369,6 @@ Style/BlockDelimiters:
- 'lib/faraday/connection.rb'
- 'lib/faraday/rack_builder.rb'
- 'lib/faraday/utils.rb'
- 'spec/faraday/request/multipart_spec.rb'
- 'spec/faraday/request/url_encoded_spec.rb'
- 'spec/faraday/utils_spec.rb'
- 'spec/support/fake_safe_buffer.rb'
Expand Down Expand Up @@ -524,24 +511,22 @@ Style/ExpandPathArguments:
- 'test/adapters/test_middleware_test.rb'
- 'test/helper.rb'

# Offense count: 4
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: format, sprintf, percent
Style/FormatString:
Exclude:
- 'lib/faraday/encoders/nested_params_encoder.rb'
- 'spec/faraday/request/multipart_spec.rb'
- 'test/adapters/integration.rb'
- 'test/live_server.rb'

# Offense count: 10
# Offense count: 9
# Configuration parameters: EnforcedStyle.
# SupportedStyles: annotated, template, unannotated
Style/FormatStringToken:
Exclude:
- 'lib/faraday/encoders/nested_params_encoder.rb'
- 'spec/faraday/request/multipart_spec.rb'
- 'test/adapters/integration.rb'
- 'test/live_server.rb'

Expand Down Expand Up @@ -569,7 +554,7 @@ Style/GuardClause:
- 'lib/faraday/request/url_encoded.rb'
- 'lib/faraday/utils/headers.rb'

# Offense count: 162
# Offense count: 154
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Expand Down Expand Up @@ -916,7 +901,7 @@ Style/StructInheritance:
Style/SymbolArray:
EnforcedStyle: brackets

# Offense count: 8
# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods.
# IgnoredMethods: respond_to, define_method
Expand All @@ -925,7 +910,6 @@ Style/SymbolProc:
- 'lib/faraday/options.rb'
- 'lib/faraday/upload_io.rb'
- 'lib/faraday/utils/headers.rb'
- 'spec/faraday/request/multipart_spec.rb'
- 'spec/support/helper_methods.rb'
- 'test/shared.rb'

Expand Down Expand Up @@ -973,7 +957,7 @@ Style/YodaCondition:
- 'script/proxy-server'
- 'test/helper.rb'

# Offense count: 283
# Offense count: 279
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Expand Down
47 changes: 36 additions & 11 deletions spec/faraday/request/multipart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
response = conn.post('/echo', payload)

expect(response.body).to be_a_kind_of(Faraday::CompositeReadIO)
match = 'multipart/form-data; boundary=%s' % Faraday::Request::Multipart::DEFAULT_BOUNDARY_PREFIX
match = format(
'multipart/form-data; boundary=%<boundary>s',
boundary: Faraday::Request::Multipart::DEFAULT_BOUNDARY_PREFIX
)
expect(response.headers['Content-Type']).to start_with(match)

response.body.send(:ios).map { |io| io.read }.each do |io|
response.body.send(:ios).map(&:read).each do |io|
re = regexes.detect { |r| io =~ r }
regexes.delete(re) if re
end
Expand All @@ -34,25 +37,47 @@
it 'generates a unique boundary for each request' do
response1 = conn.post('/echo', payload)
response2 = conn.post('/echo', payload)
expect(response1.headers['Content-Type']).not_to eq(response2.headers['Content-Type'])
expect(response1.headers['Content-Type']).not_to eq(
response2.headers['Content-Type']
)
end
end

context 'when multipart objects in param' do
let(:regexes) { [/name\=\"a\"/,
/name=\"b\[c\]\"\; filename\=\"multipart_spec\.rb\"/,
/name=\"b\[d\]\"/] }
let(:regexes) do
[/name\=\"a\"/,
/name=\"b\[c\]\"\; filename\=\"multipart_spec\.rb\"/,
/name=\"b\[d\]\"/]
end

let(:payload) { { :a => 1, :b => { :c => Faraday::UploadIO.new(__FILE__, 'text/x-ruby'), :d => 2 } } }
let(:payload) do
{
a: 1,
b: {
c: Faraday::UploadIO.new(__FILE__, 'text/x-ruby'),
d: 2
}
}
end
it_behaves_like 'a multipart request'
end

context 'when multipart objects in array param' do
let(:regexes) { [/name\=\"a\"/,
/name=\"b\[\]\[c\]\"\; filename\=\"multipart_spec\.rb\"/,
/name=\"b\[\]\[d\]\"/] }
let(:regexes) do
[/name\=\"a\"/,
/name=\"b\[\]\[c\]\"\; filename\=\"multipart_spec\.rb\"/,
/name=\"b\[\]\[d\]\"/]
end

let(:payload) { { :a => 1, :b => [{ :c => Faraday::UploadIO.new(__FILE__, 'text/x-ruby'), :d => 2 }] } }
let(:payload) do
{
a: 1,
b: [{
c: Faraday::UploadIO.new(__FILE__, 'text/x-ruby'),
d: 2
}]
}
end
it_behaves_like 'a multipart request'
end
end

0 comments on commit d579431

Please sign in to comment.