2013-10-26 193 views
2

我想包括一些助手到我的測試,但我不能讓它工作。 我得到了以下錯誤:包括幫手不工作

/home/edu/.rvm/rubies/ruby-1.9.3-p392/bin/ruby -S rspec ./spec/features/customers_spec.rb ./spec/features/login_spec.rb ./spec/features/products_spec.rb ./spec/features/suppliers_spec.rb 
     /home/edu/Desktop/rails_proyects/gg/spec/support/features.rb:2:in `block in <top (required)>': uninitialized constant MyHelp (NameError) 
      from /home/edu/.rvm/gems/[email protected]/gems/rspec-core-2.14.6/lib/rspec/core.rb:120:in `configure' 
      from /home/edu/Desktop/rails_proyects/gg/spec/support/features.rb:1:in `<top (required)>' 

我有這樣的:

# spec/support/features/session_helper.rb 
module MyHelp 
    module SessionHelpers 
    ... 
    def sign_in 
     ... 
    end 
    end 
end 

# spec/support/features.rb 
RSpec.configure do |config| 
    config.include MyHelp::SessionHelpers, type: :feature 
end 

我在這裏使用它:

# spec/features/login_spec.rb 
require 'spec_helper' 

feature "Login" do 
    scenario "with valid credentials" do 
    user = create(:user) 
    sign_in user.email, user.password 
    page.should have_content(I18n.t('layouts.header.exit', locale: 'es')) 
    end 
end 

我使用:

rspec (2.14.1) 
rspec-core (2.14.6, 2.14.5) 
rspec-expectations (2.14.3, 2.14.2) 
rspec-mocks (2.14.4, 2.14.3) 
rspec-rails (2.14.0) 

ruby 1.9.3p392 
rails 3.2.13 

有人可以幫助我嗎? 謝謝。

回答

2

它看起來像你只需要導入新的助手,你嘗試在spec/support/features.rb

require Rails.root.join('spec/support/features/session_helper') 

而且使用它之前,它是有你的類/模塊的匹配文件名最佳實踐,因此無論是文件應該被複數化,或者幫助者被單數化。

+0

它的工作原理,謝謝你! – edudepetris