Rails 2.0: HTTP Basic Authentication Test

老外Andy比较守旧,写测试不让用Rspec,所以我又回归到了Rails自带的unit test 。又感觉他有点变态,develop的时候加什么验证,搞的我很郁闷。如果我用Rspec,就很简单了,可以这么写:

在Application.rb里:
class ApplicationController < ActionController::Base

        before_filter :authenticate

        def authenticate
          authenticate_or_request_with_http_basic do |username, password|
            username == 'jared' && password == 'secret'
          end
        end
    end
Test里这么写:
describe WidgetsController do
  describe "with successful admin login" do
    before(:each) do
         controller.stub!(:authenticate).and_return(true)
    end
    ...
    end
end



但是我现在用Rails自带的unit test的话,只能自己去定义个方法:
昵  称:
登录  快速注册
验证码:

点击图片可刷新验证码请点击后输入验证码博客过2级,无需填写验证码

内  容:

同时赞一个

你可能感兴趣的:(http,basic,Authentication,休闲)