Skip to content

Commit

Permalink
Simplify tests for test-unit support
Browse files Browse the repository at this point in the history
The Rails application isn't cleaned up between tests so the test-unit
support was bleeding over into other tests. We don't have many tests
that depend on different Rails application state so I'm going with
deleting any created files after each test.

Fixes #22
Closes #32
  • Loading branch information
gaffneyc committed Nov 18, 2024
1 parent 2227859 commit e305c10
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 61 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 2.3.0 / TBD

* [ENHANCEMENT] Add support for test-unit
* [ENHANCEMENT] Add support for Ruby 3.1+ and Rails 7.0+
* [ENHANCEMENT] Drop support for EOL Ruby and Rails versions
* [ENHANCEMENT] Change depdency from all of Rails to just railties
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/templates/test.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"

class <%= class_name %>Test < ActiveSupport::TestCase
# test "the truth" do
Expand Down
29 changes: 29 additions & 0 deletions spec/interactor/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,38 @@ class Invoice::PlaceOrder
end
end
FILE
ensure
remove("spec/rails_helper.rb")
end
end

it "support test unit instead of rspec" do
# Enable test-unit support since it is skipped while generating the app.
write_file "config/initializers/test_unit.rb", <<~FILE
require "rails/test_unit/railtie"
FILE

run_command_and_stop "bundle exec rails generate interactor invoice/place_order"

path = "spec/interactors/invoice/place_order_spec.rb"
expect(path).not_to be_an_existing_file

path = "test/interactors/invoice/place_order_test.rb"
expect(path).to be_an_existing_file

expect(path).to have_file_content(<<~FILE)
require "test_helper"
class Invoice::PlaceOrderTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
FILE
ensure
remove("config/initializers/test_unit.rb")
end

it "auto-loads interactors" do
run_command_and_stop "bundle exec rails generate interactor place_order"
run_command_and_stop "bundle exec rails runner PlaceOrder"
Expand Down
60 changes: 0 additions & 60 deletions spec/interactor/rails_test_unit_spec.rb

This file was deleted.

0 comments on commit e305c10

Please sign in to comment.