Skip to content

Investigate output: Missing comma in hash or method args #64

@schneems

Description

@schneems
    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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions