将Rspec升级到Rspec 2.99,希望在挂钩之前/之后使用let连接变量



我有一个令人头疼的问题。当升级rspec时,我得到:

DEPRECATION: let declaration `directory` accessed in an `after(:all)` hook 
at:
`let` and `subject` declarations are not intended to be called

现在我明白了,我不能在before/after钩子中使用let定义的变量。然而,与我的测试套件一起使用的方法使用一个连接来预制一些RESTneneneba API操作:

let {:connection}   {user_base}
after(:all) do
connection.delete_folder
end

我的问题是:在不将每个连接都作为实例变量的情况下,有没有办法绕过这一点?我想避免每次我想预处理一个操作时调用连接变量,例如

before(:all) do
@connection = user_base
end
it "adds folder" do    
@connection.add_folder
end
it "edits folder" do
@connection.edit_folder
end

我认为RSpec希望您在每个示例之前运行块,而不是在所有示例之前运行一次:

let(:connection) { user_base }
after do # short for `after(:each) do`
connection.delete_folder
end
it "adds folder" do    
connection.add_folder
end
it "edits folder" do
connection.edit_folder
end

最新更新