Skip to content

Commit

Permalink
Merge branch 'master' into exclude_pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Bogdanović authored Mar 15, 2021
2 parents 162683b + 8bf9bd2 commit d77cad5
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,29 @@ Example of running job 4 out of 32 jobs:
minitest_booster --job 4/32
```

Under the hood, the Minitest Booster uses the following command:
If minitest booster is executed in a scope of a Rails project, the following is
executed:

``` bash
bundle exec rails test <file_list>
```

If minitest booster is running outside of a Rails project, the following is
executed:

``` bash
ruby -e 'ARGV.each { |f| require ".#{f}" }' <file_list>
```

If you want to run a custom command for minitest, use the
`MINITEST_BOOSTER_COMMAND` environment variable:

``` bash
export MINITEST_BOOSTER_COMMAND="bundle exec rake test"
minitest_booster --job 1/42
```

## ExUnit Booster

The `ex_unit_booster` loads all the files that match the `test/**/*_test.exs`
Expand Down
22 changes: 21 additions & 1 deletion lib/test_boosters/boosters/minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,33 @@ def initialize
end

def command
"ruby -e 'ARGV.each { |f| require \"./\#{f}\" }'"
if command_set_with_env_var?
command_from_env_var
elsif rails_app?
"bundle exec rails test"
else
"ruby -e 'ARGV.each { |f| require \"./\#{f}\" }'"
end
end

def split_configuration_path
ENV["MINITEST_SPLIT_CONFIGURATION_PATH"] || "#{ENV["HOME"]}/minitest_split_configuration.json"
end

def command_set_with_env_var?
!command_from_env_var.empty?
end

def command_from_env_var
ENV["MINITEST_BOOSTER_COMMAND"].to_s
end

private

def rails_app?
File.exist?("app") && File.exist?("config") && File.exist?("config/application.rb")
end

end
end
end
2 changes: 1 addition & 1 deletion lib/test_boosters/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TestBoosters
VERSION = "2.5.0".freeze
VERSION = "2.6.0".freeze
end
32 changes: 32 additions & 0 deletions spec/lib/test_boosters/boosters/minitest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,36 @@
end
end
end

describe "#command" do
before do
ENV["MINITEST_BOOSTER_COMMAND"] = "" # reset the environment
end

context "when the command is passed as env var" do
let(:command) { "bundle exec rake test" }

it "uses that command" do
ENV["MINITEST_BOOSTER_COMMAND"] = command

expect(booster.command).to eq(command)
end
end

context "when the command is not passed as env var, but we are in a rails env" do
it "uses a rails specific command" do
allow(booster).to receive(:rails_app?).and_return(true)

expect(booster.command).to eq("bundle exec rails test")
end
end

context "when there is no env command, and not in rails" do
it "uses a 'require' command" do
allow(booster).to receive(:rails_app?).and_return(false)

expect(booster.command).to eq("ruby -e 'ARGV.each { |f| require \"./\#{f}\" }'")
end
end
end
end

0 comments on commit d77cad5

Please sign in to comment.