简体   繁体   English

简单的Rspec测试因Michael Hartl RoR Tuotiral而失败

[英]Simple Rspec test failing from Michael Hartl RoR Tuotiral

I am a total neophyte and I am learning Ruby on Rails with the tutorial from Michael Hartl. 我是一个新手,我正在通过Michael Hartl的教程学习Ruby on Rails。 I am on chapter 3 and the Rspec test for the about page is failing (while the exact same test is not failing for the home and help pages). 我在第3章中,关于about页面的Rspec测试失败(而对于home和help页面,则完全相同的测试没有失败)。

The error I am getting when running $ bundle exec rspec spec/requests/static_pages_spec.rb is: 运行$ bundle exec rspec spec/requests/static_pages_spec.rb时出现的错误是:

Failures:

1) Static pages About page should have the content 'About Us'←[31mFailure/Error:←[0m ←[31mvisit 'static_pages/about'←[0m←[31mURI::InvalidURIError←[0m:←[31mthe scheme http does not accept registry part: www.example.com:80static_pages (or bad hostname?)←[0m←[36m     # ./spec/requests/static_pages_spec.rb:24:in `block (3 levels) in <top (required)>'←[0m Finished in 0.0776 seconds←[31m3 examples, 1 failure←[0m

Failed examples:

←[31mrspec ./spec/requests/static_pages_spec.rb:23←[0m ←[36m# Static pages About page should have the content 'About Us'←[0m

When accessing http://localhost:3000/static_pages/about the page loads and I can see "About Us" in big H1 letters. 当访问http://localhost:3000/static_pages/about页面加载的信息,我可以看到H1大写字母的“关于我们”。

spec/requests/static_pages_spec.rb: 规格/要求/static_pages_spec.rb:

require 'spec_helper'

describe "Static pages" do

  describe "Home page" do

    it "should have the content 'Sample App'" do
      visit '/static_pages/home'
      expect(page).to have_content('Sample App')
    end
  end

  describe "Help page" do

    it "should have the content 'Help'" do
      visit '/static_pages/help'
      expect(page).to have_content('Help')
    end
  end

  describe "About page" do

    it "should have the content 'About Us'" do
      visit 'static_pages/about'
      expect(page).to have_content('About Us')
    end
  end
end

config/routes.rb: config / routes.rb:

SampleApp::Application.routes.draw do
  get "static_pages/home"
  get "static_pages/help"
  get "static_pages/about"
end

app/controllers/static_pages_controller.rb: app / controllers / static_pages_controller.rb:

class StaticPagesController < ApplicationController
  def home
  end

  def help
  end

  def about
  end
end

app/views/about.html.erb: app / views / about.html.erb:

<h1>About Us</h1>
<p>
  The <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
  is a project to make a book and screencasts to teach web development
  with <a href="http://rubyonrails.org/">Ruby on Rails</a>. This
  is the sample application for the tutorial.
</p>

I notice you're missing the initial / in the failing test: 我注意到您在失败的测试中缺少初始/

visit 'static_pages/about'

vs

visit '/static_pages/help'

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

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