Skip to content

Commit

Permalink
Improve specs
Browse files Browse the repository at this point in the history
- Use subject to shorten expectations
- Use `rails` instead of `rake`

Close #329
  • Loading branch information
tagliala committed Sep 12, 2024
1 parent abcb6cf commit 2ca3986
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
7 changes: 4 additions & 3 deletions spec/aruba/dbconsole_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
require 'spec_helper'

RSpec.describe 'rails dbconsole', type: :aruba do
subject { action && last_command_started }

let(:action) { run_command("bash -c \"echo 'select 1 as foo_column; \\q' | bundle exec rails db\"") }
let(:last_command) { action && last_command_started }

before { copy_db_config }

it { expect(last_command).to be_successfully_executed }
it { expect(last_command).to have_output(/\bfoo_column\b/) }
it { is_expected.to be_successfully_executed }
it { is_expected.to have_output(/\bfoo_column\b/) }
end
31 changes: 17 additions & 14 deletions spec/aruba/migrations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,37 @@
context 'when a migration is generated' do
before { run_command_and_stop('bundle exec rails g migration CreateModels name:string') }

describe 'bundle exec rake db:migrate' do
let(:action) { run_command('bundle exec rake db:migrate') }
let(:last_command) { action && last_command_started }
describe 'bundle exec rails db:migrate' do
subject { action && last_command_started }

it { expect(last_command).to be_successfully_executed }
it { expect(last_command).to have_output(/CreateModels: migrated/) }
let(:action) { run_command('bundle exec rails db:migrate') }

it { is_expected.to be_successfully_executed }
it { is_expected.to have_output(/CreateModels: migrated/) }
end
end

describe 'rerun bundle exec rake db:drop db:create db:migrate', issue: 56 do
let(:command) { 'bundle exec rake db:drop db:create db:migrate' }
describe 'rerun bundle exec rails db:drop db:create db:migrate', issue: 56 do
subject { action && last_command_started }

let(:command) { 'bundle exec rails db:drop db:create db:migrate' }
let(:action) { run_command(command) }
let(:regex) { /-- change_table\(:impressions, {:temporal=>true, :copy_data=>true}\)/ }

before { copy('%/migrations/56/', 'db/migrate') }

describe 'once' do
let(:last_command) { action && last_command_started }

it { expect(last_command).to be_successfully_executed }
it { expect(last_command).to have_output(regex) }
it { is_expected.to be_successfully_executed }
it { is_expected.to have_output(regex) }
end

describe 'twice' do
let(:last_command) { run_command_and_stop(command) && action && last_command_started }
before do
action
end

it { expect(last_command).to be_successfully_executed }
it { expect(last_command).to have_output(regex) }
it { is_expected.to be_successfully_executed }
it { is_expected.to have_output(regex) }
end
end
end
23 changes: 13 additions & 10 deletions spec/aruba/rake_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@
end

describe dump_schema_task.to_s do
subject { last_command_started }

let(:db_file) { 'db/test.sql' }

before do
copy_db_config
run_command_and_stop("bundle exec rake #{dump_schema_task} SCHEMA=db/test.sql")
run_command_and_stop("bundle exec rails #{dump_schema_task} SCHEMA=db/test.sql")
end

it { expect(last_command_started).to be_successfully_executed }
it { is_expected.to be_successfully_executed }
it { expect(db_file).to be_an_existing_file }
it { expect(db_file).not_to have_file_content(/\A--/) }

context 'with schema_search_path option' do
before do
copy_db_config('database_with_schema_search_path.yml')
run_command_and_stop("bundle exec rake #{dump_schema_task} SCHEMA=db/test.sql")
run_command_and_stop("bundle exec rails #{dump_schema_task} SCHEMA=db/test.sql")
end

it 'includes chronomodel schemas' do
Expand All @@ -51,15 +53,16 @@
before do
copy_db_config
copy('%/set_config.sql', 'db/test.sql')
run_command_and_stop('bundle exec rake db:schema:load SCHEMA=db/test.sql')
run_command_and_stop('bundle exec rails db:schema:load SCHEMA=db/test.sql')
end

it { expect(last_command_started).to be_successfully_executed }
end

describe load_schema_task.to_s do
let(:action) { run_command("bundle exec rake #{load_schema_task}") }
let(:last_command) { action && last_command_started }
subject { action && last_command_started }

let(:action) { run_command("bundle exec rails #{load_schema_task}") }

context 'with db/structure.sql' do
before do
Expand All @@ -86,13 +89,13 @@
end
end

it { expect(last_command).to be_successfully_executed }
it { is_expected.to be_successfully_executed }
end

context 'without a specified username and password', issue: 55 do
before { copy_db_config }

it { expect(last_command).to be_successfully_executed }
it { is_expected.to be_successfully_executed }
end
end
end
Expand All @@ -101,7 +104,7 @@
before do
copy_db_config
copy('%/set_config.sql', 'db/test.sql')
run_command_and_stop('bundle exec rake db:data:dump DUMP=db/test.sql')
run_command_and_stop('bundle exec rails db:data:dump DUMP=db/test.sql')
end

it { expect(last_command_started).to be_successfully_executed }
Expand All @@ -112,7 +115,7 @@
before do
copy_db_config
copy('%/empty_structure.sql', 'db/test.sql')
run_command_and_stop('bundle exec rake db:data:load DUMP=db/test.sql')
run_command_and_stop('bundle exec rails db:data:load DUMP=db/test.sql')
end

it { expect(last_command_started).to be_successfully_executed }
Expand Down
3 changes: 2 additions & 1 deletion spec/aruba/subclasses_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
require 'spec_helper'

RSpec.describe 'subclasses spec', type: :aruba do
subject(:last_command) { action && last_command_started }

let(:action) { run_command('bundle exec rails runner "Foo.subclasses"') }
let(:last_command) { action && last_command_started }

before do
set_environment_variable 'CM_TEST_EAGER_LOAD', true
Expand Down

0 comments on commit 2ca3986

Please sign in to comment.