简体   繁体   English

未定义的方法“访问”-RSpec

[英]undefined method `visit' - RSpec

I currently have a test that doesn't seen to have the ability to visit particular paths. 我目前正在进行一项测试,认为该测试无法访问特定的路径。 This test is a request spec and this is my first one, as far as I can tell request spec are similar to feature test and can user capybara to do things like visit and fill_in . 据我所知,此测试是一个请求规范,这是我的第一个规范,据我所知,该请求规范与功能测试相似,并且可以使fill_in能够执行visitfill_in But right now I can't get this request spec to even visit a path. 但是现在我无法获得此请求规范,甚至无法访问路径。 Is there something I should know about request specs? 关于请求规范,我应该了解些什么吗? I'll post my code and see if you see anything strange? 我将发布我的代码,看看您是否看到任何奇怪的东西?

SPEC: 规格:

  require "spec_helper"

describe "Mailchimp" do
  describe "Manage list" do
    it "adds new subscriber to list" do
      VCR.use_cassette "mailchimp/subscriber" do
        visit new_subscriber_path
        expect {
          fill_in "first_name", with: "John"
          fill_in "last_name", with: "Mayer"
          fill_in "phone_number", with: "61615551233"
          fill_in "email", with: "john@rowster.com"
          click_button "Sign Up"
        }.to change(Subscriber, :count).by(1)
      end
    end
  end
end 

Let me know if you need to see anything else. 让我知道您是否还有其他需要。 Thank You! 谢谢!

Request specs used to be the same thing as feature specs in earlier versions of RSpec, but things have since changed. 请求规范以前与RSpec早期版本中的功能规范相同,但是此后发生了变化。

Request specs are designed for you to hit the full stack via an HTTP request and inspect details from the response . 请求规范旨在让您通过HTTP请求达到整个堆栈,并检查response详细信息。 You use methods like get , post , patch , and delete to interact with your application. 您可以使用诸如getpostpatchdelete来与您的应用程序进行交互。

An example request spec: 请求规范示例:

get "/users/#{user.id}"
expect(response.body).to include user.full_name

Feature specs are driven by Capybara and allow you to hit the full stack via elements of the interface. 功能规格由Capybara驱动,并允许您通过界面元素来发挥全部作用。 If you want to hit a specific URL, that's when you use visit . 如果您想访问特定的URL,那就是使用visit

Your question includes an example of a feature spec, so I don't really need to echo it in this answer. 您的问题包括一个功能规格的示例,因此我在此答案中实际上不需要回显它。 My piece of advice related to your code would be to change it so that it's inspecting the interface and not how it changes the database. 与您的代码有关的建议是更改它,以便它检查接口,而不是它如何更改数据库。

(So I guess I will echo your code after all. :)) (所以我想我毕竟会回显您的代码。

require "rails_helper"

feature "Mailchimp" do
  describe "Manage list" do
    scenario "adds new subscriber to list" do
      VCR.use_cassette "mailchimp/subscriber" do
        visit new_subscriber_path
        fill_in "first_name", with: "John"
        fill_in "last_name", with: "Mayer"
        fill_in "phone_number", with: "61615551233"
        fill_in "email", with: "john@rowster.com"
        click_button "Sign Up"
        expect(page).to have_content "You have successfully subscribed to our service"
      end
    end
  end
end

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

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