Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.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 使用rails 4.2中的RSpec 3.2进行测试时,路径不可用_Ruby On Rails_Ruby_Testing_Rspec - Fatal编程技术网

Ruby on rails 使用rails 4.2中的RSpec 3.2进行测试时,路径不可用

Ruby on rails 使用rails 4.2中的RSpec 3.2进行测试时,路径不可用,ruby-on-rails,ruby,testing,rspec,Ruby On Rails,Ruby,Testing,Rspec,我有这两个文件,我想在Rails 4.2中测试它(使用RSpec 3.2) 但在运行时,我会遇到异常 有人有办法解决这个问题吗 new.html.erb_spec.rb: require 'rails_helper' RSpec.describe "products/new", type: :view do before(:each) do assign(:product, Product.new()) end it "renders new product form"

我有这两个文件,我想在Rails 4.2中测试它(使用RSpec 3.2) 但在运行时,我会遇到异常

有人有办法解决这个问题吗

new.html.erb_spec.rb:

require 'rails_helper'

RSpec.describe "products/new", type: :view do
  before(:each) do
    assign(:product, Product.new())
  end

  it "renders new product form" do
    render

    # assert_select "form[action=?][method=?]", products_path, "post" do
    # end
  end
end
new.html.erb:

<h1>New Product</h1>


<%= link_to 'Back', products_path %>
网站中断。而且:测试没有运行

奇怪的是,这些测试是由生成器自动生成的,并且不起作用

你有吗

RSpec.configure do |config|
  config.include Rails.application.routes.url_helpers
  ...
end
包含在您的rails\u助手中


我找到了解决办法。。。这与进口没有任何关系

在我的Gemfile中,我在互联网上的某个地方找到了以下行:

gem 'rspec-rails', '~> 3.0', require: 'rspec/rails'
我把它修好了

gem 'rspec-rails', '~> 3.3'
之后,我的rails应用程序使用Rails4.2.4和RSpec3.3,所有关于丢失路径等的错误都消失了


谢谢你的帮助

它是否是有效的文件名
new.html.erb\u spec.rb
?在我看来,您的routes文件中没有设置产品路径。产品的路径是什么样的?是new.html.erb_spec.rb是位于specs/views/中的spec的文件名。它是由rails生成器生成的。。。(不是我的主意……:D:D:D)路线是正确的。我已经为产品使用了资源。所以他们应该是正确的。使用rake路由,我可以看到producs_路径设置正确。可能的No重复我没有,但添加后它没有任何作用。新/旧错误:'Failures:1)products/new呈现新产品表单失败/错误:render ActionView::Template::error:for###/app/views/products/new.html.erb:4:in应用程序视图(产品)新(html)erb(1064281153)87403260#./spec/views/products/new.html.erb_spec.rb:9:in`block(2层)in''
gem 'rspec-rails', '~> 3.0', require: 'rspec/rails'
gem 'rspec-rails', '~> 3.3'