Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.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 使用rspec功能测试测试新控制器动作_Ruby On Rails_Ruby On Rails 4_Rspec_Capybara_Mail Form - Fatal编程技术网

Ruby on rails 使用rspec功能测试测试新控制器动作

Ruby on rails 使用rspec功能测试测试新控制器动作,ruby-on-rails,ruby-on-rails-4,rspec,capybara,mail-form,Ruby On Rails,Ruby On Rails 4,Rspec,Capybara,Mail Form,我正在使用来处理我的网站的联系方式。我在我的测试环境中使用rspec和capybara。尝试测试联系人表单页面时遇到错误。contacts控制器的新操作确实创建了contact模型的新实例,但是我不知道如何在rspec中这样做来修复失败的原因 失败的测试输出: 联系表格规格rb 联系人\u controller.rb 路由输出 是否应该访问新联系人路径?这里有点累,但我猜是这样。您可以运行rake路由来确定路由。匹配的“/contacts”只是新的\u contacts\u路径的更干净版本。即使

我正在使用来处理我的网站的联系方式。我在我的测试环境中使用rspec和capybara。尝试测试联系人表单页面时遇到错误。contacts控制器的新操作确实创建了contact模型的新实例,但是我不知道如何在rspec中这样做来修复失败的原因

失败的测试输出:

联系表格规格rb

联系人\u controller.rb

路由输出


是否应该访问新联系人路径?这里有点累,但我猜是这样。您可以运行rake路由来确定路由。匹配的“/contacts”只是新的\u contacts\u路径的更干净版本。即使我尝试新的路径,我也会得到完全相同的错误。查看路径。为新方法定义了两条路由。一个具有匹配关键字,另一个具有资源关键字。用火柴。新的。路径为/contacts,而对于资源,路径为/contact/new。你能把rake的输出发出去吗routes@Hemali我从路径中删除了一个新方法来清理东西。然而,我仍然得到同样的错误。
No route matches {:action=>"new", :controller=>"contacts", :format=>nil} missing required keys: []
require 'spec_helper'
require 'rails_helper'

RSpec.feature "Comtact Form Email", :type => :feature do
  scenario "User sends email via contact form" do
    visit contacts_path

    fill_in 'Name', :with => 'Jony Ive'
    fill_in 'Email', :with => 'jony@apple.com'
    fill_in 'Subject', :with => 'Subject Here'
    fill_in 'Message', :with => 'Message'

    click_button 'Send Message'

    expect(page).to have_text("Thank you for your message.")

    last_email.to.should include('help@everydayrails.com') 
    last_email.from.should include('aaron@everydayrails.com')
  end 
end
class ContactsController < ApplicationController
  def new
    @contact = Contact.new
  end

  def create
    @contact = Contact.new(params[:contact])
    @contact.request = request
    if @contact.deliver
      flash[:notice] = 'Thank you for your message. We will contact you soon!'
      redirect_to contacts_path
    else
      flash[:error] = 'Your message could not be sent.'
      render :new
    end
  end
end
match '/contacts',     to: 'contacts#new',             via: 'get'
resources :contacts, only: [:create]
contacts GET             /contacts(.:format)     contacts#new
         POST            /contacts(.:format)     contacts#create