简体   繁体   English

我的rspec feautre测试中不能使用命名路由。

[英]Can't use named routes in my rspec feautre tests.

I have the tests that looks like the following: 我有如下所示的测试:

require "rails_helper"

feature "Ordering units management" do

  scenario "Creating new ordering unit" do
    visit new_ordering_units_path

    fill_in I18n.t('activerecord.attributes.ordering_unit.name'), with: "Ordering unit name"
    click_button I18n.t('submit')

    expect(page).to have_text(I18n.t('ordering_units.created'))
    expect(page).to have_content("Ordering unit name")
  end
end

When I run it I have the following error message: 运行它时,出现以下错误消息:

undefined local variable or method `new_ordering_units_path' for #<RSpec::ExampleGroups::OrderingUnitsManagement:0x00000004962810>

My spec_helper: 我的spec_helper:

RSpec.configure do |config|
  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end

  config.filter_run :focus
  config.run_all_when_everything_filtered = true

  if config.files_to_run.one?
    config.default_formatter = 'doc'
  end

  config.profile_examples = 10
  config.order = :random

  Kernel.srand config.seed do
  end
end

My rails helper: 我的rails助手:

ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'capybara'
require 'rspec/rails'
require 'capybara/rspec'
ActiveRecord::Migration.maintain_test_schema!

RSpec.configure do |config|
  config.include FactoryGirl::Syntax::Methods
  config.include Capybara::DSL

  config.before(:suite) do
      DatabaseCleaner.strategy = :transaction
      DatabaseCleaner.clean_with(:truncation)
    end

    config.before(:each) do
      DatabaseCleaner.start
    end

    config.after(:each) do
      DatabaseCleaner.clean
    end
  config.infer_spec_type_from_file_location!
end

I can't find solution for this. 我找不到解决方案。 Could anyone tell me why this ain't working? 谁能告诉我为什么这不起作用?

It should be called new_ordering_unit_path (singular). 它应该称为new_ordering_unit_path (单数)。 Type rake routes in your console to see all routes in effect. 在控制台中输入rake routes ,以查看所有有效的路由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM