Files
ubicloud/spec/routes/api/cli/spec_helper.rb
Jeremy Evans aa7da16986 Consistently use ! to begin cli error messages
This adds an assertion that the body begins with "! " for 400
responses, and then updates the few places that didn't already
do that.
2025-02-19 10:25:42 -08:00

35 lines
1.2 KiB
Ruby

# frozen_string_literal: true
require_relative "../spec_helper"
RSpec.configure do |config|
def cli(argv, status: 200, env: {}, confirm_prompt: nil, command_execute: nil)
post("/cli", {"argv" => argv}.to_json, env)
expect(last_response.status).to eq(status), "status is #{last_response.status} not #{status}, body for failing status: #{last_response.body}"
if status == 400
expect(last_response.body).to start_with("! ")
end
expect(last_response["content-type"]).to eq("text/plain")
expect(last_response["ubi-command-execute"]).to eq(command_execute) if command_execute
expect(last_response["ubi-confirm"]).to eq(confirm_prompt) if confirm_prompt
last_response.body
end
def cli_exec(argv, env: {})
body = cli(argv, env:)
[last_response.headers["ubi-command-execute"], *body.split("\0")]
end
config.define_derived_metadata(file_path: %r{\A\./spec/routes/api/cli/}) do |metadata|
metadata[:clover_cli] = true
end
config.before do |example|
next unless example.metadata[:clover_cli]
header "Accept", "text/plain"
@account = create_account
@use_pat = true
@project = project_with_default_policy(@account, name: "project-1")
end
end