Class: RSpec::Sequencing

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/sequencing.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSequencing

Returns a new instance of Sequencing.



13
14
15
# File 'lib/rspec/sequencing.rb', line 13

def initialize
  @flow = nil
end

Class Method Details

.run(description = '', &block) ⇒ Object



5
6
7
# File 'lib/rspec/sequencing.rb', line 5

def self.run(description = '', &block)
  run_after(0, description, &block)
end

.run_after(delay, description = '', &block) ⇒ Object



9
10
11
# File 'lib/rspec/sequencing.rb', line 9

def self.run_after(delay, description = '', &block)
  new.then_after(delay, description, &block)
end

Instance Method Details

#activateObject



41
42
43
44
45
# File 'lib/rspec/sequencing.rb', line 41

def activate
  # use this method if you define the sequencing in a let block
  # so RSpec runs it
  formatted_puts "sequence activated"
end

#dataflow(delay, description = '', inputs = [], &block) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/rspec/sequencing.rb', line 26

def dataflow(delay, description = '', inputs = [], &block)
  Concurrent.dataflow(*inputs.compact) do
    task(delay, &block).execute.value.tap do
      formatted_puts(description)
    end
  end
end

#task(delay, &block) ⇒ Object



34
35
36
37
38
39
# File 'lib/rspec/sequencing.rb', line 34

def task(delay, &block)
  Concurrent::ScheduledTask.new(delay) do
    block.call
    true
  end
end

#then(description, &block) ⇒ Object



22
23
24
# File 'lib/rspec/sequencing.rb', line 22

def then(description, &block)
  then_after(0, description, &block)
end

#then_after(delay, description = '', &block) ⇒ Object



17
18
19
20
# File 'lib/rspec/sequencing.rb', line 17

def then_after(delay, description = '', &block)
  @flow = dataflow(delay, description, [@flow], &block)
  self
end

#valueObject



47
48
49
# File 'lib/rspec/sequencing.rb', line 47

def value
  @flow.value
end