Sha256: 6b848460fa2d68c53f77429a49288269c3f5a5ff90cd67a314e66869e7cb14dc
Contents?: true
Size: 1.49 KB
Versions: 4
Compression:
Stored size: 1.49 KB
Contents
module Support module ForemanTasks # Stubbing for foreman tasks module Task def stub_tasks! @controller.stubs(:sync_task).returns(build_task_stub) @controller.stubs(:async_task).returns(build_task_stub) end def build_task_stub task_attrs = [:id, :label, :pending, :username, :started_at, :ended_at, :state, :result, :progress, :input, :humanized, :cli_example].inject({}) { |a, e| a.update e => nil } task_attrs[:output] = {} stub('task', task_attrs).mimic!(::ForemanTasks::Task) end def assert_async_task(expected_action_class, *args_expected) assert_foreman_task(true, expected_action_class, *args_expected) end def assert_sync_task(expected_action_class, *args_expected) assert_foreman_task(false, expected_action_class, *args_expected) end def assert_foreman_task(async, expected_action_class, *args_expected) block ||= block_from_args(args_expected) method = async ? :async_task : :sync_task task_stub = build_task_stub @controller. expects(method). with do |action_class, *args| expected_action_class == action_class && block.call(*args) end. returns(task_stub) task_stub end private def block_from_args(args_expected) ->(*_) { true } if args_expected.empty? ->(*args) { args == args_expected } end end end end
Version data entries
4 entries across 4 versions & 1 rubygems