2013-01-17 70 views
2

我不能得到水豚工作。我使用的水豚2.0.0水豚的方法是undefined

我得到這個錯誤

Failure/Error: visit "https://stackoverflow.com/users/sign_in" 
    NoMethodError: 
     undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_21:0x007fdda4c6eba0> 

在該規範

規格/請求/ forgot_password_spec.rb

describe "forgot password" do 
    it "redirects user to users firms subdomain" do 
    visit "https://stackoverflow.com/users/sign_in" 
    end 
end 

我沒有得到任何的錯誤,它找不到水豚,它包含在spec_helper.rb中

spec_helper.rb

require 'rubygems' 
require 'spork' 
require 'database_cleaner' 
Spork.prefork do 
ENV["RAILS_ENV"] ||= 'test' 
require File.expand_path("../../config/environment", __FILE__) 
require 'rspec/rails' 
require 'capybara/rspec' 
require 'rspec/autorun' 
require 'factory_girl' 


Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} 

RSpec.configure do |config| 
    config.include Devise::TestHelpers, :type => :controller 
    config.extend ControllerMacros, :type => :controller 
    config.include RequestMacros, :type => :request 
    config.mock_with :rspec 

    config.use_transactional_fixtures = false 

    config.before(:suite) do 
    DatabaseCleaner.strategy = :truncation 
    end 

    config.before(:each) do 
    DatabaseCleaner.start 
    end 

    config.after(:each) do 
    DatabaseCleaner.clean 
    end 
    config.infer_base_class_for_anonymous_controllers = false 
end 
Spork.each_run do 
    FactoryGirl.reload 
end 
end 

有沒有其他人遇到過這個?

+0

失敗的規格位於哪裏(控制器,請求,功能)以及您使用哪種版本的水豚? – dimuch

+0

謝謝更新的問題。 –

回答

6

如果你有版本>= 2.0,使用像visit水豚方法下規範應該去任何測試/功能目錄,而不是根據規格/請求,在那裏他們會通常存在於水豚1.1.2

看一看有關更多信息,以下鏈接:

如果你不想使用規格/功能目錄,你應該能夠以下列方式將測試標記爲feature並且具有水豚方法工作:

describe "Some action", type: :feature do 
    before do 
    visit "https://stackoverflow.com/users/sign_in" 
    # ... 
    end 
    # ... 
end 
+0

謝謝你解決了!我根據規範/要求提供了它 –

3

在我的情況下,我得到了這個錯誤,因爲我忘了把require "spec_helper" 放在我的新spec文件的頂部。

我已經做到了足夠的時間是我加入,希望回答的已經回答的問題,因爲它有助於其他一些博傻(或最有可能我在將來再次搜索此)。