Faraday: κΈ°λŠ₯ μš”μ²­: `Faraday::Adapter::Test`μ—μ„œ `Faraday::FlatParamsEncoder` 지원

에 λ§Œλ“  2021λ…„ 08μ›” 19일  Β·  4μ½”λ©˜νŠΈ  Β·  좜처: lostisland/faraday

1291 λ„μž… strict_mode 에 Faraday::Adapter::Test::Stubs , λ‚˜λŠ” λͺ¨λ“œμ— λŒ€ν•œ 더 λ§Žμ€ κΈ°λŠ₯을 μ›ν•˜λŠ” : 지원 Faraday::FlatParamsEncoder . 예λ₯Ό λ“€μ–΄ λ™μΌν•œ 쿼리 λ§€κ°œλ³€μˆ˜ a ν•˜μ—¬ HTTP μš”μ²­μ„ μ—¬λŸ¬ 번 ν˜ΈμΆœν•˜λ €λŠ” 경우 ν…ŒμŠ€νŠΈ μŠ€ν…μ—μ„œ 값이 λ‹€λ₯Έ λ™μΌν•œ λ§€κ°œλ³€μˆ˜κ°€ λͺ¨λ‘ μ˜¬λ°”λ₯΄κ²Œ μ „λ‹¬λ˜μ—ˆλŠ”μ§€ 확인해야 ν•©λ‹ˆλ‹€.

class Client
  def initialize(conn)
    <strong i="10">@conn</strong> = conn
  end

  def sushi(jname, params: {})
    res = @conn.get("/#{jname}", params)
    data = JSON.parse(res.body)
    data['name']
  end
end

RSpec.describe Client do
  let(:stubs) { Faraday::Adapter::Test::Stubs.new(strict_mode: true) }
  let(:conn)   { Faraday.new(request: { params_encoder: Faraday::FlatParamsEncoder }) { |b| b.adapter(:test, stubs) } }
  let(:client) { Client.new(conn) }

  it 'handles the same multiple URL parameters' do
    # The same parameter `a` is expected to appear multiple times with different values.
    stubs.get('/ebi?a=x&a=y&a=z') { [200, { 'Content-Type' => 'application/json' }, '{"name": "shrimp"}'] }

    # Test should pass
    expect(client.sushi('ebi', params: { a: %w[x y z] })).to eq('shrimp')

    # Test should not pass due to the lack of "x" and "y" for `a`
    # expect(client.sushi('ebi', params: { a: %w[z] })).to eq('shrimp')
    stubs.verify_stubbed_calls
  end
end

μ–΄λ–»κ²Œ μƒκ°ν•˜λ‚˜μš”? μ˜λ―Έκ°€ μžˆλ‹€λ©΄ ν’€ λ¦¬ν€˜μŠ€νŠΈλ₯Ό μ—΄κ³  μ‹ΆμŠ΅λ‹ˆλ‹€.

feature help wanted

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

λ˜ν•œ main λΆ„κΈ°κ°€ 이제 곧 μΆœμ‹œλ  v2.0 릴리슀λ₯Ό 가리킀고 μžˆμŒμ„ κΈ°μ–΅ν•˜μ‹­μ‹œμ˜€.
1.x λ¦΄λ¦¬μŠ€μ—μ„œλ„ 이것을 μ›ν•˜λ©΄ 1.x λΆ„κΈ°λ₯Ό λΆ„κΈ°ν•΄μ•Ό ν•©λ‹ˆλ‹€. πŸ‘

λͺ¨λ“  4 λŒ“κΈ€

μ•ˆλ…•ν•˜μ„Έμš” @yykamei , μœ„μ˜ λ‚΄μš©μ΄ 이해가 λ©λ‹ˆλ‹€. PR을 ν™˜μ˜ν•©λ‹ˆλ‹€.
ν˜ΈκΈ°μ‹¬μ—μ„œ ν˜„μž¬ μœ„μ˜ ν…ŒμŠ€νŠΈμ—μ„œ μ–΄λ–€ 일이 λ°œμƒν•©λ‹ˆκΉŒ? λ§ˆμ§€λ§‰μ€ μ§€λ‚˜κ°€λ‚˜μš”?

