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

时间:2014-12-12 19:46:00

标签: ruby-on-rails ruby rspec

我的测试如下所示:

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

当我运行它时,我有以下错误消息:

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

我的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

我的铁路助手:

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

我无法找到解决方案。有谁能告诉我为什么这个没工作?

1 个答案:

答案 0 :(得分:1)

它应该被称为new_ordering_unit_path(单数)。在控制台中键入rake routes以查看所有有效的路由。