ruby-on-rails - 使用 rspec 和 rails 测试嵌套模块

标签 ruby-on-rails ruby testing rspec

<分区>

Possible Duplicate:
Testing modules in rspec

目前我正在使用 rspec 成功测试我的模块,如下所示:

require 'spec_helper'

module Services
  module AppService
    describe AppService do
      describe "authenticate" do
        it "should authenticate the user" do
          pending "authenticate the user"
        end
      end
    end
  end
end

我的模块位于 应用程序/服务/services.rb 应用程序/服务/app_service.rb

然而,是否有更优雅的解决方案来测试我的模块而无需在规范中声明 namespace ?我觉得它与我的规范紧密相关,进行更改会引起很多麻烦。

最佳答案

除了复制 AppServices,您还可以:

module Services
  describe AppService do
  end
ene

或者:

describe Services::AppService do
end

我更喜欢前者,因为它允许我不完全限定规范中的常量名称(因为所有内容都在 Services 模块中,所以它首先看起来是相对于那个的) .

关于ruby-on-rails - 使用 rspec 和 rails 测试嵌套模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12826061/

相关文章:

ruby - 在 Mechanize 中查找没有名称的字段

unit-testing - 关于单元测试的几个问题

unit-testing - TFS 2015 在同一台机器上运行 vNext 构建和测试

ruby-on-rails - 为什么我得到方法未定义?

ruby-on-rails - 在 rails 中将字符串转换为数组

ruby-on-rails - rails : how to extend a gem's ActiveRecord child class?

arrays - 以最佳方式解析二维数组

php - 无法在 codeception 中访问 _bootstrap.php 中的变量

ruby-on-rails - 在不创建 Devise 用户的情况下验证自定义策略

ruby-on-rails - Redmine 插件仅出现在某些项目菜单中