λ˜ν•œ main λΆ„κΈ°κ°€ 이제 곧 μΆœμ‹œλ  v2.0 릴리슀λ₯Ό 가리킀고 μžˆμŒμ„ κΈ°μ–΅ν•˜μ‹­μ‹œμ˜€.
1.x λ¦΄λ¦¬μŠ€μ—μ„œλ„ 이것을 μ›ν•˜λ©΄ 1.x λΆ„κΈ°λ₯Ό λΆ„κΈ°ν•΄μ•Ό ν•©λ‹ˆλ‹€. πŸ‘

μ•ˆλ…•ν•˜μ„Έμš” @iMacTia , λ‹΅λ³€ κ°μ‚¬ν•©λ‹ˆλ‹€.

ν˜ΈκΈ°μ‹¬μ—μ„œ ν˜„μž¬ μœ„μ˜ ν…ŒμŠ€νŠΈμ—μ„œ μ–΄λ–€ 일이 λ°œμƒν•©λ‹ˆκΉŒ? λ§ˆμ§€λ§‰μ€ μ§€λ‚˜κ°€λ‚˜μš”?

μ•„, μ΅œμ‹  1.x 브랜치λ₯Ό ν†΅κ³Όν•˜μ§€ λͺ»ν•œ 것 κ°™μŠ΅λ‹ˆλ‹€. Stub#params κ°€ Faraday::Utils.parse_nested_query κ΅¬μ„±λ˜μ—ˆκΈ° λ•Œλ¬Έμ΄λΌκ³  μƒκ°ν•©λ‹ˆλ‹€. 이전 쿼리 λ§€κ°œλ³€μˆ˜λ₯Ό μž¬μ •μ˜ν•˜λŠ” κ²ƒμ²˜λŸΌ λ³΄μž…λ‹ˆλ‹€.

Randomized with seed 45661

Client
  handles the same multiple URL parameters (FAILED - 1)

Failures:

  1) Client handles the same multiple URL parameters
     Failure/Error:
       raise Stubs::NotFound, "no stubbed request for #{env[:method]} "\
                              "#{normalized_path} #{env[:body]}"

     Faraday::Adapter::Test::Stubs::NotFound:
       no stubbed request for get /ebi?a=x
     # ./lib/faraday/adapter/test.rb:253:in `call'
     # ./lib/faraday/rack_builder.rb:154:in `build_response'
     # ./lib/faraday/connection.rb:511:in `run_request'
     # ./lib/faraday/connection.rb:200:in `get'
     # ./ok.rb:11:in `sushi'
     # ./ok.rb:30:in `block (2 levels) in <top (required)>'

Finished in 0.00391 seconds (files took 0.78136 seconds to load)
1 example, 1 failure

Failed examples:

ν•˜μ§€λ§Œ μ΄λ ‡κ²Œ μ½”λ“œλ₯Ό λ³€κ²½ν•˜λ©΄ ν…ŒμŠ€νŠΈλŠ” ν†΅κ³Όν•©λ‹ˆλ‹€. 문제 μ„€λͺ…을 λ‹€μ‹œ μž‘μ„±ν–ˆμŠ΅λ‹ˆλ‹€.

diff --git a/a.rb b/a.rb
index c4b7084..91d795d 100644
--- a/a.rb
+++ b/a.rb
@@ -27,7 +27,7 @@ RSpec.describe Client do
     expect(client.sushi('ebi', params: { a: %w[x y z] })).to eq('shrimp')

     # Test should not pass due to the lack of "y" and "z" for `a`
-    expect(client.sushi('ebi', params: { a: %w[x] })).to eq('shrimp')
+    expect(client.sushi('ebi', params: { a: %w[z] })).to eq('shrimp')
     stubs.verify_stubbed_calls
   end
 end

μ–΄μ¨Œλ“  κ°μ‚¬ν•©λ‹ˆλ‹€. πŸ’ͺ μ•½κ°„μ˜ μˆ˜μ •μ„ κ°€ν•©λ‹ˆλ‹€.

이 λ¬Έμ œλŠ” #1316으둜 ν•΄κ²°λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

κ°μ‚¬ν•©λ‹ˆλ‹€!

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