集成测试失败修改Hartl sample_app

时间:2011-07-16 19:40:11

标签: ruby-on-rails

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

这是在注册页面上。我只收到电子邮件和问题字段,而不是用户名,电子邮件和密码字段。 (这不是一个很大的改变,对吧?)除了重命名的字段之外,表单是相同的(我使用的字段是:未加密的电子邮件的裸邮件 - 我加密了数据库的电子邮件地址)。路线配置相同(匹配'/ 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

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

以下是我的回应:

  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文件中交换了:问题和:电子邮件行;它会抛出错误,无论哪个是第一个。

顺便说一句,页面工作正常。这只是失败的测试。

无知的任何线索?

1 个答案:

答案 0 :(得分:0)

编辑:结果我错了,fill_in确实带符号。原帖在下面。

如果您将:baremail和:问题符号更改为字符串会发生什么?据我所知,fill_in不带符号。