Amit,
Your controller spec that you said was working was not actually testing your
controller since you were not calling any of your controller methods.
I''d suggest you create some code from rspec_scaffold on your rails
project
and just check out the code that''s generated for you.
ruby script/generate rspec_scaffold BpPost title:string body:text
On Tue, Oct 27, 2009 at 9:10 AM, Amit Kulkarni <lists at ruby-forum.com>
wrote:
> Hello everybody,
> I had written same scenario using normal code which is as follows :
> def valid_attributes
> {
> :body => "test_description",
> :title => "test123",
> }
> end
>
> describe BbPostsController, "POST Create" do
> before(:each) do
> @post = BbPost.new
> end
> context "Admin" do
> fixtures :users, :bb_posts
> @user = User.find_by_login("kiran")
> if @user
> it "should create post" do
> @post = create_post
> @post.save
> @post.should be_valid
> end
> end
> end
>
> def create_post
> args ||= valid_attributes
> BbPost.create args
> end
> end
>
> The above code is working.Now i want to try my hand on using mocks so i
> write some code using the mocks which is as follows:
>
>
> it "should create post" do
> BbPost.should_receive(:new).with("title" =>
"Test123" ,"body" =>
> "test_description", "abstract" =>
"test_abstract")
> post :create, :bb_post => { "title" =>
"Test123" ,"body" =>
> "test_description", "abstract" =>
"test_abstract" }
> end
>
> it is showing me error which is as follows :
>
> Spec::Mocks::MockExpecttionError in ''BbPostsController POST Create
admin
> should create post''
> <BbPost(id: integer, body: text, title: string,(clss)> expected :new
> with ({"body"=>"test_description",
"title"=>"Test123"}) once, but
> received it 0 ti
> mes
>
> Please suggest if something is wrong.
> I am referring to Rspec book.Also in that they had given seperate method
> of save.But like the upper one i want to do in one scenario.Is it
> possible?Please clarify
>
> Also i want to know the whether above code which is running fine
> actually uses create method of model.I think it does not uses the
> "create method of controller".Please suggest what to do in this
case.
> :-)
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
--
Att,
- Caike
http://caikesouza.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/rspec-users/attachments/20091027/a49b1173/attachment.html>