Skip to content

Commit

Permalink
add --create flag
Browse files Browse the repository at this point in the history
  • Loading branch information
pboling committed Jan 14, 2025
1 parent 53b22cd commit 6eae126
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
19 changes: 12 additions & 7 deletions .rubocop_gradual.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
"lib/turbo_tests/reporter.rb:1386902608": [
[7, 5, 400, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 2092085575]
],
"lib/turbo_tests/runner.rb:816710941": [
[12, 5, 798, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 2396047272],
[190, 11, 10, "ThreadSafety/NewThread: Avoid starting new threads.", 3411682361],
[208, 47, 6, "Style/GlobalStdStream: Use `$stderr` instead of `STDERR`.", 3356712163],
[210, 21, 10, "ThreadSafety/NewThread: Avoid starting new threads.", 3411682361],
[219, 7, 10, "ThreadSafety/NewThread: Avoid starting new threads.", 3411682361],
[279, 9, 6, "Style/GlobalStdStream: Use `$stdout` instead of `STDOUT`.", 3356722952]
"lib/turbo_tests/runner.rb:3148178217": [
[13, 5, 271, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 21989008],
[20, 5, 798, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 2396047272],
[198, 11, 10, "ThreadSafety/NewThread: Avoid starting new threads.", 3411682361],
[216, 47, 6, "Style/GlobalStdStream: Use `$stderr` instead of `STDERR`.", 3356712163],
[218, 21, 10, "ThreadSafety/NewThread: Avoid starting new threads.", 3411682361],
[227, 7, 10, "ThreadSafety/NewThread: Avoid starting new threads.", 3411682361],
[287, 9, 6, "Style/GlobalStdStream: Use `$stdout` instead of `STDOUT`.", 3356722952]
],
"spec/cli_spec.rb:43879232": [
[1, 1, 30, "RSpec/SpecFilePathFormat: Spec path should end with `turbo_tests/cli*_spec.rb`.", 965721356],
Expand All @@ -56,6 +57,10 @@
"spec/doc_formatter_spec.rb:233381593": [
[5, 16, 19, "RSpec/DescribeClass: The first argument to describe should be the class or module being tested.", 879596202]
],
"spec/turbo_tests_spec.rb:811756577": [
[10, 15, 7, "RSpec/MessageSpies: Prefer `have_received` for setting message expectations. Setup `ParallelTests::Tasks` as a spy using `allow` or `instance_spy`.", 1384559950],
[20, 15, 7, "RSpec/MessageSpies: Prefer `have_received` for setting message expectations. Setup `ParallelTests::Tasks` as a spy using `allow` or `instance_spy`.", 1384559950]
],
"turbo_tests.gemspec:2105011563": [
[30, 16, 36, "ThreadSafety/DirChdir: Avoid using `Dir.chdir` due to its process-wide effect.", 3576345059],
[31, 5, 19, "Packaging/GemspecGit: Avoid using git to produce lists of files. Downstreams often need to build your package in an environment that does not have git (on purpose). Use some pure Ruby alternative, like `Dir` or `Dir.glob`.", 3879951891]
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ Or install it yourself as:
$ gem install turbo_tests
```

## Setup

Create test databases

```bash
$ bundle exec turbo_tests --create
```

## Usage

Execute tests:
Expand Down Expand Up @@ -97,6 +105,7 @@ Options:
-v, --verbose More output
--fail-fast=[N]
--seed SEED Seed for rspec
--create Create test databases
```

## Development
Expand Down
9 changes: 9 additions & 0 deletions lib/turbo_tests/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def run
verbose = false
fail_fast = nil
seed = nil
create = false

OptionParser.new do |opts|
opts.banner = <<~BANNER
Expand Down Expand Up @@ -85,8 +86,16 @@ def run
opts.on("--seed SEED", "Seed for rspec") do |s|
seed = s
end

opts.on("--create", "Create databases") do
create = true
end
end.parse!(@argv)

if create
return TurboTests::Runner.create(count)
end

requires.each { |f| require(f) }

if formatters.empty?
Expand Down
8 changes: 8 additions & 0 deletions lib/turbo_tests/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

require "json"
require "parallel_tests/rspec/runner"
require "parallel_tests/tasks"

require_relative "../utils/hash_extension"

module TurboTests
class Runner
using CoreExtensions

def self.create(count)
ENV["PARALLEL_TEST_FIRST_IS_1"] = "true"
command = ["bundle", "exec", "rake", "db:create", "RAILS_ENV=#{ParallelTests::Tasks.rails_env}"]
args = {count: count.to_s}
ParallelTests::Tasks.run_in_parallel(command, args)
end

def self.run(opts = {})
files = opts[:files]
formatters = opts[:formatters]
Expand Down
22 changes: 22 additions & 0 deletions spec/turbo_tests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,26 @@
it "has a version number" do
expect(TurboTests::VERSION).not_to be_nil
end

describe "create" do
context "with nil count" do
it "creates databases" do
expect(ParallelTests::Tasks)
.to receive(:run_in_parallel)
.with(["bundle", "exec", "rake", "db:create", "RAILS_ENV=test"], {count: ""})

TurboTests::Runner.create(nil)
end
end

context "with count" do
it "creates databases" do
expect(ParallelTests::Tasks)
.to receive(:run_in_parallel)
.with(["bundle", "exec", "rake", "db:create", "RAILS_ENV=test"], {count: "4"})

TurboTests::Runner.create(4)
end
end
end
end

0 comments on commit 6eae126

Please sign in to comment.