*My login page has a login form with three fields:login,password,and image verification code,now how to test it?* require File.dirname(__FILE__) + "/../spec_helper" # http://www.kirkbushell.com/articles/testing-using-rspec-part-2-the-controller # http://blog.enjoyrails.com/2008/02/18/rspec-basic/ # http://rails.anyware-technologies.com.br/2009/04/21/tdd-on-rails-4-rspec-authlogic-factory_girl-and-resource_controller/ # http://matthewkwilliams.com/index.php/tag/rspec/ describe AdminController do integrate_views before(:each) do @params = {:login => ''username'', :pass => ''password'', :code_image => "1234"} end it "should redirect after input login and pass" do session.should_receive(:[]).with(:code).and_return("1234") # this does''nt work!!! #session.stub!(:[]).with(:code).and_return "1234" Admin.should_receive(:authenticate).with(params[:login], params[:pass]).and_return(true) post ''/'', @params response.should be_redirect end end 错误提示是: Spec::Mocks::MockExpectationError in ''AdminController should redirect after input login and pass'' #<ActionController::TestSession:0x9e77198> received :[] with unexpected arguments expected: (:code) got: ("flash") /home/qichunren/gems/actionpack-2.1.0/lib/action_controller/flash.rb:157:in `flash_without_components'' /home/qichunren/gems/actionpack-2.1.0/lib/action_controller/components.rb:105:in `flash'' /home/qichunren/gems/actionpack-2.1.0/lib/action_controller/flash.rb:167:in `assign_shortcuts'' /home/qichunren/gems/actionpack-2.1.0/lib/action_controller/base.rb:523:in `process_without_filters'' /home/qichunren/gems/actionpack-2.1.0/lib/action_controller/filters.rb:569:in `process_without_session_management_support'' /home/qichunren/gems/actionpack-2.1.0/lib/action_controller/session_management.rb:130:in `process_without_test'' /home/qichunren/gems/actionpack-2.1.0/lib/action_controller/test_process.rb:16:in `process'' /home/qichunren/gems/actionpack-2.1.0/lib/action_controller/test_process.rb:394:in `process'' /home/qichunren/gems/actionpack-2.1.0/lib/action_controller/test_process.rb:365:in `post'' ./spec/controllers/admin_controller_test.rb:31: Finished in 0.023053 seconds -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.