File: mocked_events.rb

package info (click to toggle)
ruby-memoizable 0.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 296 kB
  • sloc: ruby: 1,052; makefile: 4
file content (29 lines) | stat: -rw-r--r-- 766 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

RSpec.shared_context "with mocked events" do
  def register_events(object, method_names)
    method_names.each do |method_name|
      allow(object).to receive(method_name) do |*args, &block|
        events.next.call(object, method_name, *args, &block)
      end
    end
  end

  def expected_event(object, method_name, *expected_args, &handler)
    lambda do |*args, &block|
      expect(args).to eql([object, method_name, *expected_args])
      handler.call(&block)
    end
  end
end

RSpec.shared_examples "executes all events" do
  it "executes all events" do
    begin
      subject
    rescue
      # subject may raise, should be tested in other examples
    end
    expect { events.peek }.to raise_error(StopIteration)
  end
end