# Standard test fails on RESTful controller

**URL:** <https://www.ruby-forum.com/t/standard-test-fails-on-restful-controller/71106>\
**Category:** Rails\
**Created:** [October 5, 2006, 11:16am UTC](https://www.ruby-forum.com/t/standard-test-fails-on-restful-controller/71106 "2006-10-05T11:16:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RJRJRJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@RJRJRJ](https://www.ruby-forum.com/u/RJRJRJ)\
**Post date:** [October 5, 2006, 11:16am UTC](https://www.ruby-forum.com/t/standard-test-fails-on-restful-controller/71106/1 "2006-10-05T11:16:03Z")

</div>

Hi all

I am messing around with RESTful controller using edge rails (revision  
5222) and am having the following problem. I have changed the function  
that is failing by adding the client name in the flasg but that it is  
and I haven’t changed the test code either but I am getting this error.  
The fact that “Expected” is empty makes me wonder if it is a bug in edge  
rails?

—Failure message—

1. Failure:  
test\_should\_create\_client(ClientsControllerTest)  
[./test/functional/clients\_controller\_test.rb:30]:  
\<3\> expected but was  
\<2\>.

—Controller code—

def create  
@client = Client.new(params[:client])

```
respond_to do |format|
  if @client.save
    flash[:notice] = @client.name + ' was successfully created.'

    format.html { redirect_to clients_url }
    format.xml do
      headers["Location"] = client_url(@client)
      render :nothing => true, :status => "201 Created"
    end
  else
    format.html { render :action => "new" }
    format.xml { render :xml => @client.errors.to_xml }
  end
end

```

end

—Test code—

def test\_should\_create\_client  
old\_count = Client.count  
post :create, :client =\> { }  
assert\_equal old\_count+1, Client.count

```
assert_redirected_to client_path(assigns(:client))

```

end

Any help would be much appreciated because the perfectionist in me  
refuses to commit and continue until all the tests are passing 🙂

RJ

---

<div class="post-metadata">

**Author:** ![RJRJRJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@RJRJRJ](https://www.ruby-forum.com/u/RJRJRJ)\
**Post date:** [October 5, 2006, 12:04pm UTC](https://www.ruby-forum.com/t/standard-test-fails-on-restful-controller/71106/2 "2006-10-05T12:04:37Z")

</div>

RJ wrote:

> Hi all
> 
> I am messing around with RESTful controller using edge rails (revision  
> 5222) and am having the following problem. I have changed the function  
> that is failing by adding the client name in the flasg but that it is  
> and I haven’t changed the test code either but I am getting this error.  
> The fact that “Expected” is empty makes me wonder if it is a bug in edge  
> rails?

Its not empty, it’s 3 🙂

If you take out the assert\_equal, does the assert\_redirectd\_to work ?

A\>

---

<div class="post-metadata">

**Author:** ![RJRJRJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@RJRJRJ](https://www.ruby-forum.com/u/RJRJRJ)\
**Post date:** [October 5, 2006, 12:52pm UTC](https://www.ruby-forum.com/t/standard-test-fails-on-restful-controller/71106/3 "2006-10-05T12:52:10Z")

</div>

Alan C Francis wrote:

> RJ wrote:
> 
> > Hi all
> > 
> > I am messing around with RESTful controller using edge rails (revision  
> > 5222) and am having the following problem. I have changed the function  
> > that is failing by adding the client name in the flasg but that it is  
> > and I haven’t changed the test code either but I am getting this error.  
> > The fact that “Expected” is empty makes me wonder if it is a bug in edge  
> > rails?
> 
> Its not empty, it’s 3 🙂
> 
> If you take out the assert\_equal, does the assert\_redirectd\_to work ?
> 
> A\>

Aaaah I thought that was some sort of line numbering. I thought the  
messages were “Expected FOO but was BAR”. Not “FOO expected but was  
BAR”…

Crawls back into the corner.

Ok, so why isn’t it registering the new client 😉

Thanks

RJ

---

<div class="post-metadata">

**Author:** ![RJRJRJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@RJRJRJ](https://www.ruby-forum.com/u/RJRJRJ)\
**Post date:** [October 5, 2006, 1:25pm UTC](https://www.ruby-forum.com/t/standard-test-fails-on-restful-controller/71106/4 "2006-10-05T13:25:53Z")

</div>

> > Ok, so why isn’t it registering the new client 😉
> 
> If you comment out the assert\_equal, and let the assert\_redirected\_to  
> have a go, you’ll be able to see if the controller method succeeds.
> 
> I think there must also be a way to assert the contents of the flash,  
> which you can try as long as you comment out the assert\_equal(which  
> stops the test in its tracks)
> 
> Alan

Whoops, that was me thinking to myself with my fingers, wasn’t actually  
looking for an answer 😉

But thanks regardless.

RJ

---

<div class="post-metadata">

**Author:** ![RJRJRJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@RJRJRJ](https://www.ruby-forum.com/u/RJRJRJ)\
**Post date:** [October 5, 2006, 1:06pm UTC](https://www.ruby-forum.com/t/standard-test-fails-on-restful-controller/71106/5 "2006-10-05T13:06:53Z")

</div>

RJ wrote:

> Aaaah I thought that was some sort of line numbering. I thought the  
> messages were “Expected FOO but was BAR”. Not “FOO expected but was  
> BAR”…
> 
> Crawls back into the corner.
> 
> Ok, so why isn’t it registering the new client 😉

If you comment out the assert\_equal, and let the assert\_redirected\_to  
have a go, you’ll be able to see if the controller method succeeds.

I think there must also be a way to assert the contents of the flash,  
which you can try as long as you comment out the assert\_equal(which  
stops the test in its tracks)

Alan
