module RspecNestedTransactions
Constants
- CONFIG_AROUND_ALL_NESTED_BLOCKS
- CONFIG_AROUND_ALL_PROCESSED_BY_GROUP
- FIBERS_STACK
- VERSION
Public Instance Methods
nested_transaction(&block)
click to toggle source
# File lib/rspec_nested_transactions.rb, line 23 def nested_transaction(&block) around &wrapped_block(&block) nested_transaction_contexts(&block) end
Private Instance Methods
around_all(prepend, &block)
click to toggle source
# File lib/rspec_nested_transactions.rb, line 60 def around_all(prepend, &block) methods = { before: method(prepend ? :prepend_before : :before), after: method(prepend ? :prepend_after : :after), } methods[:before].call :all do |group| fiber = Fiber.new(&block) FIBERS_STACK << fiber fiber.resume(FiberAwareGroup.new(group.class)) end methods[:after].call :all do fiber = FIBERS_STACK.pop fiber.resume end end
handle_config_around(store = true, prepend = false, &block)
click to toggle source
# File lib/rspec_nested_transactions.rb, line 46 def handle_config_around(store = true, prepend = false, &block) blocks = CONFIG_AROUND_ALL_NESTED_BLOCKS blocks << block if store around_all(prepend) do |group| unless CONFIG_AROUND_ALL_PROCESSED_BY_GROUP[group.name] CONFIG_AROUND_ALL_PROCESSED_BY_GROUP[group.name] = true blocks.reverse_each do |b| group.children.each{|c| c.send :handle_config_around, false, true, &b } end end block[ group, ->(*args){group.run_examples } ] end end
nested_transaction_contexts(&block)
click to toggle source
# File lib/rspec_nested_transactions.rb, line 36 def nested_transaction_contexts(&block) (handle_config_around █ return) if ::RSpec::Core::Configuration === self around_all(false) do |group| group.children.each {|c| c.send :nested_transaction_contexts, &block } block[ group, ->(*args){ group.run_examples } ] end end
wrapped_block() { |c, ->(*args){ respond_to?(:run) ? run : run_examples| ... }
click to toggle source
# File lib/rspec_nested_transactions.rb, line 32 def wrapped_block ->(c){ yield c, ->(*args){ c.respond_to?(:run) ? c.run : c.run_examples } } end