Module: Capybara::Lockstep::SynchronizeMacros

Defined in:
lib/capybara-lockstep/capybara_ext.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(by) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/capybara-lockstep/capybara_ext.rb', line 6

def self.extended(by)
  by.instance_eval do
    prepend(@synchronize_before_module = Module.new)
    prepend(@synchronize_after_module = Module.new)
    prepend(@unsynchronize_after_module = Module.new)
  end
end

Instance Method Details

#synchronize_after(meth) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/capybara-lockstep/capybara_ext.rb', line 29

def synchronize_after(meth)
  @synchronize_after_module.module_eval do
    define_method meth do |*args, &block|
      @synchronize_after_count ||= 0
      @synchronize_after_count += 1
      super(*args, &block)
    ensure
      Lockstep.auto_synchronize(log: "Synchronizing after ##{meth}") if @synchronize_after_count == 1
      @synchronize_after_count -= 1
    end

    ruby2_keywords meth
  end
end

#synchronize_before(meth, lazy:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/capybara-lockstep/capybara_ext.rb', line 14

def synchronize_before(meth, lazy:)
  @synchronize_before_module.module_eval do
    define_method meth do |*args, &block|
      @synchronize_before_count ||= 0
      @synchronize_before_count += 1
      Lockstep.auto_synchronize(lazy: lazy, log: "Synchronizing before ##{meth}") if @synchronize_before_count == 1
      super(*args, &block)
    ensure
      @synchronize_before_count -= 1
    end

    ruby2_keywords meth
  end
end

#unsynchronize_after(meth) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/capybara-lockstep/capybara_ext.rb', line 44

def unsynchronize_after(meth)
  @unsynchronize_after_module.module_eval do
    define_method meth do |*args, &block|
      super(*args, &block)
    ensure
      Lockstep.unsynchronize
    end

    ruby2_keywords meth
  end
end