Responses shown below...<br><br>Sorry this isn&#39;t extremely informative ... in a bit of a rush. Hopefully it will point you in the appropriate direction.<br><br><div class="gmail_quote">On Sun, Apr 6, 2008 at 2:17 PM, newbie &lt;<a href="mailto:alen198@gmail.com">alen198@gmail.com</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I&#39;m new to Rspec and I&#39;m having a bit of trouble with this controller<br>
that I&#39;m testing. I think I&#39;m doing it right but I guess my syntax is<br>
wrong.<br>
I&#39;m currently using the &quot;acts_as_authenticated&quot; plug in.<br>
<br>
What I want to test out is<br>
<br>
EventController on entering the tickets_page<br>
- should show the tickets_page &nbsp;if the current_user has NOT entered<br>
this page today<br>
<br>
<br>
-----------------------------------------------------<br>
Below is my event controller<br>
-----------------------------------------------------<br>
<br>
class EventController &lt; ApplicationController<br>
<br>
&nbsp;before_filter :login_required<br>
<br>
 &nbsp;def tickets_page<br>
 &nbsp; &nbsp; &nbsp;if current_user.has_already_entered_today?<br>
 &nbsp; &nbsp; &nbsp; &nbsp;flash[:notice] = &#39;Come back tomorrow&#39;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;redirect_to :action =&gt; &#39;home&#39;<br>
 &nbsp; &nbsp; &nbsp;else<br>
 &nbsp; &nbsp; &nbsp; &nbsp;flash[:notice] = &#39;Welcome&#39;<br>
 &nbsp; &nbsp; &nbsp;end<br>
 &nbsp;end<br>
end<br>
<br>
<br>
-----------------------------------------------------<br>
Below is my rspec for this controller<br>
-----------------------------------------------------<br>
<br>
require File.dirname(__FILE__) + &#39;/../spec_helper&#39;<br>
describe EventController do<br>
<br>
 &nbsp;before(:each) do<br>
 &nbsp; &nbsp;@current_user = mock_model(User, :id =&gt; 1)<br>
 &nbsp; &nbsp;controller.stub!(:current_user).and_return(@current_user)<br>
 &nbsp; &nbsp;controller.stub!(:login_required).and_return(:true)<br>
 &nbsp;end<br>
<br>
 &nbsp;fixtures :users<br>
<br>
<br>
 &nbsp;describe &quot;on entering the tickets page&quot; do<br>
 &nbsp; &nbsp;it &quot;should show the tickets_page &nbsp;if the current_user has NOT<br>
entered this page today&quot; do<br>
 &nbsp; &nbsp; controller.current_user.stub!<br>
(:has_already_entered_today?).and_return(:false)<br>
 &nbsp; &nbsp; get :tickets_page<br>
<br>
controller.current_user.should_receive(:has_already_entered_today?).with(:false).and_return(:false)<br>
 &nbsp; &nbsp; response.should render_template(:tickets_page)<br>
 &nbsp; &nbsp;end<br>
end<br>
<br>
end<br>
<br>
-----------------------------------------------------<br>
My errors<br>
-----------------------------------------------------<br>
Mock &#39;User_1001&#39; received unexpected<br>
message :has_already_entered_today? with (no args)</blockquote><div><br>So this is a good start ... it means that the controller action is actually being mocked out ... you just need to keep moving forward mocking/stubbing out the rest of your controller actions. it&#39;s complaining that it doesn&#39;t know what to do on your <i>current_user.has_already_entered_today?</i> method.<br>
</div><div><br>@current_user.stub!(:has_already_entered_today?).and_return(&lt;insert true or false here&gt;)<br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
<br>
Anyone can help with any direction of what I might be doing wrong?<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
rspec-users mailing list<br>
<a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank">http://rubyforge.org/mailman/listinfo/rspec-users</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Bryan Ray<br><a href="http://www.bryanray.net">http://www.bryanray.net</a><br><br>&quot;Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.&quot;