Commit 5e5df4b2 authored by pbair's avatar pbair

Alter task spec to better test behavior

parent 419d61da
......@@ -100,26 +100,39 @@ describe 'gitlab:db namespace rake task' do
describe 'clean_structure_sql' do
let_it_be(:clean_rake_task) { 'gitlab:db:clean_structure_sql' }
let_it_be(:test_task_name) { 'gitlab:db:_test_multiple_structure_cleans' }
let_it_be(:structure_file) { 'db/structure.sql' }
let_it_be(:input) { 'this is structure data' }
let(:output) { StringIO.new }
it 'reenables the task after running' do
before do
allow(File).to receive(:read).with(structure_file).and_return(input)
allow(File).to receive(:open).with(structure_file, any_args).and_yield(output)
expect_any_instance_of(Gitlab::Database::SchemaCleaner).to receive(:clean).with(output)
end
after do
Rake::Task[test_task_name].clear if Rake::Task.task_defined?(test_task_name)
end
run_rake_task(clean_rake_task) do |rake_task|
expect(rake_task).to receive(:reenable)
it 'can be executed multiple times within another rake task' do
Rake::Task.define_task(test_task_name => :environment) do
expect_next_instance_of(Gitlab::Database::SchemaCleaner) do |cleaner|
expect(cleaner).to receive(:clean).with(output)
end
Rake::Task[clean_rake_task].invoke
expect_next_instance_of(Gitlab::Database::SchemaCleaner) do |cleaner|
expect(cleaner).to receive(:clean).with(output)
end
Rake::Task[clean_rake_task].invoke
end
run_rake_task(test_task_name)
end
end
def run_rake_task(task_name)
rake_task = Rake::Task[task_name]
rake_task.reenable
yield rake_task if block_given?
Rake::Task[task_name].reenable
Rake.application.invoke_task task_name
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment