Investigate output: Missing comma in hash or method args
schneems opened this issue · comments
Richard Schneeman commented
describe "webmock tests" do
before(:each) do
WebMock.enable!
end
after(:each) do
WebMock.disable!
end
it "port" do
port = rand(1000...9999)
stub_request(:any, "localhost:#{port}")
query = Cutlass::FunctionQuery.new(
port: port
).call
expect(WebMock).to have_requested(:post, "localhost:#{port}").
with(body: "{}")
end
it "body" do
body = { lol: "hi" }
port = 8080
stub_request(:any, "localhost:#{port}")
query = Cutlass::FunctionQuery.new(
port: port
body: body
).call
expect(WebMock).to have_requested(:post, "localhost:#{port}").
with(body: body.to_json)
end
end
Gives:
1 describe "webmock tests" do
❯ 10 it "port" do
❯ 20 end
❯ 22 it "body" do
❯ 23 body = { lol: "hi" }
❯ 24 port = 8080
❯ 25 stub_request(:any, "localhost:#{port}")
❯ 27 query = Cutlass::FunctionQuery.new(
❯ 28 port: port
❯ 29 body: body
❯ 30 ).call
❯ 34 end
35 end
Which is not ideal, line 28 is missing a comma.
Here's another one:
class FunctionQuery
def headers
{
"Content-Type" => "application/json"
"ce-id" => "MyFunction-#{SecureRandom.hex(10)}",
"ce-time" => "2020-09-03T20:56:28.297915Z",
"ce-type" => "",
"ce-source" => "",
"ce-sfcontext" => sfcontext,
"Authorization" => "",
"ce-specversion" => @spec_version,
"ce-sffncontext" => ssfcontext
}
end
def raw_sfcontext
{
"apiVersion" => "",
"payloadVersion" => "",
"userContext" =>
{
"orgId" => "",
"userId" => "",
"username" => "",
"orgDomainUrl" => "",
"onBehalfOfUserId" => nil,
"salesforceBaseUrl" => ""
}
}
end
end
Which gives:
DeadEnd: Unmatched `}` character detected
This code has an unmatched `}`. Ensure that opening curl braces are
closed: `{ }`.
file: /private/tmp/scratch.rb
simplified:
1 class FunctionQuery
2 def headers
3 {
❯ 4 "Content-Type" => "application/json"
❯ 5 "ce-id" => "MyFunction-#{SecureRandom.hex(10)}",
❯ 6 "ce-time" => "2020-09-03T20:56:28.297915Z",
❯ 7 "ce-type" => "",
❯ 8 "ce-source" => "",
❯ 9 "ce-sfcontext" => sfcontext,
❯ 10 "Authorization" => "",
❯ 11 "ce-specversion" => @spec_version,
13 }
14 end
16 def raw_sfcontext
❯ 17 {
❯ 18 "apiVersion" => "",
❯ 19 "payloadVersion" => "",
❯ 20 "userContext" =>
❯ 29 }
30 end
31 end
The problem is after "Content-Type" => "application/json"
(missing a comma).
Richard Schneeman commented
This is not ideal: We're introducing a syntax error by removing this line due to a trailing period:
21
22 it "body" do
23 body = { lol: "hi" }
24 port = 8080
25 stub_request(:any, "localhost:#{port}")
26
27 query = Cutlass::FunctionQuery.new(
28 port: port
29 body: body
30 ).call
31
32 expect(WebMock).to have_requested(:post, "localhost:#{port}").
❯ 33 with(body: body.to_json)
34 end
35 end
Then on 10-expand-1 this expansion and removal seems bad:
22 it "body" do
23 body = { lol: "hi" }
24 port = 8080
25 stub_request(:any, "localhost:#{port}")
26
27 query = Cutlass::FunctionQuery.new(
28 port: port
29 body: body
30 ).call
31
❯ 32 expect(WebMock).to have_requested(:post, "localhost:#{port}").
❯ 34 end
35 end