Rails pages_controller_spec.rb 测试不应该失败,但是错误?

2024-03-07

一直在关注 Michael Hart 的 Rails 教程 Mac OS X 10.7 上的 Rails 版本 3.0

$ rspec 规范/

......FF

Failures:

  1) PagesController GET 'help' should be successful
     Failure/Error: get 'help'
     ActionController::RoutingError:
       No route matches {:controller=>"pages", :action=>"help"}
     # ./spec/controllers/pages_controller_spec.rb:45:in `block (3 levels) in <top (required)>'

  2) PagesController GET 'help' should have the right title
     Failure/Error: get 'help'
     ActionController::RoutingError:
       No route matches {:controller=>"pages", :action=>"help"}
     # ./spec/controllers/pages_controller_spec.rb:49:in `block (3 levels) in <top (required)>'

Finished in 0.14686 seconds
8 examples, 2 failures

Failed examples:

rspec ./spec/controllers/pages_controller_spec.rb:44 # PagesController GET 'help' should be successful
rspec ./spec/controllers/pages_controller_spec.rb:48 # PagesController GET 'help' should have the right title

测试看起来像这样:

require 'spec_helper'

describe PagesController do
  render_views

  describe "GET 'home'" do
    it "should be successful" do
      get 'home'
      response.should be_success
    end

    it "should have the right title" do
      get 'home'
      response.should have_selector("title",
      :content => "Ruby on Rails Tutorial Sample App | Home")
    end
  end

  describe "GET 'contact'" do
    it "should be successful" do
      get 'contact'
      response.should be_success
    end
    it "should have the right title" do
      get 'contact'
      response.should have_selector("title",
      :content => "Ruby on Rails Tutorial Sample App | Contact")
    end
  end

  describe "GET 'about'" do
    it "should be successful" do
      get 'about'
      response.should be_success
    end
    it "should have the right title" do
      get 'about'
      response.should have_selector("title",
      :content => "Ruby on Rails Tutorial Sample App | About")
    end
  end

  describe "GET 'help'" do
    it "should be successful" do
      get 'help'
      response.should be_success
    end
    it "should have the right title" do
      get 'help'
      response.should have_selector("title",
      :content => "Ruby on Rails Tutorial Sample App | Help")
    end
  end
end

我在pages_controller.rb中有

class PagesController < ApplicationController
  def home
    @title = "Home"
  end

  def contact
    @title = "Contact"
  end

  def about
    @title = "About"
  end

  def help
    @title = "Help"
  end

end

在routes.rb中我有

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

当然,我还在 app/views/pages 中创建了一个 help.html.erb 页面 奇怪的是,当我运行 Rails 服务器并转到 localhost:3000/pages/help 时,我得到了具有正确标题的正确页面,使其看起来好像测试应该已经通过,但事实并非如此。此外,联系人、主页和关于测试都通过了,但是当我刚刚添加帮助时,由于某种未知的原因,它没有通过。这真的让我很烦恼,我忽略了它让我发疯的简单解决方案是什么?


下载您的代码并运行:

........
8 examples, 0 failures
Finished in 0.18184 seconds

