Sha256: ea6dcbf9e0cfe0d6ed79c9d81202c4444216dc6b43d3b2bbd25851c2692aa22d
Contents?: true
Size: 1.46 KB
Versions: 10
Compression:
Stored size: 1.46 KB
Contents
module Support module ForemanTasks 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
10 entries across 10 versions & 1 rubygems