在before(:suite)中使用“ file_fixture”?

我想在for(let i = 0; i < menu.length; i++){ for(let j = 0; j < menu[i].length; j++){ if(j == 0){ foodSectionText = menu[i][j]; let btn = document.createElement("BUTTON"); btn.innerHTML = foodSectionText; document.body.appendChild(btn); } else{ menuEntry = menu[i][j]; console.log(menuEntry); for(let k = 0; k < menuEntry.length; k++){ div = document.createElement("DIV"); div.innerHTML = menuEntry[k]; document.body.appendChild(div); } } } } 中这样做:

create table seller(
    seller_id int primary key,seller_name text,seller_email set<text>,seller_address map<text>,seller_phone list<text>,product_id int,product_title_text,product_description text,product_trackno int,product_bidoption text,bid_startdate date,bid_closedate date,bid_startprice int,bid_withdrawdate date);

    SyntaxException: line 1:110 mismatched input '>' expecting ',' (...<text>,seller_address map<text[>],...)

但是不幸的是,这不起作用:

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

wyw521 回答:在before(:suite)中使用“ file_fixture”?

file_fixture显然仅在示例级别可用。这意味着您可以在itspecify内或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
本文链接:https://www.f2er.com/3148497.html

大家都在问