rspec中模拟CAS 登录( mock login for CAS )

访问量: 5282

非常简单,用这个:  ( 1 line of code: ) 

CASClient::Frameworks::Rails::Filter.fake("some_user")

例如:  (e.g. ) 

# spec_helper.rb  : define a method called 'login')

 def login
   CASClient::Frameworks::Rails::Filter.fake("some_user")
 end

然后就可以调用它了. ( then you can call it in your rspec files: ) 

# in some rspec file
require 'spec_helper'

describe MessagesController do
  render_views
  before do
    login
    @message = FactoryGirl.create(:message, :vid => 1, :title => "test")
  end 
  it "should get show"  do  
    get :show, :id => @message.id
    response.should be_success
  end 
end

订阅/RSS Feed

Subscribe

分类/category