【发布时间】:2013-06-30 11:06:48
【问题描述】:
我正在尝试编写一些 RSpec 测试来测试我的应用程序,但我偶然发现了几个我找不到任何解决方案的问题。 1)我正在尝试测试更新操作。这是我的代码:
it "email is a new one" do
put :update, id: @user, user: FactoryGirl.attributes_for(:user, :email=>"a@b.c")
@user.reload
@user.email.should == "a@b.c"
puts @user.email
end
这是 UsersController 更新操作:
def update
@user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to edit_user_path(@user), :notice => "Your settings were successfully updated."}
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
这是错误:
Failure/Error: @user.email.should == "a@b.c"
expected: "a@b.c"
got: "user16@example.com" (using ==)
很明显,测试并没有改变用户的电子邮件。 我从这里获取了更新操作教程:http://everydayrails.com/2012/04/07/testing-series-rspec-controllers.html。 我在哪里可以找到解决方案?
【问题讨论】:
-
您将工厂分配给联系人,而不是用户...是这样的吗?
-
对不起。忘记换了。为了避免错别字,我已经多次编写并复制了它。但问题依然存在。
标签: ruby-on-rails rspec crud put