Module: TestProf::LetItBe::Freezer::Stoplist

Defined in:
lib/test_prof/recipes/rspec/let_it_be.rb

Overview

Stoplist to prevent freezing objects and theirs associations that are defined with ‘let_it_be`’s ‘freeze: false` options during deep freezing.

To only keep track of objects that are available in current example group, ‘begin` adds a new layer, and `rollback` removes a layer of unrelated objects along with rolling back the transaction where they were created.

Stoplist holds records declared with ‘freeze: false` (so we do not freeze them even if they’re used as associated records for frozen objects)

Class Method Summary collapse

Class Method Details

.beginObject



145
146
147
# File 'lib/test_prof/recipes/rspec/let_it_be.rb', line 145

def begin
  @stoplist.push([])
end

.rollbackObject



149
150
151
# File 'lib/test_prof/recipes/rspec/let_it_be.rb', line 149

def rollback
  @stoplist.pop
end

.stop!(record) ⇒ Object



141
142
143
# File 'lib/test_prof/recipes/rspec/let_it_be.rb', line 141

def stop!(record)
  @stoplist.last.push(record)
end

.stop?(record) ⇒ Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/test_prof/recipes/rspec/let_it_be.rb', line 137

def stop?(record)
  @stoplist.any? { |layer| layer.include?(record) }
end