我刚刚开始对我使用 Devise 进行身份验证的 Rails 应用程序进行一些测试。我刚刚生成了 rspec 并且只添加了
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
到我的 spec/support/devise.rb 文件。我还在我的 gemfile 中将 Capybara 添加到了测试组中,运行了 bundle 命令等。但是当我在测试中访问时,我得到了一个 no method 错误。这是我的 user_spec.rb 的示例:
require 'spec_helper'
describe "Club" do
before(:each) do
@club ||= FactoryGirl.create(:club)
FactoryGirl.create(:membership)
User.all.each{|x| x.delete}
end
describe "privacy" do
it "shouldn't be shown any tournament if the user is private" do
attributes = FactoryGirl.attributes_for(:user)
user = User.create!({private: true}.merge(attributes))
assert(user.private)
visit "/user/#{user.id}/tournaments"
page.should have_no_selector(".tournament-list")
end
end
end
当我运行 rspec 时,会出现这样的错误:
Failures:
1) Club privacy shouldn't be shown any tournament if the user is private
Failure/Error: visit "/user/#{user.id}/tournaments"
NoMethodError:
undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_3::Nested_1:0x007ff0ea113108>
# ./spec/user_spec.rb:14:in `block (3 levels) in <top (required)>'