Class: RSpec::Sequencing

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSequencing

Returns a new instance of Sequencing.



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

def initialize
  @flows = []
end

Instance Attribute Details

#flowsObject (readonly)

Returns the value of attribute flows.



15
16
17
# File 'lib/rspec/sequencing.rb', line 15

def flows
  @flows
end

Class Method Details

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



7
8
9
# File 'lib/rspec/sequencing.rb', line 7

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

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



11
12
13
# File 'lib/rspec/sequencing.rb', line 11

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

Instance Method Details

#activateObject



38
39
40
41
# File 'lib/rspec/sequencing.rb', line 38

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

#activate_quietlyObject



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

def activate_quietly
  # use this method if you define the sequencing in a let block so RSpec instantiates it
end

#assert_no_errorsObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rspec/sequencing.rb', line 43

def assert_no_errors
  # if you think you might get exceptions raised in any step the use this to get rspec to see them
  # the raised error gets set as the dataflow `reason`.
  value
  @flows.map do |flow|
    if flow.rejected?
      raise flow.reason
    end
    flow.value
  end
end

#then(description = '', &block) ⇒ Object



30
31
32
# File 'lib/rspec/sequencing.rb', line 30

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

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



21
22
23
24
25
26
27
28
# File 'lib/rspec/sequencing.rb', line 21

def then_after(delay, description = '', &block)
  @flows << Concurrent.dataflow(*@flows) do
    sleep delay
    formatted_puts(description) unless description.empty?
    block.call
  end
  self
end

#valueObject



55
56
57
58
# File 'lib/rspec/sequencing.rb', line 55

def value
  # this is a blocking operation
  @flows.last.value
end