|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "integration_spec_helper" |
| 4 | + |
| 5 | +RSpec.describe "Annotate a single file", type: "aruba" do |
| 6 | + let(:models_dir) { "app/models" } |
| 7 | + let(:command_timeout_seconds) { 10 } |
| 8 | + |
| 9 | + before do |
| 10 | + copy(Dir[File.join(aruba.config.root_directory, "spec/dummyapp/*")], aruba.config.home_directory) |
| 11 | + |
| 12 | + # Unset the bundler context from running annotaterb integration specs. |
| 13 | + # This way, when `run_command("bundle exec annotaterb")` runs, it runs as if it's within the context of dummyapp. |
| 14 | + unset_bundler_env_vars |
| 15 | + end |
| 16 | + |
| 17 | + let(:templates_dir) { File.join(aruba.config.root_directory, "spec/templates/#{ENV["DATABASE_ADAPTER"]}") } |
| 18 | + let(:model_file) { "app/models/test_default.rb" } |
| 19 | + |
| 20 | + it "annotates a single file" do |
| 21 | + expected_test_default = read(File.join(templates_dir, "test_default.rb")).join("\n") |
| 22 | + expected_test_null_false = read(File.join(templates_dir, "test_null_false.rb")).join("\n") |
| 23 | + |
| 24 | + original_test_default = read(File.join(models_dir, "test_default.rb")).join("\n") |
| 25 | + original_test_null_false = read(File.join(models_dir, "test_null_false.rb")).join("\n") |
| 26 | + |
| 27 | + # Check that files have been copied over correctly |
| 28 | + expect(expected_test_default).not_to eq(original_test_default) |
| 29 | + expect(expected_test_null_false).not_to eq(original_test_null_false) |
| 30 | + |
| 31 | + _cmd = run_command_and_stop("bundle exec annotaterb models #{model_file}", fail_on_error: true, exit_timeout: command_timeout_seconds) |
| 32 | + |
| 33 | + annotated_test_default = read(File.join(models_dir, "test_default.rb")).join("\n") |
| 34 | + annotated_test_null_false = read(File.join(models_dir, "test_null_false.rb")).join("\n") |
| 35 | + |
| 36 | + expect(last_command_started).to be_successfully_executed |
| 37 | + expect(annotated_test_default).to eq(expected_test_default) |
| 38 | + expect(annotated_test_null_false).not_to eq(expected_test_null_false) |
| 39 | + end |
| 40 | +end |
0 commit comments