質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

Q&A

解決済

1回答

2813閲覧

Rails Tutorial10章の10.32のテストが通りません

YutaShirokawa

総合スコア12

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

0グッド

2クリップ

投稿2016/10/28 18:48

編集2016/10/30 18:13

みなさん、こんにちは。
現在Rails tutorial第3版、10章に取り組んでおります。
10.32のテストが通りません。

以下、テスト結果全文です。

xxxxxxxxxxxxxxxxxxxxxxxxxxx:sample_app xxxxxxxxx$ bundle exec rake test DEPRECATION WARNING: Sprockets method `register_engine` is deprecated. Please register a mime type using `register_mime_type` then use `register_compressor` or `register_transformer`. https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors (called from block (2 levels) in <class:Railtie> at /Users/xxxxxxxxx/.rvm/gems/ruby-2.2.5/gems/sass-rails-5.0.2/lib/sass/rails/railtie.rb:57) DEPRECATION WARNING: Sprockets method `register_engine` is deprecated. Please register a mime type using `register_mime_type` then use `register_compressor` or `register_transformer`. https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors (called from block (2 levels) in <class:Railtie> at /Users/xxxxxxxxx/.rvm/gems/ruby-2.2.5/gems/sass-rails-5.0.2/lib/sass/rails/railtie.rb:58) Run options: --seed 10105 # Running: ..................F..............DEPRECATION WARNING: The assertion was not run because of an invalid css selector. unexpected '$' after '[:equal, "\"/login\""]' (called from block in <class:UsersLoginTest> at /Users/xxxxxxxxx/workspace/sample_app/test/integration/users_login_test.rb:34) DEPRECATION WARNING: The assertion was not run because of an invalid css selector. unexpected '$' after '[:equal, "\"/logout\""]' (called from block in <class:UsersLoginTest> at /Users/xxxxxxxxx/workspace/sample_app/test/integration/users_login_test.rb:35) DEPRECATION WARNING: The assertion was not run because of an invalid css selector. unexpected '$' after '[:equal, "\"/users/762146111\""]' (called from block in <class:UsersLoginTest> at /Users/xxxxxxxxx/workspace/sample_app/test/integration/users_login_test.rb:36) ... Finished in 1.560245s, 23.0733 runs/s, 76.9110 assertions/s. 1) Failure: UsersSignupTest#test_valid_signup_information_with_account_activation [/Users/xxxxxxxxx/workspace/sample_app/test/integration/users_signup_test.rb:41]: expecting <"user/show"> but rendering with <["users/show", "layouts/_shim", "layouts/_header", "layouts/_footer", "layouts/application"]> 36 runs, 120 assertions, 1 failures, 0 errors, 0 skips

また、エラーが出ているテストが以下です。

<test/integration/users_signup_test.rb> require 'test_helper' class UsersSignupTest < ActionDispatch::IntegrationTest def setup ActionMailer::Base.deliveries.clear end test "invalid signup information" do get signup_path assert_no_difference 'User.count' do post users_path, user: {name: "", email: "user@invalid", password: "foo", password_confirmation: "bar"} end assert_template 'users/new' end test "valid signup information with account activation" do get signup_path assert_difference 'User.count',1 do post users_path, user: { name: "Example User", email: "user@example.com", password: "password", password_confirmation: "password"} end # 配信されたメッセージが1つであるかどうかを確認する assert_equal 1, ActionMailer::Base.deliveries.size user = assigns(:user) assert_not user.activated? # 有効化していない状態でログインしてみる log_in_as(user) assert_not is_logged_in? # 有効化トークンが不正な場合 get edit_account_activation_path("invalid token") assert_not is_logged_in? # トークンは正しいがメールアドレスが無効な場合 get edit_account_activation_path(user.activation_token, email: 'wrong') # 有効化トークンが正しい場合 get edit_account_activation_path(user.activation_token, email:user.email) assert user.reload.activated? follow_redirect! assert_template 'user/show' assert is_logged_in? end end

エラーを見るに、「user/showしか求めてないのにいろいろレンダリングしてしまっているよ」ということが言われているのかな?と考えております。

なお、user/showが以下になります。

app/views/users/show.html.erb <% provide(:title, @user.name) %> <div class="row"> <aside class="col-md-4"> <section class="user_info"> <h1> <%= gravatar_for @user %> <%= @user.name %> </h1> </section> </aside> </div>
app/views/layouts/application.html.erb <!DOCTYPE html> <html> <head> <title><%= full_title(yield(:title)) %></title> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> <%= render 'layouts/shim' %> </head> <body> <%= render 'layouts/header' %> <div class="container"> <% flash.each do |message_type, message| %> <%= content_tag(:div, message, class: "alert alert-#{message_type}") %> <% end %> <%= yield %> <%= render 'layouts/footer' %> <%= debug(params) if Rails.env.development? %> </div> </body> </html>

どなたか、原因がおわかりの方がいらっしゃいましたら、ご教示頂きたく存じます。
よろしくお願いいたします。

追記:bin/rake aboutの結果が以下です。

/Users/xxxxxxxxxxx/.rvm/gems/ruby-2.2.5/gems/spring-1.1.3/lib/spring/application.rb:164: warning: Insecure world writable dir /usr/local in PATH, mode 040777 About your application's environment Rails version 4.2.2 Ruby version 2.2.5-p319 (x86_64-darwin14) RubyGems version 2.4.8 Rack version 1.6.4 JavaScript Runtime JavaScriptCore Middleware Rack::Sendfile, ActionDispatch::Static, Rack::Lock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007fe4fb350038>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::Head, Rack::ConditionalGet, Rack::ETag Application root /Users/xxxxxxxxxxxx/workspace/sample_app Environment development Database adapter sqlite3 Database schema version 20161030103236

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2016/10/30 04:05

bin/rake about の結果を貼って頂けますか?
退会済みユーザー

退会済みユーザー

2016/10/31 00:55

もしかして rails のバージョンが 5 系だったりするのかと思いましたが、違いましたね。追加ですいませんが、bundle exec gem list もお願いします。
guest

回答1

0

ベストアンサー

https://github.com/yasslab/sample_apps/blob/master/4_2_2/ch10/test/integration/users_signup_test.rb を見つけたので diff で比較してみたところ、 assert_template の引数が違っているようです。

assert_template 'user/show' となっているところを、assert_template 'users/show' と users に直してみてください。

投稿2016/11/03 02:22

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

YutaShirokawa

2016/11/04 07:11

ご回答ありがとうございます!非常に助かりました!!本当にありがとうございました!
退会済みユーザー

退会済みユーザー

2016/11/04 07:12

これ、エラーメッセージが分かり辛くて難解でした (^^;。スッキリされたようで何よりです。
YutaShirokawa

2016/11/04 07:14

また機会がありましたら是非よろしくお願い致します、、、僕も早く教えられる側になれるよう、頑張ります!ありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問