RSpec具有:
describe "the user" do
before(:each) do
@user = Factory :user
end
it "should have access" do
@user.should ...
end
end
如何使用Test::Unit对这样的测试进行分组?例如,在我的控制器测试中,我希望在用户登录和无人登录时测试控制器。
发布于 2011-05-08 08:17:59
据我所知,Test::Unit
不支持测试上下文。但是,the gem contest
增加了对上下文块的支持。
发布于 2013-08-07 20:30:19
您可以通过类来实现类似的功能。也许有人会说这很可怕,但它确实允许你在一个文件中分离测试:
class MySuperTest < ActiveSupport::TestCase
test "something general" do
assert true
end
class MyMethodTests < ActiveSupport::TestCase
setup do
@variable = something
end
test "my method" do
assert object.my_method
end
end
end
发布于 2011-05-11 19:24:00
虽然看起来他们现在已经将与上下文相关的代码放到了一个单独的gem中:https://github.com/thoughtbot/shoulda-context,但是应该使用https://github.com/thoughtbot/shoulda
https://stackoverflow.com/questions/5924818
复制相似问题