`
fireDragonpzy
  • 浏览: 454193 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

rspec with cancan/devise/Webrat

阅读更多
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 关键字.zip

    rspec-given, RSpec规范的Given/When/Then 关键字 用于RSpec和Minitest主机的 Given/When/Then 覆盖给定的rspec,给定的minitest,以及给定的内核,版本 3.5.3 。给定的rspec和minitest是你喜爱的测试框架的扩展,...

    ng-reviews:Angular.jsRails 客户评论应用程序

    为认证/授权设计/CanCan/Rolify Demo Live at (产品数据每天重置)管理员凭据:电子邮件: 密码:changeme 特征 普通用户 查看产品列表 对产品发表评论 查看产品后查看评论列表 认证用户 创建产品 重命名产品 ...

    CloudGuruChallenge_21.02:https

    CloudGuruChallenge_2102 待办事项:简单的用户界面(Rails? )待办事项:捕获用户的姓名,地址,照片和语音样本待办事项:将用户的名称和地址写入Cosmo的数据库待办... ://rspec.info/)通过Azure DevOps部署Ruby代码

    guard-spork:警卫

    后卫:: 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进行了测试。安装请确保已安装然后再...

    tdd-rails-pluralsight:使用RSpec,Capybara和Cucumber以及Pluralsight课程学习Rails的TDD

    用生成的目录测试新动作并显示动作测试创建动作测试索引和编辑操作测试更新和销毁操作安装和设置Devise gem 测试认证测试授权模型测试模型的责任测试验证测试协会测试实例方法测试数据库查询隔离测试嘲笑,存根和...

    chifoumi

    Rspec_rails> = 3.9.0 数据库创建: rails db:create 数据库初始化: rails db:migrate 游戏引擎测试套件: 捆绑执行器rspec rspec规格/lib/GameEngine_spec.rb rspec规格/控制器/chifoumi_controller_spec....

    rspec-ontap:RSpec在Tap-YJ上

    RSpec轻按 描述 RSpec On Tap是RSpec的TAP-... 该库文件rspec/tap_y本身只需要rspec/ontap (同样是真正rspec/tap_j )。 有了TAP-Y输出,然后可以使用tapout工具生成多种其他输出格式。 首先,确保已安装Tapout: $

    MeetMyClassmates:CS169 秋季 2014

    start server with 'rails s' 4 . open localhost: 3000 PS 现在在 heroku 上。 本地的所有功能也都在 heroku 中。 在 heroku 上试试: / PS为获得最佳体验,请尝试全屏模式。 如何运行测试: 0 . cd into ...

    RSpec.Essentials

    - **Integration with Other Tools:** It covers integrating RSpec with other popular Ruby frameworks and tools, enhancing the overall testing experience. - **Best Practices:** Emphasis on following best...

    rspec 入门者学习

    ### RSpec 入门者学习知识点详解 #### 一、RSpec 概述 RSpec 是一个流行的 Ruby 测试框架,主要用于行为驱动开发 (Behavior-Driven Development, BDD)。RSpec 的设计目的是让测试更加自然和易读,使得开发人员能够...

    rails3-devise-rspec-cucumber:具有Devise和RSpec和Cucumber的示例Rails 3.2应用程序

    Rails 4.1 有关带RSpec的Devise的Rails 4.1示例应用程序,请参见:可以使用Devise和RSpec的教程:相似的例子和教程这是来自的一系列Rails示例应用程序和教程。 请参阅其他。 相关的示例应用程序可能会有用: 随书 ...

    docker-browser-test-ja:使用Headless浏览器的Rspec测试环境

    浏览器测试Rspec / Capybara / Turnip具有与日本环境兼容的Headless Chromium浏览器测试环境。 包括IPA哥特式。有关字体许可证,请参见字体/IPA_Font_License_Agreement_v1.0.txt。快速开始由于具有最小设置的/work/...

    Pragmatic.The RSpec Book.2010.pdf

    #### 一、RSpec框架简介与特性 **RSpec** 是 Ruby 社区中最受欢迎的行为驱动开发(Behavior Driven Development, BDD)框架之一。它为开发者提供了一种灵活的方式来定义应用程序的行为,并通过简洁易读的语法来编写...

    rails_with_rspec_template:一个模板 rails 应用程序,包含使用 rspec 进行 rails 测试驱动开发所需的所有 gem

    $ rails new [application_name] -m https://raw.githubusercontent.com/wdi-sf-september-2014/rails_with_rspec_template/master/template.rb -TBd [database] 请参阅 template.rb 了解此模板的作用;)

    the rspec book.pdf

    《RSpec Book》是一本专注于Rspec的权威指南,它详细阐述了如何使用Rspec这个强大的测试框架进行行为驱动开发(BDD)。Rspec是Ruby编程语言中的一个测试库,它使得编写可读性强、表达力丰富的测试代码成为可能。这...

    rspec-sleeping_king_studios:RSpec修补程序和自定义匹配器的集合

    RSpec :: SleepingKingStudios 匹配器和扩展的集合,以使用RSpec简化TDD / BDD。 使用新功能扩展了内置匹配器,例如对Ruby 2.0+关键字参数的支持,并添加了用于测试布尔值,对象读取器/写入器属性,对象构造函数...

    rspec测试.pdf

    《RSpec测试:行为驱动开发与RSpec、Cucumber及其他工具》 RSpec是一种用于Ruby语言的单元测试框架,它提倡一种称为“行为驱动开发”(Behavior Driven Development,BDD)的测试方式。RSpec允许开发者以自然语言的...

    ammeter:一个让您编写Rails 3生成器规范的宝石

    电表 一颗让您轻松编写Rails 3 Generators规格的宝石。 RSpec的使用电流表,我们...require 'generators/rspec/model/model_generator' describe Rspec :: Generators :: ModelGenerator , :type => :generator do

    Atom-language-rspec,atom的rspec语言包。为pauldruziak/语言做出贡献.zip

    Atom-language-rspec是专门为Atom文本编辑器设计的一款插件,旨在增强其对RSpec代码的语法高亮和编辑支持。RSpec是一种流行的Ruby行为驱动开发(BDD)框架,用于编写可读性强、表达力强的测试代码。这款插件由...

Global site tag (gtag.js) - Google Analytics