ruby on rails - Can't figure out what's wrong with this error: syntax error, unexpected tLABEL, expecting '=', in my Rspec test? -
i getting error:
comments_controller_spec.rb:12: syntax error, unexpected tlabel, expecting '=' ...ate, post_id: post.id, comment: attributes_for(:comment)}.to... ^
when running spec file comments_controller_spec.rb:
require 'rails_helper' describe commentscontroller describe "post #create" comment = create(:comment) post = comment.post "properly creates comment" expect{post :create, post_id: post.id, comment: attributes_for(:comment)}.to change(comment, :count).by(1) end end end
which can gather reading other posts haven't closed block or hash. i've been looking on again , again , can't find isn't closed properly. seems pointing post method source of problem, believe have passed in of it's arguments. i'm not sure else wrong. can tell going on here? help.
updated:
i changed test this:
it "properly creates comment" expect {post(:create, post_id: post.id, comment: attributes_for(:comment))}.to change(comment, :count).by(1) end
and error message is:
commentscontroller post #create creates comment failure/error: expect {post(:create, post_id: post.id, comment: attributes_for(:comment))}.to change(comment, :count).by(1) argumenterror: wrong number of arguments (given 2, expected 0) # ./spec/controllers/comments_controller_spec.rb:13:in `block (4 levels) in <top (required)>' # ./spec/controllers/comments_controller_spec.rb:13:in `block (3 levels) in <top (required)>'
and here post_factory.rb:
factorygirl.define factory :post content "this post content!" user end end
i believe change
matcher expects block:
expect{post :create, post_id: post.id, comment: attributes_for(:comment)}.to change{ comment.count }.by(1)
if that's not it, try adding brackets around arguments post
, thinking perhaps parser having issues:
expect{ post(:create, post_id: post.id, comment: attributes_for(:comment)) }.to change{ comment.count }.by(1)
as last resort, do:
expect post(:create, post_id: post.id, comment: attributes_for(:comment)) end.to change{ comment.count }.by(1)
Comments
Post a Comment