水豚访问方法不起作用

2024-02-08

我不确定发生了什么,但我无法进行简单的测试,因为水豚的访问方法不适合我。我一直在努力完成这个 Railscast 正在测试 http://railscasts.com/episodes/275-how-i-test.

一旦我到达 Capybara 需要访问登录页面的点,测试就会失败,因为它只能访问我的 root_url。这就是失败的样子。请注意,它失败了,因为它甚至无法访问登录页面。它卡在主页上:

Running: spec/requests/password_resets_spec.rb
Running tests with args ["--color", "--failure-exit-code", "2", "--format", "progress", "--format", "Guard::RSpec::Formatter::NotificationRSpec", "--out", "/dev/null", "--require", "/Users/lee/.rvm/gems/ruby-1.9.3-p0@supply_side/gems/guard-rspec-0.6.0/lib/guard/rspec/formatters/notification_rspec.rb", "spec/requests/password_resets_spec.rb"]...
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Home | My App</title>
<link href="/assets/application.css" media="all" rel="stylesheet" type="text/css">
<script src="/assets/application.js" type="text/javascript"></script>
</head>
<body>
  <ul class="user_nav">
<li><a href="/signup">Sign up</a></li>
      <li><a href="/login">log in</a></li>
  </ul>
<h1>Supply Side</h1>
<p>
  This is the home page for My App.
</p>

<h2>Visit the <a href="/secret">Secret Page</a>.</h2>


</body>
</html>
F

Failures:

  1) PasswordResets emails user when requesting password reset
     Failure/Error: click_link "Forgot Your Password?"
     Capybara::ElementNotFound:
       no link with title, id or text 'Forgot Your Password?' found
     # (eval):2:in `click_link'
     # ./spec/requests/password_resets_spec.rb:8:in `block (2 levels) in <top (required)>'

Finished in 0.40915 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/requests/password_resets_spec.rb:4 # PasswordResets emails user when requesting password reset
Done.

我添加了打印 page.html 以显示它没有进入登录页面。测试如下所示:

require 'spec_helper'

describe "PasswordResets" do
  it "emails user when requesting password reset" do
    user = Factory(:user)
    visit login_path
    print page.html
    click_link "Forgot Your Password?"
    fill_in "Email", :with => user.email
    click_button "Reset Password"
  end
end

这是我的规范/spec_helper.rb:

require 'rubygems'
require 'spork'

Spork.prefork do
  # Loading more in this block will cause your tests to run faster. However, 
  # if you change any configuration or code from libraries loaded here, you'll
  # need to restart spork for it take effect.
  # This file is copied to spec/ when you run 'rails generate rspec:install'
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'capybara/rspec'

  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

  RSpec.configure do |config|
    config.mock_with :rspec

    # If you're not using ActiveRecord, or you'd prefer not to run each of your
    # examples within a transaction, remove the following line or assign false
    # instead of true.
    config.use_transactional_fixtures = true

    # If true, the base class of anonymous controllers will be inferred
    # automatically. This will be the default behavior in future versions of
    # rspec-rails.
    config.infer_base_class_for_anonymous_controllers = false

    config.treat_symbols_as_metadata_keys_with_true_values = true
    config.filter_run :focus => true
    config.run_all_when_everything_filtered = true
  end
end

Spork.each_run do
  # This code will be run each time you run your specs.
  FactoryGirl.reload
end

这是我的宝石文件:

gem 'rails', '3.2.0'
gem 'heroku'
gem 'jquery-rails'
gem 'sorcery'

group :production do
  gem 'pg'
end

group :development, :test do 
  gem 'sqlite3'
  gem 'rspec-rails'
  gem 'factory_girl_rails'
  gem 'capybara'
  gem 'guard-rspec'
  gem 'spork'
  gem 'guard-spork'
  gem 'rb-fsevent'
  gem 'wirble'
end

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end

我的路线:

  get "logout" => "sessions#destroy", :as => "logout"
  get "login" => "sessions#new", :as => "login"
  get "signup" => "users#new", :as => "signup"
  resources :users do
    member do
      get :activate
    end
  end
  resources :sessions
  match "/forgot_password" => "sessions#forgot_password"
  resources :password_resets
  match "/secret" => "pages#secret"
  root :to => "pages#home"

最后是我的 config/environments/test.rb

 # Settings specified here will take precedence over those in config/application.rb

  # The test environment is used exclusively to run your application's
  # test suite. You never need to work with it otherwise. Remember that
  # your test database is "scratch space" for the test suite and is wiped
  # and recreated between test runs. Don't rely on the data there!
  config.cache_classes = true

  # Configure static asset server for tests with Cache-Control for performance
  config.serve_static_assets = true
  config.static_cache_control = "public, max-age=3600"

  # Log error messages when you accidentally call methods on nil
  config.whiny_nils = true

  # Show full error reports and disable caching
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Raise exceptions instead of rendering exception templates
  config.action_dispatch.show_exceptions = false

  # Disable request forgery protection in test environment
  config.action_controller.allow_forgery_protection    = false

  # Tell Action Mailer not to deliver emails to the real world.
  # The :test delivery method accumulates sent emails in the
  # ActionMailer::Base.deliveries array.
  config.action_mailer.delivery_method = :test

  # Raise exception on mass assignment protection for Active Record models
  config.active_record.mass_assignment_sanitizer = :strict

  # Print deprecation notices to the stderr
  config.active_support.deprecation = :stderr

  config.action_mailer.default_url_options = { :host => 'localhost:3000' }

我在 ruby​​ 1.9.3 上运行 Rails 3.2。我不知道为什么这不起作用。提前致谢!


