简体   繁体   English

Ruby 1.8.7上的Rspec失败

[英]Rspec Failures on Ruby 1.8.7

I'm using Ruby 1.8.7 installed on mac osx10.8 with brew install and rvm. 我正在使用brew install和rvm在Mac osx10.8上安装的Ruby 1.8.7。 When I do bundle exec spec spec/requests/static_pages_spec.rb I get these errors 当我bundle exec spec spec/requests/static_pages_spec.rb出现这些错误

FFFFF.FFF

Failures:

  1) Static pages Home page should have the h1 'Sample App'
     Failure/Error: visit root_path
     NameError:
       undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x104b5a108>
     # ./spec/requests/static_pages_spec.rb:8

  2) Static pages Home page should have the base title
     Failure/Error: visit root_path
     NameError:
       undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x104b45258>
     # ./spec/requests/static_pages_spec.rb:13

  3) Static pages Home page should not have a custom page title
     Failure/Error: visit root_path
     NameError:
       undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x104b3ea48>
     # ./spec/requests/static_pages_spec.rb:18

  4) Static pages Help page should have the h1 'Help'
     Failure/Error: visit help_path
     ActionView::Template::Error:
       undefined method `full_title' for #<#<Class:0x106d53c50>:0x106d509b0>
     # ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb__291545742_2204731780'
     # ./spec/requests/static_pages_spec.rb:26

  5) Static pages Help page should have the title 'Help'
     Failure/Error: visit help_path
     ActionView::Template::Error:
       undefined method `full_title' for #<#<Class:0x106d53c50>:0x106cde630>
     # ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb__291545742_2204731780'
     # ./spec/requests/static_pages_spec.rb:31

  6) Static pages About page should have the title 'About Us'
     Failure/Error: expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us")
     NoMethodError:
       undefined method `has_title?' for #<Capybara::Session>
     # ./spec/requests/static_pages_spec.rb:45

  7) Static pages Contact page should have the content 'Contact'
     Failure/Error: visit contact_path
     ActionView::Template::Error:
       undefined method `full_title' for #<#<Class:0x106d53c50>:0x106c303c8>
     # ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb__291545742_2204731780'
     # ./spec/requests/static_pages_spec.rb:52

  8) Static pages Contact page should have the title 'Contact'
     Failure/Error: visit contact_path
     ActionView::Template::Error:
       undefined method `full_title' for #<#<Class:0x106d53c50>:0x106c07298>
     # ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb__291545742_2204731780'
     # ./spec/requests/static_pages_spec.rb:57

Finished in 0.41599 seconds
9 examples, 8 failures

Failed examples:

rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page should have the h1 'Sample App'
rspec ./spec/requests/static_pages_spec.rb:12 # Static pages Home page should have the base title
rspec ./spec/requests/static_pages_spec.rb:17 # Static pages Home page should not have a custom page title
rspec ./spec/requests/static_pages_spec.rb:25 # Static pages Help page should have the h1 'Help'
rspec ./spec/requests/static_pages_spec.rb:30 # Static pages Help page should have the title 'Help'
rspec ./spec/requests/static_pages_spec.rb:43 # Static pages About page should have the title 'About Us'
rspec ./spec/requests/static_pages_spec.rb:51 # Static pages Contact page should have the content 'Contact'
rspec ./spec/requests/static_pages_spec.rb:56 # Static pages Contact page should have the title 'Contact'

Does anyone know how to fix any/all of these errors? 有谁知道如何解决所有这些错误? here are my associated files: routes.rb 这是我的关联文件:routes.rb

SampleApp::Application.routes.draw do

  match '/static_pages/home', :to =>'static_pages#home'
  match '/help' => 'static_pages#help',    :via => 'get'
  match '/about' => 'static_pages#about',   :via => 'get'
  match '/contact' => 'static_pages#contact', :via => 'get'

  get "static_pages/home"

  get "static_pages/help"

  get "static_pages/about"

  get "static_pages/contact"

static_pages_spec.rb static_pages_spec.rb

require 'spec_helper'

describe "Static pages" do

  describe "Home page" do

    it "should have the h1 'Sample App'" do
      visit root_path
      expect(page).to have_content('Sample App')
    end

    it "should have the base title" do
      visit root_path
      expect(page).to have_title("Ruby on Rails Tutorial Sample App")
    end

    it "should not have a custom page title" do
      visit root_path
      expect(page).not_to have_title('| Home')
    end
  end

  describe "Help page" do

    it "should have the h1 'Help'" do
      visit help_path
      expect(page).to have_content('Help')
    end

    it "should have the title 'Help'" do
      visit help_path
      expect(page).to have_title("Ruby on Rails Tutorial Sample App | Help")
    end
  end

  describe "About page" do

    it "should have the h1 'About Us'" do
      visit about_path
      expect(page).to have_content('About Us')
    end

    it "should have the title 'About Us'" do
      visit about_path
      expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us")
    end
  end

  describe "Contact page" do

    it "should have the content 'Contact'" do
      visit contact_path
      expect(page).to have_content('Contact')
    end

    it "should have the title 'Contact'" do
      visit contact_path
      expect(page).to have_title("Ruby on Rails Tutorial Sample App | Contact")
    end
  end
end

I have updated my Xcode, libiconv, and everything associated. 我已经更新了我的Xcode,libiconv和所有相关的东西。 I am currently most of the way through chapter 5 of the ruby on rails tutorial and I for the life of me have no idea what is causing these errors. 目前,我大部分时间都在“ ruby​​ on rails”教程的第5章中学习,我一生都不知道是什么导致了这些错误。 I have followed the tutorial perfectly so far with the minor exceptions such as changing a colon method into hash rockets and different gem versions, etc. 到目前为止,我已经完美地遵循了本教程,除了一些小例外,例如将冒号方法更改为哈希火箭和不同的gem版本等。

rake results: 耙结果:

s s

tatic_pages_home     /static_pages/home(.:format)    static_pages#home
                help GET /help(.:format)                 static_pages#help
               about GET /about(.:format)                static_pages#about
             contact GET /contact(.:format)              static_pages#contact
                     GET /static_pages/home(.:format)    static_pages#home
   static_pages_help GET /static_pages/help(.:format)    static_pages#help
  static_pages_about GET /static_pages/about(.:format)   static_pages#about
static_pages_contact GET /static_pages/contact(.:format) static_pages#contact

When you create routes using match and get like that, you don't get named routes like help_path by default. 当使用match创建路由并get类似的路由help_path ,默认情况下不会获得诸如help_path的命名路由。 Run rake routes to see which routes are configured, and what their named helpers (if any) are. 运行rake routes以查看配置了哪些路由,以及它们的命名助手(如果有)是什么。 You likely don't have many named routes. 您可能没有太多的命名路线。

You can use :as to name your routes: 您可以使用:as来命名您的路线:

match '/help' => 'static_pages#help', :via => 'get', :as => 'help'

That will get you help_path and help_url . 那将为您提供help_pathhelp_url If you define routes using eg resources :help , a lot of that magic is done for you. 如果您使用诸如resources :help来定义路由,那么很多魔术就是为您完成的。 In the case of your routes to static assets, using :as is the best approach. 对于通往静态资产的路线,最好使用:as

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

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