1

I am following the examples in the Rails Tutorial website and I'm having issues getting the integration tests to work. Specifically the example at listing 8.20 in section 8.4.2 in the tutorial.

At the visit signup_path line of code below I get the following error: "undefined local variable or method `signup_path'"

require 'spec_helper'

describe "Users" do
  describe "signup" do
    describe "failure" do
      it "should not make a new user" do
        visit signup_path
        fill_in "Name", :with => ""
        fill_in "Email", :with => ""
        fill_in "Password", :with => ""
        fill_in "Confirmation", :with => ""
        click_button
        response.should render_template("users/new")
        response.should have_selector("div#error_explanation")
      end
    end
  end
end

Here's the full test file on github

However, if I run all the tests at once, then I do not get the error. The error only happens when I run that individual test.

My project can be viewed on github here

How do I fix this error?

4

2 回答 2

1

经过一番挣扎,我意识到这根本不是一个 ID(至少在 Rails 3.0.3 中),而是一个名为id_error_explanation.

修复了将最后一位替换为:

response.should have_selector('div.id_error_explanation').

于 2011-01-03T15:18:55.910 回答
0

您应该根据清单 8.21 更改测试。测试将如下所示:

规范/请求/users_spec.rb:

require 'spec_helper'

describe "Users" do
  describe "signup" do
    describe "failure" do
      it "should not make a new user" do
        lambda do
          get signup_path
          fill_in "Name", :with => ""
          fill_in "Email", :with => ""
          fill_in "Password", :with => ""
          fill_in "Confirmation", :with => ""
          click_button "Sign up"
          response.should have_selector("div#error_explanation")
        end.should_not change(User, :count)
      end
    end
  end
end
于 2010-10-08T20:08:17.880 回答