141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/rspec/core/prefactory.rb', line 141
def self.included(base)
require 'prefactory/active_record_integration'
base.extend RSpecAroundAll
base.before(:all) do
clear_prefactory_memoizations
end
base.around(:all) do |group|
ActiveRecord::Base.with_disposable_transaction { group.run_examples }
end
base.after(:all) do
clear_prefactory_memoizations
end
base.around(:each) do |example|
clear_prefactory_memoizations
ActiveRecord::Base.with_disposable_transaction { example.run }
clear_prefactory_memoizations
end
base.instance_eval do
def describe_with_transaction(*args, &block)
original_caller = caller
modified_block = proc do
instance_eval do
before(:all) { clear_prefactory_memoizations }
around(:all) do |group|
ActiveRecord::Base.with_disposable_transaction { group.run_examples }
end
after(:all) { clear_prefactory_memoizations }
end
instance_eval(&block)
end
caller_metadata = { :caller => original_caller }
if args.last.is_a?(Hash)
args.last.merge!(caller_metadata)
else
args << caller_metadata
end
describe_without_transaction(*args, &modified_block)
end
class << self
alias_method :describe_without_transaction, :describe
alias_method :describe, :describe_with_transaction
alias_method :context, :describe
end
end
end
|