├── .github └── workflows │ └── tests.yml ├── .gitignore ├── .rspec ├── CHANGELOG.md ├── CONTRIBUTING.md ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── gemfiles ├── rails-main.gemfile ├── rails70.gemfile ├── rails71.gemfile ├── rails72.gemfile └── rails80.gemfile ├── interactor-rails.gemspec ├── lib ├── generators │ ├── interactor.rb │ ├── interactor │ │ └── organizer_generator.rb │ ├── interactor_generator.rb │ └── templates │ │ ├── interactor.erb │ │ ├── organizer.erb │ │ ├── spec.erb │ │ └── test.erb └── interactor │ └── rails.rb └── spec ├── interactor └── rails_spec.rb ├── spec_helper.rb └── support └── aruba.rb /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Run Tests 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | jobs: 10 | spec: 11 | runs-on: ubuntu-latest 12 | 13 | strategy: 14 | matrix: 15 | ruby_version: 16 | - "3.1" 17 | - "3.2" 18 | - "3.3" 19 | - "3.4" 20 | gemfile: 21 | - "rails70" 22 | - "rails71" 23 | - "rails72" 24 | - "rails80" 25 | exclude: 26 | - ruby_version: "3.1" 27 | gemfile: "rails80" 28 | - ruby_version: "3.4" 29 | gemfile: "rails70" 30 | include: 31 | - ruby_version: "head" 32 | gemfile: "rails-main" 33 | 34 | env: 35 | BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile 36 | 37 | steps: 38 | - uses: actions/checkout@v4 39 | 40 | - name: Set up Ruby 41 | uses: ruby/setup-ruby@v1 42 | with: 43 | ruby-version: ${{ matrix.ruby_version }} 44 | bundler-cache: true 45 | 46 | - name: Run Tests 47 | run: bundle exec rake 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle 2 | /Gemfile.lock 3 | /coverage 4 | /gemfiles/*.gemfile.lock 5 | /pkg 6 | /tmp 7 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --order random 3 | --require spec_helper 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 2.3.0 / 2024-11-18 2 | 3 | * [ENHANCEMENT] Add support for test-unit 4 | * [ENHANCEMENT] Add support for Ruby 3.1+ and Rails 7.0+ 5 | * [ENHANCEMENT] Drop support for EOL Ruby and Rails versions 6 | * [ENHANCEMENT] Change depdency from all of Rails to just railties 7 | * [ENHANCEMENT] Prefer spec/rails_helper.rb when available 8 | * [ENHANCEMENT] Use double quotes in templates 9 | 10 | ## 2.2.0 / 2019-09-01 11 | 12 | * [ENHANCEMENT] Add support for Ruby 2.6 13 | * [ENHANCEMENT] Add support for Rails 6.0+ 14 | 15 | ## 2.2.0 / 2018-04-23 16 | 17 | * [ENHANCEMENT] Add support for Ruby 2.5 18 | * [ENHANCEMENT] Drop support for EOL Ruby version 2.2 19 | * [ENHANCEMENT] Add support for Rails 5.2 20 | 21 | ## 2.1.1 / 2017-05-09 22 | 23 | * [BUGFIX] Properly constrain the gemspec's Rails version requirement 24 | 25 | ## 2.1.0 / 2017-05-09 26 | 27 | * [FEATURE] Add spec templates 28 | * [ENHANCEMENT] Add support for Ruby 2.4 29 | * [ENHANCEMENT] Drop support for EOL Ruby versions 1.9.3, 2.0, and 2.1 30 | * [ENHANCEMENT] Add support for Rails 5.1 31 | * [ENHANCEMENT] Drop support for EOL Rails versions 3.0, 3.1, 3.2, 4.0, and 4.1 32 | 33 | ## 2.0.2 / 2016-03-18 34 | 35 | * [ENHANCEMENT] Add support for Ruby versions 2.1, 2.2, and 2.3 36 | * [ENHANCEMENT] Add support for Rails versions 4.1, 4.2, and 5.0 (beta) 37 | 38 | ## 2.0.1 / 2014-09-08 39 | 40 | * [BUGFIX] Generate nested directories for generated namespaced interactors 41 | 42 | ## 2.0.0 / 2014-09-08 43 | 44 | * [ENHANCEMENT] Update to be play nice with Interactor 3.0 45 | 46 | ## 1.0.1 / 2013-08-19 47 | 48 | * [ENHANCEMENT] Open up the interactor dependency version requirement 49 | * [BUGFIX] Require interactor 50 | * [ENHANCEMENT] Remove the Interactor::Rails module 51 | 52 | ## 1.0.0 / 2013-08-17 53 | 54 | * Initial release! 55 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Interactor Rails 2 | 3 | Interactor Rails is open source and contributions from the community are 4 | encouraged! No contribution is too small. 5 | 6 | Please consider: 7 | 8 | * adding a feature 9 | * squashing a bug 10 | * writing documentation 11 | * reporting an issue 12 | * fixing a typo 13 | * correcting [style](https://github.com/styleguide/ruby) 14 | 15 | ## How do I contribute? 16 | 17 | For the best chance of having your changes merged, please: 18 | 19 | 1. [Fork](https://github.com/collectiveidea/interactor-rails/fork) the project. 20 | 2. [Write](http://en.wikipedia.org/wiki/Test-driven_development) a failing test. 21 | 3. [Commit](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) changes that fix the tests. 22 | 4. [Submit](https://github.com/collectiveidea/interactor-rails/pulls) a pull request with *at least* one animated GIF. 23 | 5. Be patient. 24 | 25 | If your proposed changes only affect documentation, include the following on a 26 | new line in each of your commit messages: 27 | 28 | ``` 29 | [ci skip] 30 | ``` 31 | 32 | This will signal [Travis](https://travis-ci.org) that running the test suite is 33 | not necessary for these changes. 34 | 35 | ## Bug Reports 36 | 37 | If you are experiencing unexpected behavior and, after having read Interactor's 38 | and Interactor Rails' documentation, are convinced this behavior is a bug, 39 | please: 40 | 41 | 1. [Search](https://github.com/collectiveidea/interactor-rails/issues) existing issues. 42 | 2. Collect enough information to reproduce the issue: 43 | * Ruby version 44 | * Rails version 45 | * Interactor version 46 | * Interactor Rails version 47 | * Specific setup conditions 48 | * Description of expected behavior 49 | * Description of actual behavior 50 | 3. [Submit](https://github.com/collectiveidea/interactor-rails/issues/new) an issue. 51 | 4. Be patient. 52 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gemspec 4 | 5 | gem "rails" 6 | 7 | group :test do 8 | gem "aruba" 9 | gem "codeclimate-test-reporter", "~> 1.0" 10 | gem "rspec" 11 | end 12 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Collective Idea 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Interactor Rails 2 | 3 | [![Gem](https://img.shields.io/gem/v/interactor-rails.svg?style=flat-square)](http://rubygems.org/gems/interactor-rails) 4 | [![Build](https://github.com/collectiveidea/interactor-rails/actions/workflows/tests.yml/badge.svg)](https://github.com/collectiveidea/interactor-rails/actions/workflows/tests.yml) 5 | [![Coverage](https://img.shields.io/codeclimate/coverage-letter/collectiveidea/interactor-rails.svg?style=flat-square)](https://codeclimate.com/github/collectiveidea/interactor-rails) 6 | [![Maintainability](https://img.shields.io/codeclimate/maintainability/collectiveidea/interactor-rails.svg?style=flat-square)](https://codeclimate.com/github/collectiveidea/interactor-rails) 7 | 8 | Interactor Rails provides Rails support for the 9 | [Interactor](https://github.com/collectiveidea/interactor) gem. 10 | 11 | ## Installation 12 | 13 | Add this line to your application's Gemfile: 14 | 15 | ```ruby 16 | gem "interactor-rails", "~> 2.0" 17 | ``` 18 | 19 | Interactor Rails is tested against Ruby 3.1 and newer on Rails 7.0 or newer. 20 | For older versions of Ruby and Rails use version 2.2.1. 21 | 22 | ## Usage 23 | 24 | Interactor Rails ensures that `app/interactors` is included in your autoload 25 | paths, and provides generators for your convenience. 26 | 27 | ```bash 28 | rails generate interactor authenticate_user 29 | ``` 30 | 31 | adds to `app/interactors/authenticate_user.rb`: 32 | 33 | ```ruby 34 | class AuthenticateUser 35 | include Interactor 36 | 37 | def call 38 | # TODO 39 | end 40 | end 41 | ``` 42 | 43 | There is also a generator for organizers. 44 | 45 | ```bash 46 | rails generate interactor:organizer place_order charge_card send_thank_you fulfill_order 47 | ``` 48 | 49 | adds to `app/interactors/place_order.rb`: 50 | 51 | ```ruby 52 | class PlaceOrder 53 | include Interactor::Organizer 54 | 55 | organize ChargeCard, SendThankYou, FulfillOrder 56 | end 57 | ``` 58 | 59 | ## Contributions 60 | 61 | Interactor Rails is open source and contributions from the community are 62 | encouraged! No contribution is too small. 63 | 64 | See Interactor Rails' 65 | [contribution guidelines](CONTRIBUTING.md) for more information. 66 | 67 | ## Thank You! 68 | 69 | A very special thank you to [Attila Domokos](https://github.com/adomokos) for 70 | his fantastic work on [LightService](https://github.com/adomokos/light-service). 71 | Interactor is inspired heavily by the concepts put to code by Attila. 72 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require "rspec/core/rake_task" 3 | 4 | RSpec::Core::RakeTask.new(:spec) 5 | 6 | task default: :spec 7 | -------------------------------------------------------------------------------- /gemfiles/rails-main.gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gemspec path: ".." 4 | 5 | gem "rails", github: "rails/rails" 6 | 7 | group :test do 8 | gem "aruba" 9 | gem "codeclimate-test-reporter", "~> 1.0" 10 | gem "rspec" 11 | end 12 | -------------------------------------------------------------------------------- /gemfiles/rails70.gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gemspec path: ".." 4 | 5 | gem "rails", "~> 7.0.0" 6 | 7 | group :test do 8 | gem "aruba" 9 | gem "codeclimate-test-reporter", "~> 1.0" 10 | gem "rspec" 11 | end 12 | -------------------------------------------------------------------------------- /gemfiles/rails71.gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gemspec path: ".." 4 | 5 | gem "rails", "~> 7.1.0" 6 | 7 | group :test do 8 | gem "aruba" 9 | gem "codeclimate-test-reporter", "~> 1.0" 10 | gem "rspec" 11 | end 12 | -------------------------------------------------------------------------------- /gemfiles/rails72.gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gemspec path: ".." 4 | 5 | gem "rails", "~> 7.2.0" 6 | 7 | group :test do 8 | gem "aruba" 9 | gem "codeclimate-test-reporter", "~> 1.0" 10 | gem "rspec" 11 | end 12 | -------------------------------------------------------------------------------- /gemfiles/rails80.gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gemspec path: ".." 4 | 5 | gem "rails", "~> 8.0.0" 6 | 7 | group :test do 8 | gem "aruba" 9 | gem "codeclimate-test-reporter", "~> 1.0" 10 | gem "rspec" 11 | end 12 | -------------------------------------------------------------------------------- /interactor-rails.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Gem::Specification.new do |spec| 4 | spec.name = "interactor-rails" 5 | spec.version = "2.3.0" 6 | 7 | spec.author = "Collective Idea" 8 | spec.email = "info@collectiveidea.com" 9 | spec.description = "Interactor Rails provides Rails support for the Interactor gem." 10 | spec.summary = "Rails support for Interactor" 11 | spec.homepage = "https://github.com/collectiveidea/interactor-rails" 12 | spec.license = "MIT" 13 | 14 | spec.files = `git ls-files`.split($/) 15 | spec.test_files = spec.files.grep(/^spec/) 16 | 17 | spec.add_dependency "interactor", "~> 3.0" 18 | spec.add_dependency "railties", ">= 7.0" 19 | 20 | spec.add_development_dependency "bundler" 21 | spec.add_development_dependency "rake" 22 | end 23 | -------------------------------------------------------------------------------- /lib/generators/interactor.rb: -------------------------------------------------------------------------------- 1 | module Interactor 2 | class Generator < ::Rails::Generators::NamedBase 3 | def self.source_root 4 | File.expand_path("templates", __dir__) 5 | end 6 | 7 | def generate 8 | template "#{self.class.generator_name}.erb", File.join("app/interactors", class_path, "#{file_name}.rb") 9 | 10 | if use_test_unit? 11 | template "test.erb", File.join("test/interactors", class_path, "#{file_name}_test.rb") 12 | else 13 | template "spec.erb", File.join("spec/interactors", class_path, "#{file_name}_spec.rb") 14 | end 15 | end 16 | 17 | def use_test_unit? 18 | ::Rails.application.config.generators.options[:rails][:test_framework] == :test_unit 19 | end 20 | 21 | def rspec_helper_file 22 | if File.exist?("spec/rails_helper.rb") 23 | "rails_helper" 24 | else 25 | "spec_helper" 26 | end 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /lib/generators/interactor/organizer_generator.rb: -------------------------------------------------------------------------------- 1 | require "generators/interactor" 2 | 3 | module Interactor 4 | class OrganizerGenerator < Interactor::Generator 5 | argument :interactors, type: :array, default: [], banner: "name name" 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/generators/interactor_generator.rb: -------------------------------------------------------------------------------- 1 | require "generators/interactor" 2 | 3 | class InteractorGenerator < Interactor::Generator 4 | end 5 | -------------------------------------------------------------------------------- /lib/generators/templates/interactor.erb: -------------------------------------------------------------------------------- 1 | class <%= class_name %> 2 | include Interactor 3 | 4 | def call 5 | # TODO 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/generators/templates/organizer.erb: -------------------------------------------------------------------------------- 1 | class <%= class_name %> 2 | include Interactor::Organizer 3 | 4 | <%- if interactors.any? -%> 5 | organize <%= interactors.map(&:classify).join(", ") %> 6 | <%- else -%> 7 | # organize Interactor1, Interactor2 8 | <%- end -%> 9 | end 10 | -------------------------------------------------------------------------------- /lib/generators/templates/spec.erb: -------------------------------------------------------------------------------- 1 | require "<%= rspec_helper_file %>" 2 | 3 | RSpec.describe <%= class_name %>, type: :interactor do 4 | describe ".call" do 5 | pending "add some examples to (or delete) #{__FILE__}" 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/generators/templates/test.erb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class <%= class_name %>Test < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /lib/interactor/rails.rb: -------------------------------------------------------------------------------- 1 | require "interactor" 2 | -------------------------------------------------------------------------------- /spec/interactor/rails_spec.rb: -------------------------------------------------------------------------------- 1 | module Interactor 2 | describe "Rails" do 3 | before do 4 | run_command_and_stop <<~CMD 5 | bundle exec rails new example \ 6 | --skip-git \ 7 | --skip-keeps \ 8 | --skip-action-mailer \ 9 | --skip-action-mailbox \ 10 | --skip-action-text \ 11 | --skip-action-cable \ 12 | --skip-active-record \ 13 | --skip-active-job \ 14 | --skip-active-storage \ 15 | --skip-asset-pipeline \ 16 | --skip-spring \ 17 | --skip-listen \ 18 | --skip-coffee \ 19 | --skip-javascript \ 20 | --skip-turbolinks \ 21 | --skip-test-unit \ 22 | --skip-test \ 23 | --skip-system-test \ 24 | --skip-bundle \ 25 | --skip-bootsnap \ 26 | --quiet 27 | CMD 28 | 29 | cd "example" 30 | write_file "Gemfile", <<~FILE 31 | gem "rails" 32 | gem "interactor-rails", path: "#{ROOT}" 33 | FILE 34 | 35 | run_command_and_stop "bundle install" 36 | end 37 | 38 | context "rails generate" do 39 | context "interactor" do 40 | it "generates an interactor and spec" do 41 | run_command_and_stop "bundle exec rails generate interactor place_order" 42 | 43 | path = "app/interactors/place_order.rb" 44 | expect(path).to be_an_existing_file 45 | expect(path).to have_file_content(<<~FILE) 46 | class PlaceOrder 47 | include Interactor 48 | 49 | def call 50 | # TODO 51 | end 52 | end 53 | FILE 54 | 55 | path = "spec/interactors/place_order_spec.rb" 56 | expect(path).to be_an_existing_file 57 | expect(path).to have_file_content(<<~FILE) 58 | require "spec_helper" 59 | 60 | RSpec.describe PlaceOrder, type: :interactor do 61 | describe ".call" do 62 | pending "add some examples to (or delete) \#{__FILE__}" 63 | end 64 | end 65 | FILE 66 | end 67 | 68 | it "requires a name" do 69 | run_command_and_stop "bundle exec rails generate interactor" 70 | 71 | expect("app/interactors/place_order.rb").not_to be_an_existing_file 72 | expect(last_command_started.stdout).to include("rails generate interactor NAME") 73 | end 74 | 75 | it "handles namespacing" do 76 | run_command_and_stop "bundle exec rails generate interactor invoice/place_order" 77 | 78 | path = "app/interactors/invoice/place_order.rb" 79 | expect(path).to be_an_existing_file 80 | expect(path).to have_file_content(<<~FILE) 81 | class Invoice::PlaceOrder 82 | include Interactor 83 | 84 | def call 85 | # TODO 86 | end 87 | end 88 | FILE 89 | 90 | path = "spec/interactors/invoice/place_order_spec.rb" 91 | expect(path).to be_an_existing_file 92 | expect(path).to have_file_content(<<~FILE) 93 | require "spec_helper" 94 | 95 | RSpec.describe Invoice::PlaceOrder, type: :interactor do 96 | describe ".call" do 97 | pending "add some examples to (or delete) \#{__FILE__}" 98 | end 99 | end 100 | FILE 101 | end 102 | end 103 | 104 | context "interactor:organizer" do 105 | it "generates an organizer" do 106 | run_command_and_stop <<~CMD 107 | bundle exec rails generate interactor:organizer place_order 108 | CMD 109 | 110 | path = "app/interactors/place_order.rb" 111 | expect(path).to be_an_existing_file 112 | expect(path).to have_file_content(<<~FILE) 113 | class PlaceOrder 114 | include Interactor::Organizer 115 | 116 | # organize Interactor1, Interactor2 117 | end 118 | FILE 119 | 120 | path = "spec/interactors/place_order_spec.rb" 121 | expect(path).to be_an_existing_file 122 | expect(path).to have_file_content(<<~FILE) 123 | require "spec_helper" 124 | 125 | RSpec.describe PlaceOrder, type: :interactor do 126 | describe ".call" do 127 | pending "add some examples to (or delete) \#{__FILE__}" 128 | end 129 | end 130 | FILE 131 | end 132 | 133 | it "generates an organizer with interactors" do 134 | run_command_and_stop <<~CMD 135 | bundle exec rails generate interactor:organizer place_order \ 136 | charge_card fulfill_order 137 | CMD 138 | 139 | path = "app/interactors/place_order.rb" 140 | expect(path).to be_an_existing_file 141 | expect(path).to have_file_content(<<~FILE) 142 | class PlaceOrder 143 | include Interactor::Organizer 144 | 145 | organize ChargeCard, FulfillOrder 146 | end 147 | FILE 148 | end 149 | 150 | it "requires a name" do 151 | run_command_and_stop "bundle exec rails generate interactor:organizer" 152 | 153 | expect("app/interactors/place_order.rb").not_to be_an_existing_file 154 | expect(last_command_started.stdout).to include("rails generate interactor:organizer NAME") 155 | end 156 | 157 | it "handles namespacing" do 158 | run_command_and_stop "bundle exec rails generate interactor:organizer invoice/place_order" 159 | 160 | path = "app/interactors/invoice/place_order.rb" 161 | expect(path).to be_an_existing_file 162 | expect(path).to have_file_content(<<~FILE) 163 | class Invoice::PlaceOrder 164 | include Interactor::Organizer 165 | 166 | # organize Interactor1, Interactor2 167 | end 168 | FILE 169 | 170 | path = "spec/interactors/invoice/place_order_spec.rb" 171 | expect(path).to be_an_existing_file 172 | expect(path).to have_file_content(<<~FILE) 173 | require "spec_helper" 174 | 175 | RSpec.describe Invoice::PlaceOrder, type: :interactor do 176 | describe ".call" do 177 | pending "add some examples to (or delete) \#{__FILE__}" 178 | end 179 | end 180 | FILE 181 | end 182 | end 183 | 184 | it "prefers rails_helper if available" do 185 | write_file "spec/rails_helper.rb", <<~FILE 186 | require "spec_helper" 187 | FILE 188 | 189 | run_command_and_stop "bundle exec rails generate interactor place_order" 190 | 191 | path = "spec/interactors/place_order_spec.rb" 192 | expect(path).to be_an_existing_file 193 | expect(path).to have_file_content(<<~FILE) 194 | require "rails_helper" 195 | 196 | RSpec.describe PlaceOrder, type: :interactor do 197 | describe ".call" do 198 | pending "add some examples to (or delete) \#{__FILE__}" 199 | end 200 | end 201 | FILE 202 | ensure 203 | remove("spec/rails_helper.rb") 204 | end 205 | end 206 | 207 | it "support test unit instead of rspec" do 208 | # Enable test-unit support since it is skipped while generating the app. 209 | write_file "config/initializers/test_unit.rb", <<~FILE 210 | require "rails/test_unit/railtie" 211 | FILE 212 | 213 | run_command_and_stop "bundle exec rails generate interactor invoice/place_order" 214 | 215 | path = "spec/interactors/invoice/place_order_spec.rb" 216 | expect(path).not_to be_an_existing_file 217 | 218 | path = "test/interactors/invoice/place_order_test.rb" 219 | expect(path).to be_an_existing_file 220 | 221 | expect(path).to have_file_content(<<~FILE) 222 | require "test_helper" 223 | 224 | class Invoice::PlaceOrderTest < ActiveSupport::TestCase 225 | # test "the truth" do 226 | # assert true 227 | # end 228 | end 229 | FILE 230 | ensure 231 | remove("config/initializers/test_unit.rb") 232 | end 233 | 234 | it "auto-loads interactors" do 235 | run_command_and_stop "bundle exec rails generate interactor place_order" 236 | run_command_and_stop "bundle exec rails runner PlaceOrder" 237 | end 238 | 239 | it "auto-loads organizers" do 240 | run_command_and_stop "bundle exec rails generate interactor:organizer place_order" 241 | run_command_and_stop "bundle exec rails runner PlaceOrder" 242 | end 243 | end 244 | end 245 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | if ENV["CODECLIMATE_REPO_TOKEN"] 2 | require "simplecov" 3 | SimpleCov.start 4 | end 5 | 6 | require "interactor/rails" 7 | 8 | require "bundler" 9 | Bundler.require(:test) 10 | 11 | ROOT = File.expand_path("../..", __FILE__) 12 | 13 | Dir[File.expand_path("../support/*.rb", __FILE__)].each { |f| require f } 14 | -------------------------------------------------------------------------------- /spec/support/aruba.rb: -------------------------------------------------------------------------------- 1 | require "aruba/api" 2 | 3 | Aruba.configure do |config| 4 | config.exit_timeout = 60 5 | end 6 | 7 | RSpec.configure do |config| 8 | config.include(Aruba::Api) 9 | 10 | config.before do 11 | setup_aruba 12 | end 13 | end 14 | --------------------------------------------------------------------------------