Ruby on rails 失败/错误:预期{单击按钮提交}

Ruby on rails 失败/错误:预期{单击按钮提交},ruby-on-rails,testing,rspec,Ruby On Rails,Testing,Rspec,我在用rspec测试,我还在学习,我想我走对了路。。。但是当我测试我的rspec文件时,我得到了以下错误: Failures: 1) UsersController signup with valid information should create a user Failure/Error: expect { click_button submit }.to change(User, :count).by(1) count should have been changed by

我在用rspec测试,我还在学习,我想我走对了路。。。但是当我测试我的rspec文件时,我得到了以下错误:

 Failures:

1) UsersController signup with valid information should create a user
 Failure/Error: expect { click_button submit }.to change(User, :count).by(1)
   count should have been changed by 1, but was changed by 0
 # ./spec/controllers/user_controller_spec.rb:31

Finished in 1.16 seconds
2例,1例失败

我知道这意味着什么,但我不知道如何解决它,谁能帮我解决这个问题请…我把我的rspec文件

require 'spec_helper'

describe UsersController do


describe "signup" do

before { visit new_user_registration_path }

let(:submit) { "Sign up" }

describe "with invalid information" do
  it "should not create a user" do
    expect { click_button submit }.not_to change(User, :count)
  end
end

describe "with valid information" do
  before do
    fill_in "Email", :with=> "user@example.com"
    fill_in "Password", :with=> "foobar"
    #fill_in "password_confirmation", :with=> "foobar"
  end
(此处显示的是错误…在第行下方)


感谢您的关注

因此,您的规范失败了。规范本身看起来还可以。所以我会去看看

  • 实施到位了吗?您可以在浏览器中尝试该方案。那里行吗?如果不是,那么您的测试失败了(这很好),需要添加实现
  • 如果实现有效,请再次仔细检查规范。是否提供了相关信息

    在“电子邮件”中填写:“=>”user@example.com" 填写“密码”:使用=>“foobar”

    足以创建用户吗

  • 如果仍然没有找到原因,可以使用capybaras save_和open_页面(为此安装launchy gem),并在测试期间查看页面
补充:


好的,正如我所说的,这应该是一个集成测试-将它从spec/controllers移到spec/requests文件夹(并更改第一行,因为您没有描述UsersController!但这不会导致问题)。

ps:如果您在调查中遇到问题,请发布rspec的实际故障(在输出中进一步)-还有一件事我注意到了:这是集成测试还是控制器测试?(它位于哪里?)-从文件中我可以说是一个集成测试,但它说的是描述UsersController。关于这一点的讨论,请参阅。感谢您的回答,阅读您的帖子,我想规范是不够的,因为实现是有效的。那么,您可以发布失败规范的完整输出吗?您使用的是哪个框架?网鼠还是水豚?我刚刚将我非常相似的集成测试移到controllers文件夹中,得到了非常不同的错误消息:6)提交失败后用户页面注册信息无效/错误:在{vist signup_path}之前NameError:undefined局部变量或###./spec/controllers/user_pages_spec.rb:22:inblock(3层)in',因为在水豚控制器规范中,视图不会呈现,正如我在上面发布的链接中详细解释的那样。
      it "should create a user" do
         expect { click_button submit }.to change(User, :count).by(1)
      end
   end
  end
end