Re: [rspec-users] having trouble specing an ajax request
Sorry I pasted the wrong spec. Here is correct one - it "should show deals listing" do controller.stub!(:prepare_search_conditions).and_return(true) Deal.should_receive(:paginate).and_return(@deals) get :index controller.expect_render(:partial => '/deals/front/listing') end > Thanks, > Namrata. -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] having trouble specing an ajax request
Do I need to spec an AR. If yes, what is the best way to spec this. here is the code - def index @deals = Deal.paginate(:all, :conditions => prepare_search_conditions, :order => 'created_at DESC', :page => params[:page] ) if request.xhr? render :update do |page| page.replace_html "table", :partial => "/deals/front/listing" end end I am new to Rspec. Is this the right way? it "should list all deals" do controller.stub!(:prepare_search_conditions).and_return(true) Deal.should_receive(:paginate).with(:all, {:conditions=>true, :order=>"created_at DESC", :page=>nil}).and_return(@deals) get :list controller.expect_render(:partial => '/deals/cms/list') end Thanks, Namrata. -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] stuck on testing validation
Here is a very good example by Luke, which I think you should follow - http://www.lukeredpath.co.uk/2006/8/29/developing-a-rails-model-using-bdd-and-rspec-part-1 fyi, Namrata -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] rspec controller action list
Followed your example! Still getting the following error - Spec::Mocks::MockExpectationError in 'ArticlesController should list all article s' Mock 'ArticlesController' expected :find_city with (any args) once, but received it 0 times spec/controllers/articles_controller_spec.rb:3: Thanks, Namrata -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] rspec controller action list
Here is the action - def list @articles = find_city.articles.paginate :all, :page => params[:page] , :order => "live_on DESC", :conditions => { :type_for => "blog" } end and the spec - it "should list all articles 2" do articles = mock("articles") get :list controller.should_receive(:find_city).and_return(articles) controller.should_receive(:articles) articles.should_receive(:paginate).with(:order => "live_on DESC", :conditions => { :type_for => "blog" }) response.should render_template('articles/list') end I am stubbing find_city and articles during set up before_post do controller.stub!(:find_city) controller.stub!(:articles) end Is this right? -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] rspec controller action list
> > If the code is the same as it was in the first post in this thread, > it's because the action is taking place before setting the > expectations. Yes, it is the same. As you have suggested earlier. I am pasting the spec again. #list it "should list all articles" do articles = mock("articles") articles.should_receive(:paginate).with(:order => "live_on DESC", :conditions => { :type_for => "blog" }) controller.should_receive(:find_city).and_return(articles) response.should be_success get :list end Thx, Namrata. -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] rspec controller action list
Matthias Hennemeyer wrote: > Am 03.03.2008 um 04:38 schrieb Namrata Tiwari: > >> The method find_city is in application controller. I think the method >> 'find_city' is being called but its expecting some args. >> > The message: > > Mock 'ArticlesController' expected :find_city with (any args) once, but > received > it 0 times > > means that the method find_city was *not* called. > > If the original method expects args or not doesn't matter. > Because should_receive works as both an expectation and a stub, the > original method will not be called and no ArgumentError will be raised. Okaayyy! Then can you also please say why its not calling this :find_city method? Thx, Namrata. -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] rspec controller action list
Bryan Ray wrote: > It has to do with your "find_city" method. You spec is expecting it to > be > called from controller, hence: > > controller.should_receive(:find_city) > > Where is that method and why isn't it being called should be your next > questions based on the code and spec you've pasted. > The method find_city is in application controller. I think the method 'find_city' is being called but its expecting some args. Thanks, Namrata. -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] rspec controller action list
Thanks Mr David for your reply. This gives me a better understanding of so called train wreck. I am still facing problems with this spec. firstly - I think I need to put a colon before order(e.g. :order=> "live_on DESC") #list it "should list all articles" do articles = mock("articles") articles.should_receive(:paginate).with(:order => "live_on DESC", :conditions => { :type_for => "blog" }) controller.should_receive(:find_city).and_return(articles) get :list end but this gives me the following error Spec::Mocks::MockExpectationError in 'ArticlesController should list all article s' Mock 'ArticlesController' expected :find_city with (any args) once, but received it 0 times spec/controllers/articles_controller_spec.rb:3: Thanks, Namrata. -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] rspec controller action list
This action will list all the articles according to city. Please, can some one guide me through this spec. def list @articles = find_city.articles.paginate :all, :page => params[:page] , :order => "live_on DESC", :conditions => { :type_for => "blog" } end it "should list all articles" do get :list controller.stub!(:find_city) controller.should_receive(:find_city) controller.stub!(:articles) controller.should_receive(:articles) articles.should_receive(:paginate).and_return(@articles) response.should render_template('articles/list') end I get the following error when I run the spec. NameError in 'ArticlesController should list all articles' undefined local variable or method `articles' for # spec/controllers/articles_controller_spec.rb:212: spec/controllers/articles_controller_spec.rb:3: -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users