rspec with cancan/devise/Webrat

[url]http://stackoverflow.com/questions/4200343/rspec-cancan-and-devise[/url]
 
1 controller
def mock_user(stubs={})
@mock_user ||= mock_model(User, stubs).as_null_object
end

def mock_link(stubs={})
(@mock_ak_config ||= mock_model(User).as_null_object).tap do |user|
user.stub(stubs) unless stubs.empty?
end
end

before(:each) do
# mock up an authentication in the underlying warden library
request.env['warden'] = mock(Warden, :authenticate => mock_user,
:authenticate! => mock_user)
@ability = Object.new
@ability.extend(CanCan::Ability)
controller.stub(:current_ability) { @ability }
end
2 spec_helper.rb
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true

# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
config.include Devise::TestHelpers, :type => [:controller, :views]
config.include ControllerHelpers, :type => :controller


end

Webrat.configure do |config|
config.mode = :rails
end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值