【问题标题】:Integration Test Failing in Modification of Hartl sample_appHartl sample_app修改集成测试失败
【发布时间】:2023-03-19 12:19:02
【问题描述】:

我正在尝试稍微修改 Hartl 的 Ruby On Rails 教程的功能,并从我的新集成测试中得到一个完全神秘的错误。

这是在注册页面上。我只有电子邮件和问题字段,而不是用户名、电子邮件和密码字段。 (变化不大,对吗?)除了重命名的字段外,表单是相同的(我使用字段 :baremail 来表示未加密的电子邮件——我加密了数据库的电子邮件地址)。路由配置相同( match '/signup', :to => 'users#new' )。

这是 spec/requests/users_spec.rb 文件的相关部分:

require 'spec_helper'

describe "Users" do

  describe "signup" do

    describe "failure" do
      it "should not accept a bogus email" do
        lambda do
          visit signup_path
          fill_in "Question",     :with => ""
          fill_in :baremail,        :with => " bogus email"
          click_button
          response.should render_template('users/new')
          response.should have_selector("div#error_explanation")
        end.should_not change(User, :count)
      end

      it "should not accept a question without an email"  do
        lambda do
          visit signup_path
          fill_in :question,     :with => "What, me worry?"
          fill_in :baremail,        :with => ""
          click_button
          response.should render_template('users/new')
          response.should have_selector("div#error_explanation")
        end.should_not change(User, :count)
      end

(请注意,这两个测试使用两种不同的填充协议。)

这是我得到的回应:

  1) Users signup failure should not accept a bogus email
     Failure/Error: fill_in "Question",     :with => ""
     Nokogiri::CSS::SyntaxError:
       unexpected '(' after 'DESCENDANT_SELECTOR'
     # ./spec/requests/users_spec.rb:11:in `block (5 levels) in <top (required)>'
     # ./spec/requests/users_spec.rb:9:in `block (4 levels) in <top (required)>'

  2) Users signup failure should not accept a question without an email
     Failure/Error: fill_in :question,     :with => "What, me worry?"
     Nokogiri::CSS::SyntaxError:
       unexpected '(' after 'DESCENDANT_SELECTOR'
     # ./spec/requests/users_spec.rb:22:in `block (5 levels) in <top (required)>'
     # ./spec/requests/users_spec.rb:20:in `block (4 levels) in <top (required)>

...等等。我尝试用字符串替换 signup_path (以防 signup_path 未定义),但没有效果。我已经交换了 Rspec 文件中的 :question 和 :email 行;无论哪个是第一个,它都会引发错误。

顺便说一下,页面工作正常。只有测试失败。

对于无知的人有什么线索吗?

【问题讨论】:

  • 写出看起来像正常特征的奇怪方法。

标签: ruby-on-rails


【解决方案1】:

编辑:原来我错了,fill_in 确实需要符号。原帖如下。

如果将 :baremail 和 :question 符号更改为字符串会怎样?据我所知,fill_in 不带符号。

【讨论】:

  • 没错。我用字符串和符号都试过了,没有区别。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多