在您的测试日志中,当测试执行访问登录路径时,您是否最初点击了该操作,但随后被重定向回主页?

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

水豚访问方法不起作用 的相关文章

  • 如何使用 RSpec 测试 javascript 重定向?

    我正在使用 xhr post 与控制器交互 并且我期待重定向 在 js erb 中 我有 window location href address 手动测试 浏览器会正确重定向 我如何使用 RSpec 测试它 response should
  • 从标记访问 json 属性 - gmaps4rails

    我正在升级到 gmaps4rails v2 我似乎无法从 javascript 访问标记 json 属性 这在我使用的先前版本 1 5 6 中有效 具体来说 内置控制器 users User all hash Gmaps4rails bui
  • 在复杂的文件夹结构中进行测试

    我正在 golang 中构建一个设计模式存储库 为了运行所有测试 我使用这个 bash 脚本 有用 bin bash go test creational abstract factory go go test creational bui
  • Rails 应用程序中区域设置文件的组织

    我目前有以下4个文件配置 语言环境我的根应用程序 en yml de yml simple form en yml simple form de yml In my 应用程序 rb它驻留在一个规格 虚拟用于测试应用程序 gem 的文件夹我有
  • 为 REST API 编写单元测试的最佳方法是什么?

    在为 API 包装器编写单元测试时 我应该对 REST API 端点进行真正的调用 还是应该使用 mocl 响应来模拟成功和错误的调用 单元测试意味着只测试你的unit API 包装器 仅此而已 因此 不幸的是 您应该模拟整个 API 另一
  • 如果没有按钮,Espresso 不会记录任何意图

    我正在尝试编写一个测试来验证使用浓缩咖啡启动的意图 问题是有意的 不记录任何意图 我有这个测试 Test public void shoulddosomething startActivity intended hasComponent h
  • Devise + CanCan 只是阻止其他用户编辑对象

    您如何防止其他用户编辑对象 例如不属于自己的配置文件对象 大多数在线示例都是具有多个用户角色的复杂示例 我无法使其正常工作 但必须很简单 def initialize user can update Profile do profile p
  • 导轨中的多个 DB 连接

    我正在尝试在 ROR 应用程序中连接多个数据库 我的 database yml 如下所示 在你的database yml文件中 发展 adapter mysql username root password database example
  • 如何创建下载链接

    创建下载链接的最佳方法是什么 还有比下面更好的方法吗 我正在考虑使用link to Download controller gt action gt id gt 视图中 Adding match documents download id
  • Rails 3 - 创建复选框(与 _destroy 相反)

    我有一个与 OutputFields 具有 has many 关系的查询模型 在查询控制器的新函数中 我在查询实例中构建了多个输出字段 在我的表单中 我希望每个复选框都确定是否保存对象 检查意味着将此 OutputField 实例保存到数据
  • Rails3 SQL 日志记录输出在单独的文件中

    我希望将所有 ActiveRecord SQL 日志记录重定向到不同的文件中 将其放在控制台或 log development log 中有点混乱 怎么做 我希望将其放在 log development sql log 文件中 Thanks
  • 使用 simple_form Rails 时测试 HTML 5 表单验证

    我正在为我的待办事项列表应用程序使用 devise 和 simple form 现在 我的 users edit html erb 有以下代码 h2 Edit profile h2 我的 user rb 看起来像这样 class User
  • 如何在 Azure DevOps 发布管道中保存测试结果

    在发布管道期间 我将启动 Selenium 测试 如果这些测试失败 则会进行屏幕截图 我正在寻找一种上传它们的方法 以便我可以查看它们并检查出了什么问题 我设法将它们压缩 但不幸的是 所有上传方法都不适用于发布管道 有没有办法在发布管道期间
  • 正则表达式检查 ruby​​ 中的字母数字字符串

    我正在尝试验证 ruby 中的字符串 任何包含空格 下划线或任何特殊字符的字符串都将无法通过验证 有效字符串应仅包含字符 a zA Z0 9 我的代码看起来像 def validate string regex a zA Z0 9 if s
  • 使用 REST 协议和 JSON 数据格式测试 Web 服务的最佳工具是什么? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我是使用 JSON 数据格式测试 REST Web 服务的新手 我尝试了SOUPUI 但不幸的是不支持
  • 解析包含 json 字符串的 json

    我有一个 json 里面有另一个 json 但它在双引号内 因此它给了我一个解析错误 除了使用之外还有什么方法可以解析这个jsongsub替换双引号 obj Name FirstName Douglas LastName Crockford
  • 如何在 akka actor 中测试公共方法?

    我有一个 akka 演员 class MyActor extends Actor def recieve def getCount id String Int do a lot of stuff proccess id do more st
  • 在 Rails 3 中将“当前”类添加到导航的最佳方法

    我的导航菜单中有一些静态页面 我想向当前显示的项目添加一个像 current 这样的类 我这样做的方法是添加大量的辅助方法 每个方法对应一个项目 来检查控制器和操作 def current root class class current
  • 设计和自定义 Rails 用户 URL

    我目前正在使用 Rails 3 2 5 和最新的 devise gem 目前用户可以访问他们的个人资料页面 example com users john doe 我想删除网址的用户部分 因此网址将是example com john doe
  • 如何在 Rails 3 中查看用户的实时活动?

    我想做的是让我的管理员用户能够实时 通过一些 AJAX jQuery 功能 看到我的用户正在做什么 我该如何去做呢 我认为它与会话活动有关 并且我已经开始将会话保存到数据库 而不是 cookie 但一般来说 我如何获取该信息并实时解析它 我

随机推荐