我用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
(这是错误出现在......下面的行)
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
end
end
end
感谢您的关注
答案 0 :(得分:0)
所以,你有一个失败的规范。规范本身看起来不错。所以我会检查
如果实施有效,请仔细检查规格。是提供的信息
fill_in“电子邮件”,:with => “user@example.com” fill_in“密码”,:with => “foobar的”
足以创建用户吗?
此外:
好吧,正如我所说,这应该是一个集成测试 - 将它从spec / controllers移动到spec / requests文件夹(并且确实改变了第一行,因为你没有描述UsersController!但是这不应该导致问题)。