【问题标题】:method not recognized in rspec integration testing despite module included in spec_helper尽管 spec_helper 中包含模块,但在 rspec 集成测试中无法识别方法
【发布时间】:2013-02-22 05:09:45
【问题描述】:

我收到一个错误,我的方法没有定义。错误是“未定义的局部变量或方法 'mock_auth_hash',尽管在 spec_helper 中包含定义 mock_auth_hash 的模块。

我正在尝试使用omniauth 进行一些rspec 集成测试,我正在关注此链接https://gist.github.com/kinopyo/1338738

请帮我找出问题所在,因为我花了太多时间试图找出这个问题...也许我需要一双新的眼睛...

这是我的文件

spec->support->omniauth_macros.rb

module OmniauthMacros
    def mock_auth_hash
        OmniAuth.config.mock_auth[:facebook] = {'provider' =>"facebook",
                                        'uid' =>"12345",
                                        'info'=>{'name'=>"John Doe"},
                                        'credentials'=>{'token'=>"AAABBBCCC"}}
    end
end

spec->spec_helper.rb

RSpec.configure do |config|
.
.
.
config.include OmniauthMacros #I've also tried putting config.include(OmniauthMacros)
.
.
end

OmniAuth.config.test_mode = true

spec->requests->game_pages_spec.rb

describe "signing in" do
        before {visit root_url}
        mock_auth_hash
        before {click_button "Login with Facebook"}
        it {should have_selector('h1',text: 'Welcome')}
end

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    您对mock_auth_hash 的调用必须在beforeit 内进行。

    【讨论】:

    • 谢谢。我不敢相信事情就这么简单。
    猜你喜欢
    • 2019-06-03
    • 2013-04-27
    • 2012-06-13
    • 2023-03-12
    • 2016-10-17
    • 1970-01-01
    • 1970-01-01
    • 2013-11-02
    • 1970-01-01
    相关资源
    最近更新 更多