我目前在一个非常基本的rails 3.2应用程序中运行miniskirt和minitest。我遇到的问题是,如果我在同一个"describe“子句中声明了两个"it”测试,那么setup方法中的miniskirt数据会被创建两次。我正在使用Ryan Bates在第327集中概述的设置。
def setup
@res_a = Factory(:reservation)
@res_b = Factory(:reservation)
end当我使用rake test运行测试时。我在第一次测试中总共得到了2个预订,然后在第二个测试中得到了4个。
有什么想法吗?
更新:
以下是我正在运行的测试的示例
it "should return all reservations for a given date" do
Reservation.for_date(Time.mktime(2012, 1, 1)).all.count.must_equal 2
end如果我用两个不同的it方法运行上面的测试,那么第二个方法就会失败,因为实际的计数是4。所以在我看来,Miniskirt没有在两次测试之间回滚数据库。
发布于 2012-10-26 13:15:54
如果使用"describe",请使用之前和之后:
http://old.rspec.info/documentation/before_and_after.html
===规范
require 'minitest/autorun'
describe Meme do
before do
@meme = Meme.new
end
describe "when asked about cheeseburgers" do
it "must respond positively" do
@meme.i_can_has_cheezburger?.must_equal "OHAI!"
end
endhttps://stackoverflow.com/questions/13080567
复制相似问题