Ruby on rails 使用;文件“U夹具”;在之前(:套房)?
我想在Ruby on rails 使用;文件“U夹具”;在之前(:套房)?,ruby-on-rails,testing,rspec,rspec-rails,Ruby On Rails,Testing,Rspec,Rspec Rails,我想在spec\u助手中执行此操作: 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:
spec\u助手中执行此操作
:
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)>
有效吗
为什么会这样?是否可以在(:suite)块之前的
中使用文件\u fixture
?文件\u fixture
显然仅在示例级别可用。这意味着您可以在It
或specify
或let
块内使用它
它的作用-它只是读取文件的简单助手,您可能可以通过以下方式修复它:
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
file\u fixture
显然仅在示例级别可用。这意味着您可以在It
或specify
或let
块内使用它
它的作用-它只是读取文件的简单助手,您可能可以通过以下方式修复它:
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