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

时间:2019-11-06 22:50:04

标签: ruby-on-rails testing rspec rspec-rails

我想在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

1 个答案:

答案 0 :(得分:0)

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