我有一个rspec测试,即描述和它
我想添加before :all
和before :each
行为
我可以通过直接输入测试规范文件来添加它,即
describe "test" do
before :all do
CONTINUE_SPEC= true
end
around :each do |example|
if CONTINUE_SPEC
CONTINUE_SPEC = false
example.run
CONTINUE_SPEC = true unless example.exception
else
example.skip
end
end
... actual tests...
但是我想在几乎每个规范中都有它,所以我想我可以使用require_relative
语句来简化它。但是当我使用require_relative with
require_relative '../../support/continue_test_if_passing'
我得到了
Failure/Error:
before :all do
CONTINUE_SPEC= true
end
NoMethodError:
undefined method `before' for main:Object
答案 0 :(得分:1)
只需将其添加到spec_helper.rb
区块中的RSpec.configure
:
RSpec.configure do |config|
config.before :all do
CONTINUE_SPEC= true
end
config.around :each do |example|
if CONTINUE_SPEC
CONTINUE_SPEC = false
example.run
CONTINUE_SPEC = true unless example.exception
else
example.skip
end
end
# ...
end