Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.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 为什么';在我的数据库中看不到对象吗?_Ruby On Rails_Rspec_Capybara - Fatal编程技术网

Ruby on rails 为什么';在我的数据库中看不到对象吗?

Ruby on rails 为什么';在我的数据库中看不到对象吗?,ruby-on-rails,rspec,capybara,Ruby On Rails,Rspec,Capybara,给定 使用硒的水豚试验在“John's Cafe”的“have_content”中失败 capybara是否无法看到在before块中添加到db的db对象 我确信测试数据库中有对象,但它没有显示在视图页面上,视图页面在开发中连接正确,我更好奇为什么这个测试不会通过。谢谢 我的测试套件是根据avdi的博客文章配置的 您可以尝试以下几件事: a) 将'pry'gem添加到gem文件中,然后可以将binding.pry添加到测试代码中。例如: require 'spec_helper' descri

给定

使用硒的水豚试验在“John's Cafe”的“have_content”中失败

capybara是否无法看到在before块中添加到db的db对象

我确信测试数据库中有对象,但它没有显示在视图页面上,视图页面在开发中连接正确,我更好奇为什么这个测试不会通过。谢谢

我的测试套件是根据avdi的博客文章配置的
您可以尝试以下几件事: a) 将'pry'gem添加到gem文件中,然后可以将binding.pry添加到测试代码中。例如:

require 'spec_helper'

describe "visit '/'" do
  context "displays ", :driver => :selenium do
    before :each do
      FactoryGirl.create :restaurant, name: "John's Cafe"
      visit '/'
    end
    context "content:" do
      it "Restaurantly Spots!" do
        expect(page).to have_content 'Restaurantly Spots!'
      end

      it "John's Cafe" do
        expect(page).to have_content "John's Cafe"
      end
    end
  end
end
it "John's Cafe" do
  binding.pry
  expect(page).to have_content "John's Cafe"
end
此时,当您运行测试时,您将看到一个控制台(如irb或rails控制台),并对您的应用程序进行自省。因此,您可以查看内容是否在数据库中。例如:

require 'spec_helper'

describe "visit '/'" do
  context "displays ", :driver => :selenium do
    before :each do
      FactoryGirl.create :restaurant, name: "John's Cafe"
      visit '/'
    end
    context "content:" do
      it "Restaurantly Spots!" do
        expect(page).to have_content 'Restaurantly Spots!'
      end

      it "John's Cafe" do
        expect(page).to have_content "John's Cafe"
      end
    end
  end
end
it "John's Cafe" do
  binding.pry
  expect(page).to have_content "John's Cafe"
end
这应该会给你一个关于餐厅是否被保存到数据库的线索

一个问题,第一次考试通过了吗?“餐馆景点!”

让我知道这是否有效,或者你有更多的问题


Mike Riley

还有一件事你可能想从FactoryGirl中提取出来。在开始之前先创建。你可以这样做:让(:restaurant){FactoryGirl.create:restaurant,name:“John's Cafe”}在doI尝试这两个之前,@mike pry表示db正确保存了记录。我不确定,我最终使用了一个稍微不同的测试结构,在那里我通过浏览器交互创建对象,它似乎可以工作。谢谢