我想在 spec_helper
中执行此操作:
config.before(:suite) do
allow(Net::HTTP)
.to receive(:get)
.with(URI(some_uri))
.and_return(file_fixture('response.json').read)
end
但不幸的是,这不起作用:
NoMethodError:
undefined method `file_fixture' for #<RSpec::Core::AnonymousExampleGroup (no description provided)>
但是当我这样做的时候:
config.before(:each) do
...
end
有用吗?
为什么会这样,是否也可以在 before(:suite)
block 中使用 file_fixture
?
最佳答案
file_fixture
显然仅在示例级别可用。这意味着您可以在 it
或 specify
或 let
block 中使用它。
它的作用 - 它只是一个读取文件的简单助手,您可以这样修复它:
config.before(:suite) do
allow(Net::HTTP)
.to receive(:get)
.with(URI(some_uri))
.and_return(File.read('path/to/your/fixtures/response.json'))
end
关于ruby-on-rails - 在之前使用 "file_fixture"(:suite)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58739582/