[rspec-users] How to do controller.stub(:some_method) at request test when using rspec2

Jiang Guimin lists at ruby-forum.com
Thu Mar 3 02:36:29 EST 2011


Hi,
  I hava a controller

  class DynamicFlowsController < ApplicationController

   def create
      @workflow = Workflow.find_by_id(params[:workflow_id])
      table = @workflow.flex_table
       save_u_and_node(table, @workflow.node_definition)
       redirect_to "/#{table.name}"
   end

  end

  and I had written some rspec codes

   describe "save attachment" do

    before(:each) do
      workflow, table, form = init_stubs("baoxiaos", 1)
      definition = workflow.node_definition
      controller.should_receive(:save_u_and_node).with(table,
definition)
    end

    it "should be successful" do
      file = UploadFile.new("a" * 10000, "testfile", "text/plain")
      post '/workflows/1/baoxiaos', { :attachment => file}
      response.should be_successful
    end

  end

When I run the test, unfortunately rspec told me that "controller"  is
nil, I got a fail test.
So, I want to konw how to get the correct "controller" object.

Thanks
Kayak

-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list