首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails 3教程第8章集成测试失败

Rails 3教程第8章集成测试失败
EN

Stack Overflow用户
提问于 2013-08-15 03:36:28
回答 1查看 257关注 0票数 0

我一直在学习Michael的Rails 3教程。一直持续到第八章的整合测试。我运行了以下命令来创建集成测试:

代码语言:javascript
复制
rails generate integration_test users

它创建了一个文件,然后我添加了两个测试:一个用于失败(空表单),一个用于成功(实际有效的表单字段)。

下面是上面的命令生成的users_spec.rb文件:

代码语言:javascript
复制
require 'spec_helper'
require 'database_cleaner'

describe "Users" do

  describe "GET /users" do
    it "works! (now write some real specs)" do
      # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
      get users_index_path
      response.status.should be(200)
    end
  end

  describe "signup" do

    describe "failure" do
      it "should not make a new user with empty data" do
        lambda do
          visit signup_path
          fill_in "Name",         :with => ""
          fill_in "Email",        :with => ""
          fill_in "Password",     :with => ""
          fill_in "Confirmation", :with => ""
          click_button
          response.should render_template('users/new')
          response.should have_selector("div#error_explanation")
        end.should_not change(User, :count)
      end #end "should not make a new user with empty data" do
    end #end describe failure

    describe "success" do
      it "should make a new user" do
        lambda do
          visit signup_path
          fill_in "Name",         :with => "Example User"
          fill_in "Email",        :with => "user@example.com"
          fill_in "Password",     :with => "foobar"
          fill_in "Confirmation", :with => "foobar"
          click_button
          response.should have_selector("div.flash.success", :content => "Welcome")
          response.should render_template('users/new')
        end.should change(User, :count).by(1)
      end
    end #end success
  end #end describe signup
end #end describe Users

我不知道为什么,但所有的测试都失败了,虽然它们不应该。我是不是遗漏了一些显而易见的东西?我已经运行了rake :迁移,清除了DB,但我就是不明白。

控制台错误来自:rspec spec/requests/users_spec.rb

代码语言:javascript
复制
JorgeZapata:sample_app jorgezapata$ rspec spec/requests/users_spec.rb
Rack::File headers parameter replaces cache_control after Rack 1.5.
FFF

Failures:

  1) Users GET /users works! (now write some real specs)
     Failure/Error: get users_index_path
     NameError:
       undefined local variable or method `users_index_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007ffd9bbd6550>
     # ./spec/requests/users_spec.rb:8:in `block (3 levels) in <top (required)>'

  2) Users signup failure should not make a new user with empty data
     Failure/Error: visit signup_path
     ActionView::Template::Error:
       /Users/jorgezapata/rails_projects/sample_app/app/views/users/new.html.erb:17: syntax error, unexpected tSTRING_BEG, expecting ')'
       ....label :password_confirmation "Confirmation" );@output_buffe...
       ...                               ^
     # <internal:prelude>:10:in `synchronize'
     # ./spec/requests/users_spec.rb:18:in `block (5 levels) in <top (required)>'
     # ./spec/requests/users_spec.rb:17:in `block (4 levels) in <top (required)>'

  3) Users signup success should make a new user
     Failure/Error: visit signup_path
     ActionView::Template::Error:
       /Users/jorgezapata/rails_projects/sample_app/app/views/users/new.html.erb:17: syntax error, unexpected tSTRING_BEG, expecting ')'
       ....label :password_confirmation "Confirmation" );@output_buffe...
       ...                               ^
     # <internal:prelude>:10:in `synchronize'
     # ./spec/requests/users_spec.rb:33:in `block (5 levels) in <top (required)>'
     # ./spec/requests/users_spec.rb:32:in `block (4 levels) in <top (required)>'

Finished in 0.12243 seconds
3 examples, 3 failures

Failed examples:

rspec ./spec/requests/users_spec.rb:6 # Users GET /users works! (now write some real specs)
rspec ./spec/requests/users_spec.rb:16 # Users signup failure should not make a new user with empty data
rspec ./spec/requests/users_spec.rb:31 # Users signup success should make a new user

谢谢,请提前告知!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-15 04:03:34

你在错误中得到了答案。

1:

代码语言:javascript
复制
undefined local variable or method `users_index_path'

这条路根本不存在。从控制台运行rake routes以获取可用路由的列表。很有可能是users_path

2和3:

代码语言:javascript
复制
ActionView::Template::Error:
   /Users/jorgezapata/rails_projects/sample_app/app/views/users/new.html.erb:17: syntax error, unexpected tSTRING_BEG, expecting ')'

在第17行的app/view/user/new.html.erb文件中有一个语法错误。

学习读取错误输出。它告诉你你需要知道的一切(通常)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18245959

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档