def postspec() Postspec.postspec end def use(*args) postspec.use(*args) end def statement(*args, **opts, &block) postspec.statement(*args, **opts, &block) end def exec(*args) postspec.conn.execute(*args) end def execute(*args, **opts, &block) postspec.execute(*args, **opts, &block) end def fox() postspec.fox end def db() postspec.db end def timestamp() postspec.timestamp end def timestamptz() postspec.timestamptz end def datestamp() postspec.datestamp end def data() postspec.data end def inserted_records() postspec.inserted end def updated_records() postspec.updated end def deleted_records() postspec.deleted end def anchors() postspec.anchors end def fixture() postspec.fixture end def transaction(&block) postspec.transaction(&block) end def push_transaction() postspec.push_transaction end def pop_transaction() postspec.pop_transaction end RSpec.configure do |config| config.before(:suite) do # puts "postspec_helper before suite" $postspec_failed = false Postspec.configure { |postspec_config| postspec_config.fail_fast ||= (config.fail_fast == 1) } end config.after(:suite) do # puts "postspec_helper after suite" postspec.terminate if !postspec.failed? end config.around(:example) do |example| if postspec.failed? example.skip else postspec.conn.push_transaction begin result = example.run case example.execution_result.exception when PG::Error # Collapse whole transaction stack postspec.fail! postspec.conn.cancel_transaction when Exception # Pops only last transaction postspec.fail! postspec.conn.pop_transaction(commit: postspec.failed?) else # Success - pop last transaction postspec.conn.pop_transaction(commit: postspec.failed?, fail: false) end rescue => ex # Happens when rspec itself fails postspec.conn.cancel_transaction postspec.fail! raise end result end end end class RSpec::Core::ExampleGroup def self.set_search_path(*args) postspec.set_search_path(self, *args) end def self.use(*args) postspec.use(self, *args) end def self.statement(*args) postspec.statement(self, *args) end def self.procedure(*args) postspec.procedure(self, *args) end end # Monkey patch RSpec to interpret a nil argument to describe/context as "no # output and no indentation". It is used in the implementation of #group below # module RSpec module Core module Formatters # @private class DocumentationFormatter def example_group_started(notification) description = notification.group.description.strip if description != "" output.puts if @group_level == 0 output.puts "#{current_indentation}#{notification.group.description.strip}" @group_level += 1 end end def example_group_finished(notification) description = notification.group.description.strip if description != "" @group_level -= 1 if @group_level > 0 end end end end end end # Extend RSpec with a "group" declaration that provides a scope like # describe/context but is silent # module RSpec module Core class ExampleGroup class << self def group(&block) describe(nil, &block) end end end end end