require 'rails_helper'
describe "Foo" , type : :model do
it "ex3" do
puts "--ex3--"
puts "rep: #{ @rep . inspect } "
puts "Report count: #{ Report . count } "
end
context "c1" do
before :context do
puts "creating a report"
@rep = create :report
end
it "ex1" do
puts "--ex1--"
puts "rep: #{ @rep . inspect } "
puts "Report count: #{ Report . count } "
end
end
it "ex2" do
puts "--ex2--"
puts "rep: #{ @rep . inspect } "
puts "Report count: #{ Report . count } "
end
end
Result without database_cleaner
Foo
--ex3 --
rep : nil
Report count : 2
ex3
--ex2 --
rep : nil
Report count : 2
ex2
c1
creating a report
--ex1 --
rep : #<Report id: 3, name: "Report 1", year: 2015, description: "et", created_at: "2015-07-24 10:20:30", updated_at: "2015-07-24 10:20:30">
Report count : 3
ex1
Result with database_cleaner
Foo
Foo
--ex3 --
rep : nil
Report count : 0
ex3
--ex2 --
rep : nil
Report count : 0
ex2
c1
creating a report
--ex1 --
rep : #<Report id: 1, name: "Report 1", year: 2015, description: "dolor", created_at: "2015-07-24 10:28:23", updated_at: "2015-07-24 10:28:23">
Report count : 1
ex1
config . before ( :suite ) do
DatabaseCleaner . strategy = :transaction
DatabaseCleaner . clean_with ( :truncation )
end
config . around ( :each ) do |example |
DatabaseCleaner . cleaning do
example . run
end
end
config . after ( :each ) do
DatabaseCleaner . clean
end
config . after ( :context ) do
DatabaseCleaner . clean
end