我正在尝试运行此测试,但由于某种原因它失败了。
describe "User Pages" do
subject { page }
.
.
describe "Sign up" do
before { visit signup_path }
let(:submit) { "Sign Me Up" }
.
.
describe "with valid information" do
before do
fill_in "name", with: "newuser"
fill_in "Username", with: "user254"
fill_in "Email", with: "user@yahoo.com"
select "Male", from: "gender"
fill_in "Password", with: "password"
fill_in "Confirm Password", with: "password"
end
it "Should create a user" do
expect { click_button submit}.to change(User, :count).by(1)
end
end
但是,当我运行测试时,出现此错误
Failures:
1) User Pages 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/requests/user_pages_spec.rb:35:in `block (4 levels) in <top (required)>'
Finished in 4.61 seconds
35 examples, 1 failure
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:34 # User Pages signup with valid information Should create a user
这是我在控制器中的创建操作
def create
@user = User.new(params[:user])
if @user.save
redirect_to @user
else
render 'new'
end
end
当我尝试在浏览器中注册时,注册成功。我的测试有什么问题吗?谢谢