Module: DataShifter::SpecHelper
- Defined in:
- lib/data_shifter/spec_helper.rb
Overview
Test helpers for RSpec. Include this module in your spec_helper or rails_helper:
require "data_shifter/spec_helper"
RSpec.configure do |config|
config.include DataShifter::SpecHelper, type: :data_shift
end
Or include it in individual specs:
RSpec.describe DataShifts::BackfillFoo do
include DataShifter::SpecHelper
...
end
Instance Method Summary collapse
-
#capture_data_shift_output ⇒ Object
Run a shift and capture its output.
-
#run_data_shift(shift_class, dry_run: true, commit: false) ⇒ Axn::Result
Run a data shift class with the given options.
-
#silence_data_shift_output ⇒ Object
Suppress STDOUT output during a block (useful for cleaner test output).
Instance Method Details
#capture_data_shift_output ⇒ Object
Run a shift and capture its output. Returns [Axn::Result, String] tuple.
65 66 67 68 69 70 71 72 73 |
# File 'lib/data_shifter/spec_helper.rb', line 65 def capture_data_shift_output original_stdout = $stdout $stdout = StringIO.new result = yield output = $stdout.string [result, output] ensure $stdout = original_stdout end |
#run_data_shift(shift_class, dry_run: true, commit: false) ⇒ Axn::Result
Run a data shift class with the given options. Returns the Axn::Result.
36 37 38 39 |
# File 'lib/data_shifter/spec_helper.rb', line 36 def run_data_shift(shift_class, dry_run: true, commit: false) effective_dry_run = commit ? false : dry_run shift_class.call(dry_run: effective_dry_run) end |
#silence_data_shift_output ⇒ Object
Suppress STDOUT output during a block (useful for cleaner test output).
48 49 50 51 52 53 54 |
# File 'lib/data_shifter/spec_helper.rb', line 48 def silence_data_shift_output original_stdout = $stdout $stdout = StringIO.new yield ensure $stdout = original_stdout end |