Ruby on Rails App Testing with Rspec and Capybara

蹲街弑〆低调 提交于 2019-12-12 04:59:34

问题


when i create a feature test for my application get the following error:

 ActionController::RoutingError:
   No route matches [GET] "/example"

My application uses subdomains and sub-applications(engines/modules) within these subdomains. Now when i set for Capybara the app_host or default_host through an feature_subdomain_helper like

Capybara.app_host = "example.lvh.me" or
Capybara.default_host = "example.lvh.me"

and into my rails_helper.rb i add the following code line

  config.extend SubdomainHelpers, type: :feature

I get the same error. Now i think the configured subdomain are not considered by my feature test.

My Rspec Version is: 3.2 and Capybara Version is: 2.4.4

My sample feature test looks like:

require 'rails_helper'
feature 'Example Page' do

  scenario 'visit example page' do

    visit "/example"

    expect(page).to have_content 'Example'
  end
end

Have someone an idea what i do wrong?

Edit: Mainapp routes:

constraints(Subdomain) do
  mount Example::Engine => '/', as: 'example'
end

Engine routes:

Example::Engine.routes.draw do

  scope '/example', nav_scope: 'example' do
  end
end

回答1:


The names of Capybara.default_host and Capybara.app_host are slightly misleading since they both need to be set as URLs to function properly

Capybara.default_host = "http://example.lvh.me"

If that doesn't fix your issue check rake routes and make sure the action you think is mounted at '/example' really is.



来源:https://stackoverflow.com/questions/36922936/ruby-on-rails-app-testing-with-rspec-and-capybara

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!