2017-01-05 113 views
-1

我对Ruby和RSpec非常陌生。我想创建基本规格文件中查找该模块:测试Ruby模块

module DownloadAttemptsHelper 

    def download_attempt_filter_select_options 
    search_types = [ 
     [I18n.t("helpers.download_attempts.search_types_default"),   'default'   ], 
     [I18n.t("helpers.download_attempts.search_types_account_id"),  'account_id'  ], 
     [I18n.t("helpers.download_attempts.search_types_remote_ip"),  'remote_ip'  ], 
    ] 
    options_for_select(search_types) 
    end 
end 

小试

describe DownloadAttemptsHelper do 
    it "does something" do 
    expect(1).to be_odd 
    end 
end 

我得到:

`<top (required)>': uninitialized constant DownloadAttemptsHelper (NameError) 

我需要导入的目录路径和模块的名称? 你可以给我一些非常基本的例子,我如何测试这个模块?

+0

有很多教程和指南,在互联网,如何编写规格,你尝试过什么? –

+0

是的,但我对这种语言太陌生了。你能给我一些基本的例子吗? –

+0

这不是一种语言,它是一个测试框架。这里是谷歌的第一个链接。 https://www.codeschool.com/courses/testing-with-rspec –

回答

-1

你必须包括在RSpec的测试文件的模块,使它的可用方法的测试案例:如果您使用Rails的

describe "DownloadAttemptsHelper" do 
    include DownloadAttemptsHelper 

    it "does something" do 
    expect(1).to be_odd 
    end 
end 
+0

我再次得到同样的错误:''':未初始化的常量DownloadAttemptsHelper(NameError)'。可能我需要指定目录和文件位置? –

0

,你需要确保你的模块被加载时服务器启动。打开一个rails c并检查是否可以在那里访问你的模块。如果没有,你可以像这里所描述Auto-loading lib files in Rails 4

也就是说,让Rails的自动加载类的lib目录下,如果这就是你的助手位于做点什么。