|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "test_helper" |
| 4 | + |
| 5 | +class ClaudeFinalizeTest < GeneratorTestCase |
| 6 | + template <<~'CODE' |
| 7 | + DOCKER_DEV_ROOT = ".dockerdev" |
| 8 | + todos = [ |
| 9 | + "📝 Important things to take care of:", |
| 10 | + " - Make sure you have `ENV[\"RAILS_ENV\"] = \"test\"` (not `ENV[\"RAILS_ENV\"] ||= \"test\"`) in your test helper.", |
| 11 | + " - Don't forget to add DATABASE_URL to your database.yml" |
| 12 | + ] |
| 13 | +
|
| 14 | + <%= include "claude_finalize" %> |
| 15 | + CODE |
| 16 | + |
| 17 | + def setup |
| 18 | + super |
| 19 | + @mock_bin = File.expand_path("../fixtures/bin", __dir__) |
| 20 | + @claude_output_file = File.join(TMP_DIR, "claude_args.txt") |
| 21 | + end |
| 22 | + |
| 23 | + def test_runs_claude_with_correct_arguments |
| 24 | + original_path = ENV["PATH"] |
| 25 | + ENV["PATH"] = "#{@mock_bin}:#{original_path}" |
| 26 | + ENV["CLAUDE_MOCK_OUTPUT"] = @claude_output_file |
| 27 | + |
| 28 | + begin |
| 29 | + run_generator(input: ["y"]) # "y" for yes? prompt |
| 30 | + ensure |
| 31 | + ENV["PATH"] = original_path |
| 32 | + ENV.delete("CLAUDE_MOCK_OUTPUT") |
| 33 | + end |
| 34 | + |
| 35 | + assert File.exist?(@claude_output_file), "Mock claude should have been called" |
| 36 | + |
| 37 | + args = File.read(@claude_output_file) |
| 38 | + |
| 39 | + # Check --allowedTools flag and tools |
| 40 | + assert_includes args, "--allowedTools" |
| 41 | + assert_includes args, "Read" |
| 42 | + assert_includes args, "Edit" |
| 43 | + assert_includes args, "Write" |
| 44 | + assert_includes args, "Grep" |
| 45 | + assert_includes args, "Bash(git *)" |
| 46 | + |
| 47 | + # Check prompt content includes todos |
| 48 | + assert_includes args, "Ruby on Whales" |
| 49 | + assert_includes args, "TODOs to complete" |
| 50 | + assert_includes args, "Important things to take care of" |
| 51 | + assert_includes args, "ENV[\"RAILS_ENV\"] = \"test\"" |
| 52 | + assert_includes args, "DATABASE_URL" |
| 53 | + |
| 54 | + # Check prompt includes references |
| 55 | + assert_includes args, "evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development" |
| 56 | + assert_includes args, "system-of-a-test" |
| 57 | + assert_includes args, "vite-lizing-rails" |
| 58 | + end |
| 59 | + |
| 60 | + def test_skips_when_user_declines |
| 61 | + original_path = ENV["PATH"] |
| 62 | + ENV["PATH"] = "#{@mock_bin}:#{original_path}" |
| 63 | + ENV["CLAUDE_MOCK_OUTPUT"] = @claude_output_file |
| 64 | + |
| 65 | + begin |
| 66 | + run_generator(input: ["n"]) # "n" for no |
| 67 | + ensure |
| 68 | + ENV["PATH"] = original_path |
| 69 | + ENV.delete("CLAUDE_MOCK_OUTPUT") |
| 70 | + end |
| 71 | + |
| 72 | + refute File.exist?(@claude_output_file), "Mock claude should not have been called when user declines" |
| 73 | + end |
| 74 | + |
| 75 | + def test_skips_when_claude_unavailable |
| 76 | + # Don't add mock bin to PATH, so claude won't be found |
| 77 | + ENV["CLAUDE_MOCK_OUTPUT"] = @claude_output_file |
| 78 | + original_path = ENV["PATH"] |
| 79 | + ENV["PATH"] = __dir__ |
| 80 | + |
| 81 | + begin |
| 82 | + run_generator(input: []) # No input needed since prompt won't appear |
| 83 | + ensure |
| 84 | + ENV["PATH"] = original_path |
| 85 | + ENV.delete("CLAUDE_MOCK_OUTPUT") |
| 86 | + end |
| 87 | + |
| 88 | + refute File.exist?(@claude_output_file), "Mock claude should not have been called when unavailable" |
| 89 | + end |
| 90 | +end |
0 commit comments