Re: [Rails] Help with functional test
Guru Cifani lol
2012/5/23 thiagocifani <cifani.thiago@gmail.com>
Are u using mocha? If you are using mocha, I think you should write something like that:mock('post', hash)regards--2012/5/23 Kleber Shimabuku <klebershimabuku@gmail.com>
Hi guys,I'm starting to write tests and I writing a functional test for my 'create' action.So, basically I have the following test:describe '#create' do@attributes = { title: 'New post', description: 'Please add some text here', location: 'Anywhere' }context 'when logged in' dologin_userbefore { post :create, @attributes }it 'should create a new post' dopost = mock(Post, @attributes)assigns(:post).should_not be_nilPost.should_receive(:save).and_return(post)response.should redirect_to successful_submitted_posts_pathendit 'should NOT create a new post' doendendcontext 'when NOT logged in' dobefore { post :create, @attributes }it { response.should_not be_successful }it { response.should redirect_to new_user_session_path }endendBut it's failing and I don't get understand why.1) PostsController#create when logged in should create a new postFailure/Error: post = mock(Post, @attributes)ArgumentError:wrong number of arguments (3 for 2)# ./spec/controllers/posts_controller_spec.rb:40:in `block (4 levels) in <top (required)>'Finished in 0.77996 seconds6 examples, 1 failurewhy mock method expects 3 arguments? what they should be?I have read on some blogs this kind of syntax.mock(Object, hash)And this is my controller:# encoding: utf-8class PostsController < ApplicationControllerload_and_authorize_resourcebefore_filter :authenticate_user!respond_to :htmldef new@post = Post.newenddef create@post = current_user.posts.build(params[:post])if @post.saveredirect_to successful_submitted_posts_pathelserender :newendenddef successful_submitted; endendWhat I'm doing wrong?Please give me some hints.Thank you.--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/ouy4grWHNOwJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
thiagocifani
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
--
att,
Rogerio
A complicação se descomplica na mesma proporção que fazemos os nós se desatarem ao tecer o conhecimento do saber.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home