简体   繁体   中英

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 . 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.

Request specs are designed for you to hit the full stack via an HTTP request and inspect details from the response . You use methods like get , post , patch , and delete to interact with your application.

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. If you want to hit a specific URL, that's when you use 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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