ruby-on-rails – Nil不是Rspec的象征
发布时间:2020-12-17 01:52:38 所属栏目:百科 来源:网络整理
导读:当我在我的localhost上以开发模式运行时.一切正常,我可以轻松删除我的帖子.但我的要求规格失败了. 当我运行测试时,我收到此错误: 1) Posts when logged in should delete posts Failure/Error: expect{click_on "Usuń spot"}.to change(Post.count).by(1)
当我在我的localhost上以开发模式运行时.一切正常,我可以轻松删除我的帖子.但我的要求规格失败了.
当我运行测试时,我收到此错误: 1) Posts when logged in should delete posts Failure/Error: expect{click_on "Usuń spot"}.to change(Post.count).by(1) TypeError: nil is not a symbol posts_spec.rb describe "when logged in" do let(:user) {FactoryGirl.create(:user)} let!(:post) {user.posts.create(content: "Brilliant! I just saw the most amazing ever. She looked so cute!")} content = "Example of spot post,for TDD. It's not real spot. Not yet." before(:each) { log_user(user) } it "should delete posts" do visit user_post_path(user,post) expect{click_on "Usuń spot"}.to change(Post.count).by(1) end show.haml =@post.content =link_to "Usuń spot",[@user,@post],method: :delete posts_controller.rb def show @user = current_user @post = @user.posts.find(params[:id]) end def destroy @user = current_user @post = @user.posts.find_by_id(params[:id]) @post.destroy flash[:success] = "Post destroyed" redirect_to root_url end 解决方法
更改需要一个块,因此可以对其进行两次评估以验证值的更改.
这应该工作: expect{click_on "Usuń spot"}.to change{Post.count}.by(1) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |