http://stackoverflow.com/questions/4200343/rspec-cancan-and-devise
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
分享到:
相关推荐
rspec-given, RSpec规范的Given/When/Then 关键字 用于RSpec和Minitest主机的 Given/When/Then 覆盖给定的rspec,给定的minitest,以及给定的内核,版本 3.5.3 。给定的rspec和minitest是你喜爱的测试框架的扩展,...
为认证/授权设计/CanCan/Rolify Demo Live at (产品数据每天重置)管理员凭据:电子邮件: 密码:changeme 特征 普通用户 查看产品列表 对产品发表评论 查看产品后查看评论列表 认证用户 创建产品 重命名产品 ...
CloudGuruChallenge_2102 待办事项:简单的用户界面(Rails? )待办事项:捕获用户的姓名,地址,照片和语音样本待办事项:将用户的名称和地址写入Cosmo的数据库待办... ://rspec.info/)通过Azure DevOps部署Ruby代码
后卫:: Spork Guard :: Spork允许自动智能地启动/重新加载RSpec / Cucumber / Test :: Unit 服务器。 与Spork 0.8.4和0.9.0.rcX兼容。 已针对Ruby 1.9.3、2.0.0、2.1.2和JRuby进行了测试。安装请确保已安装然后再...
用生成的目录测试新动作并显示动作测试创建动作测试索引和编辑操作测试更新和销毁操作安装和设置Devise gem 测试认证测试授权模型测试模型的责任测试验证测试协会测试实例方法测试数据库查询隔离测试嘲笑,存根和...
Rspec_rails> = 3.9.0 数据库创建: rails db:create 数据库初始化: rails db:migrate 游戏引擎测试套件: 捆绑执行器rspec rspec规格/lib/GameEngine_spec.rb rspec规格/控制器/chifoumi_controller_spec....
RSpec轻按 描述 RSpec On Tap是RSpec的TAP-... 该库文件rspec/tap_y本身只需要rspec/ontap (同样是真正rspec/tap_j )。 有了TAP-Y输出,然后可以使用tapout工具生成多种其他输出格式。 首先,确保已安装Tapout: $
start server with 'rails s' 4 . open localhost: 3000 PS 现在在 heroku 上。 本地的所有功能也都在 heroku 中。 在 heroku 上试试: / PS为获得最佳体验,请尝试全屏模式。 如何运行测试: 0 . cd into ...
Rails 4.1 有关带RSpec的Devise的Rails 4.1示例应用程序,请参见:可以使用Devise和RSpec的教程:相似的例子和教程这是来自的一系列Rails示例应用程序和教程。 请参阅其他。 相关的示例应用程序可能会有用: 随书 ...
浏览器测试Rspec / Capybara / Turnip具有与日本环境兼容的Headless Chromium浏览器测试环境。 包括IPA哥特式。有关字体许可证,请参见字体/IPA_Font_License_Agreement_v1.0.txt。快速开始由于具有最小设置的/work/...
$ rails new [application_name] -m https://raw.githubusercontent.com/wdi-sf-september-2014/rails_with_rspec_template/master/template.rb -TBd [database] 请参阅 template.rb 了解此模板的作用;)
RSpec :: SleepingKingStudios 匹配器和扩展的集合,以使用RSpec简化TDD / BDD。 使用新功能扩展了内置匹配器,例如对Ruby 2.0+关键字参数的支持,并添加了用于测试布尔值,对象读取器/写入器属性,对象构造函数...
RSpec is a popular tool for TDD with ruby. In this talk, we start with subject and let. Then we dive into should_receive vs. asserting side effects. Last part of this talk covers some traps and ...
电表 一颗让您轻松编写Rails 3 Generators规格的宝石。 RSpec的使用电流表,我们...require 'generators/rspec/model/model_generator' describe Rspec :: Generators :: ModelGenerator , :type => :generator do
基本应用基本的Rails 4应用程序。 具有Facebook登录功能的用户和管理系统。 它对Heroku不可安装。 该视图是使用实现的。 这是。 请注意,未设置用于Facebook登录的环境变量,因此以这种方式登录将不起作用。...
斯科富有关Ruby库( lib/ )中的文件如何相互关联以及与Rspec( spec/ )使用的文件之间的关系的简单指南。 该项目是使用bundle gem sko_foo创建的,然后进行了修改以演示如何在适当的目录中构造文件。 我会忘记文件...
rspec_api_documentation, 从RSpec自动生成API文档 RSpec Doc为你的Rails API生成漂亮的。查看一个示例文件。更改请查看维基以了解最新的更改。安装将rspec_api_documentation添加到你的文件gem 'rspec_a
原版The RSpec Book并附有源码
rspec出入门者学习理解,介绍的非常的详细、清楚; 欢迎下载学习~
Dox从Rails应用程序中的Rspec控制器/请求规范生成API文档。 它以格式格式化测试输出。 使用ReDoc渲染器将文档生成并显示为HTML。 这是一个。 安装 将此行添加到应用程序的Gemfile中: group :test do gem 'dox' ...