Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用;文件“U夹具”;在之前(:套房)?_Ruby On Rails_Testing_Rspec_Rspec Rails - Fatal编程技术网

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