require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe TasksController do mock_models :task describe :get => :index do expects :find, :on => Task, :with => :all, :returns => mock_task should_assign_to :tasks, :with => mock_task describe Mime::XML do expects :to_xml, :on => mock_task, :returns => 'generated xml' should_assign_to :tasks, :with => mock_task should_respond_with :body => /generated_xml/, :content_type => Mime::XML end end describe :get => :show, :id => '37' do expects :find, :on => Task, :with => '37', :returns => mock_task should_assign_to :task, :with => mock_task describe Mime::XML do expects :to_xml, :on => mock_task, :returns => 'generated xml' should_assign_to :task, :with => mock_task should_respond_with :body => /generated_xml/, :content_type => Mime::XML end end describe :get => :new do expects :new, :on => Task, :returns => mock_task should_assign_to :task, :with => mock_task end describe :get => :edit, :id => '37' do expects :find, :on => Task, :with => '37', :returns => mock_task should_assign_to :task, :with => mock_task end describe :post => :create, :task => {:these => 'params'} do expects :new, :on => Task, :with => {'these' => 'params'}, :returns => mock_task describe "with valid params" do expects :save, :on => mock_task, :returns => true should_assign_to :task, :with => mock_task should_redirect_to { task_url(mock_task) } end describe "with invalid params" do expects :save, :on => mock_task, :returns => false should_assign_to :task, :with => mock_task should_render_template 'new' end end describe :put => :update, :id => "37", :task => {:these => 'params'} do expects :find, :on => Task, :with => '37', :returns => mock_task describe "with valid params" do expects :update_attributes, :on => mock_task, :with => {'these' => 'params'}, :returns => true should_assign_to :task, :with => mock_task should_redirect_to { task_url(mock_task) } end describe "with invalid params" do expects :update_attributes, :on => mock_task, :with => {'these' => 'params'}, :returns => false should_assign_to :task, :with => mock_task should_render_template 'edit' end end describe :delete => :destroy do expects :find, :on => Task, :with => '37', :returns => mock_task expects :destroy, :on => mock_task should_assign_to :task, :with => mock_task should_redirect_to { tasks_url } end end