キリンめも(技術)

記事を書いています #rails #swift #JS #UE4 #unity

Railsの会12日目「テストが落ちたので修正」補足

 

今日の進捗。

f:id:geta206:20160719052539p:plain

agenda

  1.  テストが落ちた原因
  2. 解決方法
  3. まとめ 

1.テストが落ちた!!!!!!(テストが落ちた原因)

テストコマンドを打った↓

$ bundle exec rake test

iTerm------------------------------------------------------------------------------------

# Running: 
F.F
Finished in 0.389066s, 7.7108 runs/s, 15.4215 assertions/s.
  1) Failure:
StaticPagesControllerTest#test_should_get_about [/Users/kadehina/Desktop/web.study/Ruby-study/workspace/sample_app/test/controllers/static_pages_controller_test.rb:19]:
<About | Ruby on Rails Tutorial Sample App> expected but was
<Home | Ruby on Rails Tutorial Sample App>..
Expected 0 to be >= 1.
 
  2) Failure:
StaticPagesControllerTest#test_should_get_home [/Users/kadehina/Desktop/web.study/Ruby-study/workspace/sample_app/test/controllers/static_pages_controller_test.rb:7]:
<Home | Ruby on Rails Tutorial Sample App> expected but was
<About | Ruby on Rails Tutorial Sample App>..
Expected 0 to be >= 1.
 
3 runs, 6 assertions, 2 failures, 0 errors, 0 skips
 
FAIL: 1
 
----------------------------------------------------------------------------------------------------------- 
 エラーが出ている…!
2)の部分。エラー文に注目。

f:id:geta206:20170311184431p:plain

ーーーーーーーーーーーーーーーーーーー
そして、URLの部分を読む。。
[/Users/kadehina/Desktop/web.study/Ruby-study/workspace/sample_app/test/controllers/static_pages_controller_test.rb:7]:
 
7行目がおかしい???????
 
とりあえずエラー文の指示通り、Sublime で開き、間違ったコードを探した。
7行目を見てみる。
ーーーーーーーーーーーーーーーーーーーーー
7行目  
           Sublime
  assert_select "title", "Home | Ruby on Rails Tutorial Sample App"
 
…?? どうゆう意味なんだ!
これの意味を教科書から探し始める。
 
教科書のサイトを開き
コマンド+F で  assert_select "title", "Home | Ruby on Rails Tutorial Sample App” を探す。
以下のURLに7行目の意味が書かれていた。
ーーーーーーーーーーーーーーーーーーー
なるほど。
特定のHTMLタグが存在するかどうかをテストします。(この種のアサーション メソッドはその名から「セレクタ」と呼ばれることもあります)。

 

 その次に下記の文章を読んでまた、Sublime で確認した。

上のセレクタは、<title>タグの内に「Home|Ruby on Rails Tutorial Sample App」という文字があるかどうかをチェックします。
この文章の意味を何となくわかった…!
assert_select "title", "Home | Ruby on Rails Tutorial Sample App"
 
 ーーーーーーーーーーーーーーーー
 
そして、、もう一度エラー文読んだ。
 
<Home | Ruby on Rails Tutorial Sample App> expected but was
<About | Ruby on Rails Tutorial Sample App>..
 
homeがaboutになっているのかな…?(多分)
 …?わからない!!!!
 
 もう一度
 
えらーのコードaboutのページ()を確認した。
about.html.erb と書かれているコードに
<% provide(:title, “Home") %>
(:title, “Home") の中がaboutページなのにHomeになっている…!
間違いを発見した。
ーーーーーーーーーーーーーーーーーーーー
 
もしかすると、homeも…?と思い
home.html.erb も同じように確認した。
<% provide(:title, “About") %>
(:title, “About")の中はやはりAboutって書かれていた。( ;´Д`)
!!ここで自分の間違いに確信を持つ。(遅い
 
ーーーーーーーーーーーーーー

2.error解決方法

about.html.erbから修正しました。
以下のようになっていた。
<% provide(:title, "Home") %>
<h1>Sample App</h1>
<p>
  This is the home page for the
  <a href="http://www.railstutorial.org/">Ruby on Rails Tutorial</a>
  sample application.
</p>
 
これを
以下のように修正しました。(aboutページ

<% provide(:title, "About") %>
<h1>About</h1>
<p>
  The <a href="http://www.railstutorial.org/"><em>Ruby on Rails
  Tutorial</em></a> is a
  <a href="http://railstutorial.jp">book</a> and
  <a href="http://screencasts.railstutorial.org/">screencast series</a>
  to teach web development with
  <a href="http://rubyonrails.org/">Ruby on Rails</a>.
  This is the sample application for the tutorial.
</p>

 

 
ーーーーーーーーーーーーーーーーーーーーー
同様に
home.html.erb も同じように。
 <% provide(:title, "About") %>  ・・・・・(以下略)・・・・
 と書かれていたものを以下のようにコピペ(教科書から)した。
<% provide(:title, "Home") %>   ・・・・・(以下略)・・・・
ーーーーーーーーーーーーーーーーーーーーー
できているのか確認のためエラー解決したか確認!
$ bundle exec rake test
iTermーーーーーーーーーーーーー
# Running:
...
Finished in 0.351705s, 8.5299 runs/s, 17.0597 assertions/s.
 
3 runs, 6 assertions, 0 failures, 0 errors, 0 skips
ーーーーーーーーーーーーー
 
できました。!!!!!

3.まとめ 

かなり初歩的な間違いだったのですが、

$ bundle exec rake test の大切さを学べた気がします。

そのほかにも エラーの直し方までを相手に説明のために書けば良いのかも…!

反省点

  • エラーの読み方が甘い。(英語大事…
  • コードの意味を理解していない。

 

エラーの解決方法まで簡単にまとめてみた。

  1. エラーが発生!!(エラー文を読む 7行目がおかしいらしい
  2. 7行目を読む 
  3. 意味を調べるため、教科書を見直す(railstutorial)
  4. 文が多くて探せなかったので command  +  F で検索をかける
  5. エラー文をもう一度みる (home と aboutの異変に気付く。
  6. 修正
  7. $ bundle exec rake test

 

まだまだ初心者から抜け出せそうにない…( ;  ; )