它正在运行 GET 'help',所以我认为您正在自动测试中运行它,并且它没有重新加载。可能的?

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Rails pages_controller_spec.rb 测试不应该失败,但是错误? 的相关文章

  • Ruby on Rails:Cucumber:如何点击打开新窗口的链接?

    我有一个在新窗口中打开的链接 我需要测试该新窗口中的应用程序部分 任何建议将不胜感激 定义一个包含以下代码的步骤 page driver browser switch to window page driver browser window
  • 在表单中编辑序列化哈希?

    我正在序列化存储在settings表中的字段 并且希望能够在表单字段中编辑该哈希 class Template lt ActiveRecord Base serialize settings end 但我就是这么做那么文本区域只显示序列化数
  • 如何在 Rails 上的 .yml 本地化文件中换行?

    我有一个带有一些本地化内容的 terms en yml 文件 例如 en devise registrations terms text This agreement was written in English US To the ext
  • 在 ruby​​ 中创建登录会话时理解“current_user”概念

    我正在阅读很棒的 Michael Hartl 教程来构建 ruby 应用程序here http ruby railstutorial org chapters sign in sign out sec 3acurrent user 我试图理
  • orchard cms路由问题

    我创建了一些自定义内容类型 其中包括路线部分 以便我的内容管理员可以编辑项目的别名 我没有运气配置一条路线 使我自己的控制器能够为这些项目的请求提供服务 核心 Routable 模块中到 ItemController 的路径的路由优先级为
  • GUI 测试工具 PyUseCase 与 Dogtail 相比如何?

    GUI测试工具如何Py用例 http pypi python org pypi PyUseCase重命名为故事文本 http pypi python org pypi StoryText 相比于Dogtail http en wikiped
  • 通过 jquery/javascript 在警报或确认对话框中单击“确定”?

    我正在考虑在backbone js 和jquery 中编写一些UI 测试 它们可能不是最好的方法 但这是我正在考虑的事情 通过纯代码自动化测试而无需记录和回放 使用这种方法唯一让我摸不着头脑的是 在某些 用例流程 执行的 中 会出现确认 警
  • 黄瓜与 RSpec

    我想开始深入研究 BDD 我以前从未使用过 TDD 现在 不确定我是否应该从学习 RSpec 开始 然后跳到 Cucumber 或者直接使用 Cucumber 我一直在互联网上阅读有关两者的内容 在我看来 Cucumber 可能是 RSpe
  • 绕过 dev/urandom|random 进行测试

    我想编写一个功能测试用例 用已知的随机数值来测试程序 我已经在单元测试期间用模拟对其进行了测试 但我也希望用于功能测试 当然不是全部 最简单的方法是什么 dev urandom仅覆盖一个进程 有没有办法做类似的事情chroot对于单个文件并
  • 如何测试 google.maps.Geocoder?

    你好 我正在尝试编写一个 简单 测试来检查反应类组件状态更改 具体来说 我正在测试如果 Google 成功对我发送的某些字符串 地址 进行地理编码 lat 纬度 和 lng 经度 状态是否会发生变化 这是我想测试的示例 i e the la
  • 如何使用backbone和requirejs定义/使用多个路由

    我将我的应用程序分成了几个应用程序 main js app js app1 routing controller app app2 routing controller app 1 当我尝试使用路由器时app1 他们工作 2 当我尝试使用路
  • 我应该如何使用 alias_method_chain 作为构建方法?

    我正在使用 Ruby on Rails 3 2 13 我想正确使用alias method chain build option name声明 因为我收到一个奇怪的错误 那是 在我的控制器文件中我有 class Articles Comme
  • 如何在 Symfony2 WebTestCase 中重定向后获取当前 URL?

    使用 Symfony2 WebTestCase 我进行了以下测试 client gt request GET this gt assertTrue client gt getResponse instanceof RedirectRespo
  • 在生产环境中使用 Rails 设置 sunspot solr

    我尝试了各种链接 但我似乎找不到关于创建与生产中的 Rails 一起运行的 solr 实例的好资源 我知道您必须为生产设置 solr 服务器 我已经尝试使用 tomcat 设置 solr 但我似乎无法将其链接到 Rails 应用程序 有什么
  • 如何检查字符串是否为有效日期

    我有一个字符串 31 02 2010 并想检查它是否是有效日期 最好的方法是什么 我需要一个方法 如果字符串是有效日期 则返回 true 如果不是 则返回 false require date begin Date parse 31 02
  • Rails 4 可安装引擎,找不到文件“jquery”

    我正在创建一个 Rails 可安装引擎插件 它使用 gem jquery rails 我在 gemspec 文件中添加了这段代码 s add dependency jquery rails gt 3 0 1 and run bundle i
  • 如何使用sunspot_rails gem 搜索相关文章

    我有一个迷你博客应用程序 我希望用户查看与他们在文章显示页面中阅读的内容相关的文章 没有 sunspot rails gem 我会做这样的事情 在我的模型中 def self related search query join AND fi
  • 从数组中删除空白元素

    当我从 ruby on Rails 表单中保存多个选择时 它似乎在前面添加了一个空白元素 我该如何删除它 该字段为 selected player utf8 gt authenticity token gt H8W7qPBezubyeU0a
  • Gem 在 irb 中可用,但在 Rails 控制台中不可用

    我正在尝试在我的 Rails 项目中使用 RedCloth gem 当我使用irb我可以加载宝石 require rubygems require RedCloth 它工作正常 但是当我在 Rails 控制台中尝试相同的操作时 我收到一条错
  • 如何启用 vstest.console.exe 日志记录?

    我试图查看在 Visual Studio 2013 中运行测试时究竟执行了什么 vstest 命令 如何启用 vstest console exe 日志记录 执行的命令是带有相关参数的 VSTest Console exe 当您运行测试时

随机推荐