1

Rails チュートリアル Web サイトの例に従っていますが、統合テストを機能させるのに問題があります。具体的には、チュートリアルのセクション 8.4.2にリストされている 8.20 の例です。

以下のコードのsignup_path行にアクセスすると、次のエラーが表示されます。「未定義のローカル変数またはメソッド `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

github の完全なテスト ファイルは次のとおりです。

ただし、すべてのテストを一度に実行すると、エラーは発生しません。エラーは、その個々のテストを実行したときにのみ発生します。

私のプロジェクトはこちらのgithubで見ることができます

このエラーを修正するにはどうすればよいですか?

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 に答える