RoR Rake测试失败:期待<“users / show”>但渲染

时间:2015-01-21 22:32:40

标签: ruby-on-rails ruby

我在Rails 4中运行集成测试,我收到以下故障:

1) Failure:
UsersLoginTest#test_valid_signup_information [/Users/************/workspace/myapp/test/integration/users_login_test.rb:38]:
expecting <"users/show"> but rendering with <["shared/_error_messages", "users/new", "layouts/_header", "layouts/_footer", "layouts/application", "user_mailer/account_activation", "static_pages/home"]>

22 runs, 120 assertions, 1 failures, 0 errors, 0 skips

它指向的测试在这里:

 test "valid signup information" do
    get signup_path
    assert_difference 'User.count', 1 do
      post_via_redirect users_path, user: { name:  "Example User",
                                            email: "user@example.com",
                                            password:              "password",
                                            password_confirmation: "password" }
    end
    assert_template 'users/show'
    assert is_logged_in?
  end

在用户控制器中,创建功能在此处:

def create
    @user = User.new(user_params)
    if @user.save
      UserMailer.account_activation(@user).deliver!
      flash[:info] = "Please check your email to activate your account."
      redirect_to root_url
    else
      render 'new'
    end
  end

你看到这里出了什么问题,为什么失败了?谢谢。

编辑:

UsersLoginTest的日志文件:test_valid_signup_information:

UsersLoginTest: test_valid_signup_information
---------------------------------------------
  [1m[36mUser Load (0.1ms)[0m  [1mSELECT  `users`.* FROM `users`  WHERE `users`.`id` = 762146111 LIMIT 1[0m
Started GET "/signup" for 127.0.0.1 at 2015-01-21 14:03:04 -0800
Processing by UsersController#new as HTML
  Rendered shared/_error_messages.html.slim (0.1ms)
  Rendered layouts/_header.html.erb (0.2ms)
  Rendered layouts/_footer.html.erb (0.1ms)
Completed 200 OK in 4ms (Views: 3.3ms | ActiveRecord: 0.0ms)
  [1m[35m (0.2ms)[0m  SELECT COUNT(*) FROM `users`
Started POST "/users" for 127.0.0.1 at 2015-01-21 14:03:04 -0800
Processing by UsersController#create as HTML
  Parameters: {"user"=>{"name"=>"Example User", "email"=>"user@example.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}}
  [1m[36m (0.1ms)[0m  [1mSAVEPOINT active_record_1[0m
  [1m[35mUser Exists (0.2ms)[0m  SELECT  1 AS one FROM `users`  WHERE `users`.`email` = 'user@example.com' LIMIT 1
  [1m[36mSQL (0.2ms)[0m  [1mINSERT INTO `users` (`activation_digest`, `created_at`, `email`, `name`, `password_digest`, `updated_at`) VALUES ('$2a$04$DEMdkJmbjK3DUTmv7O2u7eX6Cy7nfYErvEoO4fN62vMGZ5XDwyrnC', '2015-01-21 22:03:04', 'user@example.com', 'Example User', '$2a$04$1L56dTrE0Wa./qUOhzA50OKako81UG3wO25Z00Dj2UkejeW1e6hQi', '2015-01-21 22:03:04')[0m
  [1m[35m (0.1ms)[0m  RELEASE SAVEPOINT active_record_1

UserMailer#account_activation: processed outbound mail in 5.8ms
Redirected to http://www.example.com/
Completed 302 Found in 15ms (ActiveRecord: 0.6ms)
Started GET "/" for 127.0.0.1 at 2015-01-21 14:03:04 -0800
Processing by StaticPagesController#home as HTML
  Rendered layouts/_header.html.erb (0.2ms)
  Rendered layouts/_footer.html.erb (0.1ms)
Completed 200 OK in 2ms (Views: 1.8ms | ActiveRecord: 0.0ms)
  [1m[36m (0.2ms)[0m  [1mSELECT COUNT(*) FROM `users`[0m
  [1m[35m (0.4ms)[0m  ROLLBACK
  [1m[36m (0.1ms)[0m  [1mBEGIN[0m
------------------------------------------------------------------

1 个答案:

答案 0 :(得分:1)

您正在重定向到root:

redirect_to root_url

但是你的测试期待'用户/节目'。

编辑: 要重定向到用户个人资料:

redirect_to @user