Skip to content

Commit b3cd190

Browse files
authored
Add integration test for annotating a singular file (#64)
This PR builds on top of the integration tests in #60 and adds a test for annotating a single file: `bundle exec annotaterb models app/models/test_default.rb`
1 parent e988ea4 commit b3cd190

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ end
1515

1616
task spec: ["spec:unit", "spec:integration"]
1717

18-
task default: :spec
18+
task default: ["spec:unit"]

spec/dummyapp/Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ group :development do
3838
# Use console on exceptions pages [https://github.com/rails/web-console]
3939
gem "web-console"
4040

41+
gem "pry-byebug"
42+
4143
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
4244
# gem "rack-mini-profiler"
4345

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

Comments
 (0)