gpt4 book ai didi

ruby-on-rails - 为什么我的 ruby 测试找不到访问?

转载 作者:太空宇宙 更新时间:2023-11-03 16:05:56 24 4
gpt4 key购买 nike

我正在使用 minitest、rails 和 capybara,下面的测试给了我这个错误...

    undefined method `visit' for #<Page:0x007f8bf3697630>
STDERR:
Exception `NoMethodError' at /Users/trace/.rvm/gems/ruby-1.9.3-p194@application.1/gems/activemodel-3.1.8/lib/active_model/attribute_methods.rb:385:in `method_missing'
/Users/trace/.rvm/gems/ruby-1.9.3-p194@application.1/gems/activerecord-3.1.8/lib/active_record/attribute_methods.rb:60:in `method_missing'
/Users/trace/.rvm/gems/ruby-1.9.3-p194@application.1/gems/capybara-2.0.1/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
test/support/utilities.rb:2:in `sign_in_user'
test/integration/pages_intergration_test.rb:12:in `block (4 levels) in <top (required)>'
/Users/trace/.rvm/gems/ruby-1.9.3-p194@application.1/gems/mocha-0.9.12/lib/mocha/integration/mini_test/version_201_to_202.rb:27:in `run'

这是我的文件 test/integration/pages_intergration_test.rb

require "minitest_helper"

describe "Pages integration" do
let(:page) { FactoryGirl.create(:page }

describe "Page Management tool" do

describe "Visiting a page" do
let(:user) { FactoryGirl.create(:user)}
it "Should see the welcome message" do
sign_in_user(admin_user)
should have_content("Welcome")
end
end
end
end

和我的文件test/support/utilities.rb

def sign_in_user(user)
visit root_path
fill_in "EMAIL ADDRESS", with: user.email
fill_in "PASSWORD", with: user.password
click_button "SIGN IN"
end

这是我的 minitest.rb ...以防万一我在这里做错了什么

ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)

require "minitest/autorun"
require "minitest/rails"
require "minitest/rails/capybara"
require "active_support/testing/setup_and_teardown"
require 'turn'

require 'factory_girl'

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

Dir.glob(File.dirname(__FILE__) + "/factories/*").each do |factory|
require factory
end

require 'database_cleaner'
DatabaseCleaner.strategy = :truncation

class MiniTest::Rails::ActiveSupport::TestCase
before :each do
DatabaseCleaner.start
end

after :each do
DatabaseCleaner.clean
end
end

class IntegrationTest < MiniTest::Spec
include Rails.application.routes.url_helpers
include Capybara::DSL

register_spec_type(/integration$/, self)

before :each do
DatabaseCleaner.start
end

after :each do
DatabaseCleaner.clean
Capybara.reset_sessions!
Capybara.use_default_driver
end
end

class HelperTest < MiniTest::Spec
include ActiveSupport::Testing::SetupAndTeardown
include ActionView::TestCase::Behavior
register_spec_type(/Helper$/, self)

before :each do
DatabaseCleaner.start
end

after :each do
DatabaseCleaner.clean
end
end

关于问题是什么的任何想法......

最佳答案

最新版本的 Capybara(2.0 分支)有需要考虑的更改。这是来自 changelog 的相关部分(相关段落加粗):

Notably, we changed the :type that Capybara assumes your specs run under in RSpec to :feature (previously it was :request). The latest release of spec/features. Alternatively you can use the Capybara Feature DSL (feature instead of describe), which should work without any additional tweaking. If you see errors like undefined method visit, then you're probably encountering this issue. If you're including modules into :request specs, you will probably need to change that to :feature.

因此,将 describe 更改为 feature 可能会解决问题。

关于ruby-on-rails - 为什么我的 ruby 测试找不到访问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13974249/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com