Ruby on rails 使用capybara和web模拟rails应用程序进行测试

Ruby on rails 使用capybara和web模拟rails应用程序进行测试,ruby-on-rails,testing,rspec,mocking,capybara,Ruby On Rails,Testing,Rspec,Mocking,Capybara,你好!! 我有一个rails api和主干上的前端。 我的api调用外部api以获取一些资源 我想在capybara中对整个应用程序进行集成测试。我正在使用网络模拟 我的spec_助手的剪报: WebMock.disable_net_connect!(allow_localhost: true) RSpec.configure do |config| config.before(:each) do stub_request(:get, "url.com/live/en/live/l

你好!! 我有一个rails api和主干上的前端。 我的api调用外部api以获取一些资源

我想在capybara中对整个应用程序进行集成测试。我正在使用网络模拟

我的spec_助手的剪报:

WebMock.disable_net_connect!(allow_localhost: true)

RSpec.configure do |config|
  config.before(:each) do
    stub_request(:get, "url.com/live/en/live/list.json").
      with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
      to_return(status: 200, body: body, headers: {})
  end  
(...)
end

def body
  "{\"version\":\"9\",\"sports\":[{\"id\":101,\"title\":\"Football\"},{\"id\":100,\"title\":\"Tenis\"}]}"
end
我的功能测试:

feature 'sports displayment' do
  scenario 'user access to the site' do
    visit root_path

    expect(page).to have_text("Football")
  end
end
显示的错误
应在“”中找到文本“Football”
如果我在控制器上嵌入binding.pry,它将不工作(意味着它不会通过它)

我确信这个应用程序可以工作,所以这是一个测试问题

应用程序的链接

-------编辑-------

我一直在尝试一些合理的新事物,但仍然不起作用。 我添加了selenium,因为默认的capybara diver不支持js,我添加了
wait_for_ajax
,这是一种方法,可以确保capybara正在等待ajax请求,并且我还为此场景启用了js:

require 'rails_helper'

feature 'sports displayment' do

  before(:all) do
    Capybara.current_driver = :selenium
  end

  scenario 'user access to the site', js: true do
    visit '/'

    wait_for_ajax

    expect(page).to have_text("Football")
  end
end
你应该试试看

expect(page).to have_content("Football")
你应该试试看

expect(page).to have_content("Football")

谢谢@Gerard-你能在上面的整个设置中发布到你的回购协议分支的链接吗?嗨@SamJoseph,谢谢你的帮助。这是与此功能测试相关的分支谢谢@Gerard-你能在上面的整个设置中发布到你的回购协议分支的链接吗?嗨@SamJoseph,谢谢你的帮助。这是此特性测试的关注点