On Feb 7, 2008 2:27 PM, Rick DeNatale <[EMAIL PROTECTED]> wrote: > I've got a controller which produces an RSS feed, pretty much based on > Ryan Bates recent RailsCast. > > I'm having a heck of a time getting the spec to successfully fetch the > feed though. I gave up got it working without a spec, and I'm now > trying to back up and get the spec to work. > > The controller is simplicity itself: > > class PodcastRssFeedController < ApplicationController > > def index > @podcasts = Podcast.latest(100) > end > > end > > I have a route which gets to the index action and sets :format => > :rss, as I said this produces a valid rss response in the real world, > just not in the spec. > > Here's the basic spec: > > require File.dirname(__FILE__) + '/../spec_helper' > require File.dirname(__FILE__) + '/../be_valid_feed' > > def mock_podcast(i) > mock_model( > Podcast, > :artist_name_slug => "Artist#{i}" > ) > end > > describe PodcastRssFeedController do > > before(:all) do > @podcasts = (1..5).map {|i| mock_podcast(i)} > Podcast.stub!(:latest).and_return(@podcasts) > end > > describe 'handling GET brightsidepodcasts/rss.xml' do > > def do_get > @request.format = 'rss' > get 'index', :format => :rss > end > > it "should successfully get feed" do > do_get > response.should be_success > end > > it "should validate" do > do_get > response.should be_valid_feed > end > end > > end > > The validation example is failing because the response body is being returned > as > podcast_rss_feed/index > > I've tried stepping through with rdebug and I can't figure out where > it's going wrong. > > I eventually end up here: > > 1099 logger.info("Rendering #{template_path}" + (status ? > " (#{status})" : '')) if logger > => 1100 render_for_text(@template.render_file(template_path, > use_full_path, locals), status) > 1101 end > 1102 > 1103 def render_for_text(text = nil, status = nil, > append_response = false) #:nodoc: > 1104 @performed_render = true > /Users/rick/Documents/terralien/brightside/site/vendor/rails/actionpack/lib/action_controller/base.rb:1100 > > When I s(tep) into this I end up here: > > 173 @template.metaclass.class_eval do > 174 define_method :file_exists? do > 175 true > 176 end > 177 define_method :render_file do |*args| > => 178 @first_render ||= args[0] > 179 end > 180 end > 181 end > 182 end > /Users/rick/Documents/terralien/brightside/site/vendor/plugins/rspec_on_rails/lib/spec/rails/example/controller_example_group.rb:178 > > It looks like the real ActionView::Base.render_file never gets called > and that's where it looks like the realization that it's looking for > rss rather than say html seems to happen. > > Can anyone shed any light on this?
Try integrate_views: describe PodcastRssFeedController do integrate_views ... end Without that, render gets modified by rspec (to isolate your controllers from their views). HTH, David > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users