Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 4 Capybara webkit AJAX请求中未找到RecordNotFound_Ruby On Rails 4_Selenium_Rspec_Capybara_Capybara Webkit - Fatal编程技术网

Ruby on rails 4 Capybara webkit AJAX请求中未找到RecordNotFound

Ruby on rails 4 Capybara webkit AJAX请求中未找到RecordNotFound,ruby-on-rails-4,selenium,rspec,capybara,capybara-webkit,Ruby On Rails 4,Selenium,Rspec,Capybara,Capybara Webkit,我有一个表格可以创建一个新的地址。该表单包括拥有地址的父模型(在本例中为客户)的id。提交表单时,AJAX请求会转到AddressesController,由JavaScript响应。问题是,有时找到父模型,有时找不到 这在RSpec中起作用: before do click_link add_address fill_in country_field, with: country fill_in city_field, with: city fill_in st

我有一个表格可以创建一个新的
地址
。该表单包括拥有
地址的父模型(在本例中为
客户
)的id。提交表单时,AJAX请求会转到
AddressesController
,由JavaScript响应。问题是,有时找到父模型,有时找不到

这在RSpec中起作用:

before do
    click_link add_address
    fill_in country_field, with: country
    fill_in city_field, with: city
    fill_in street_field, with: street
    fill_in postal_code_field, with: postal_code
    click_button submit_address
    expect(page.title).to eq(show_page_title)
end

it { is_expected.to have_content(address_created) }
但是,当我将
expect(page.title.)从before语句移动到自己的测试(当然更好)时:

我得到以下错误:

ActiveRecord::RecordNotFound:
  Couldn't find Customer with 'id'=1

如果我在before语句以及接收请求的
地址控制器中添加
puts Customer.count
last,我从before语句中的行中得到1,但从控制器中得到0!这是怎么可能的?

它解决了这个问题,不过我需要做更多的测试才能确定。我现在可以确认上面的解决方案解决了我的问题。我不知道为什么,因为
Customer
应该在运行测试之前创建,因为我使用
let创建它!(:customer){FactoryGirl.create(:customer)}
语句。它解决了这个问题,不过我需要做更多的测试才能确定。我现在可以确认上面的解决方案解决了我的问题。我不知道为什么,因为
Customer
应该在运行测试之前创建,因为我使用
let创建它!(:customer){FactoryGirl.create(:customer)}
语句。
ActiveRecord::RecordNotFound:
  Couldn't find Customer with 'id'=1