Joe*_*ean 10 ruby ruby-on-rails activesupport
我需要为类或系统范围的一些Rails测试设置一个设置和拆卸方法,但我只找到了一种方法来定义一个适用于每个测试级别的常规设置/拆卸.
例如:
class ActiveSupport::TestCase
setup do
puts "Setting up"
end
teardown do
puts "tearing down"
end
end
Run Code Online (Sandbox Code Playgroud)
将执行每个测试用例的输出,但我想要像:
class ActiveSupport::TestCase
setup_fixture do
puts "Setting up"
end
teardown_fixture do
puts "tearing down"
end
end
Run Code Online (Sandbox Code Playgroud)
这将执行安装_
夹具之前所有的测试方法,然后执行拆卸_
夹具后所有的测试方法.
有这样的机制吗?如果没有,是否有一种简单的方法来修补这种机制?
有几种流行的测试框架构建Test::Unit
并提供这种行为:
describe "A Widget" do
before(:all) do
# stuff that gets run once at startup
end
before(:each) do
# stuff that gets run before each test
end
after(:each) do
# stuff that gets run after each test
end
after(:all) do
# stuff that gets run once at teardown
end
end
Run Code Online (Sandbox Code Playgroud)
context "A Widget" do
# same syntax as RSpec for before(:all), before(:each), &c.
end
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2434 次 |
最近记录: |