Responses shown below...<br><br>Sorry this isn'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 <<a href="mailto:alen198@gmail.com">alen198@gmail.com</a>> 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'm new to Rspec and I'm having a bit of trouble with this controller<br>
that I'm testing. I think I'm doing it right but I guess my syntax is<br>
wrong.<br>
I'm currently using the "acts_as_authenticated" 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 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 < ApplicationController<br>
<br>
before_filter :login_required<br>
<br>
def tickets_page<br>
if current_user.has_already_entered_today?<br>
flash[:notice] = 'Come back tomorrow'<br>
redirect_to :action => 'home'<br>
else<br>
flash[:notice] = 'Welcome'<br>
end<br>
end<br>
end<br>
<br>
<br>
-----------------------------------------------------<br>
Below is my rspec for this controller<br>
-----------------------------------------------------<br>
<br>
require File.dirname(__FILE__) + '/../spec_helper'<br>
describe EventController do<br>
<br>
before(:each) do<br>
@current_user = mock_model(User, :id => 1)<br>
controller.stub!(:current_user).and_return(@current_user)<br>
controller.stub!(:login_required).and_return(:true)<br>
end<br>
<br>
fixtures :users<br>
<br>
<br>
describe "on entering the tickets page" do<br>
it "should show the tickets_page if the current_user has NOT<br>
entered this page today" do<br>
controller.current_user.stub!<br>
(:has_already_entered_today?).and_return(:false)<br>
get :tickets_page<br>
<br>
controller.current_user.should_receive(:has_already_entered_today?).with(:false).and_return(:false)<br>
response.should render_template(:tickets_page)<br>
end<br>
end<br>
<br>
end<br>
<br>
-----------------------------------------------------<br>
My errors<br>
-----------------------------------------------------<br>
Mock 'User_1001' 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's complaining that it doesn'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(<insert true or false here>)<br> </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>"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."