{"id":1325,"date":"2012-12-25T23:01:00","date_gmt":"2012-12-25T14:01:00","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=1325"},"modified":"2018-11-14T16:33:57","modified_gmt":"2018-11-14T07:33:57","slug":"rails%e3%83%a9%e3%82%a4%e3%83%96%e3%83%a9%e3%83%aa%e7%b4%b9%e4%bb%8b-%e3%83%86%e3%82%b9%e3%83%88%e3%81%ae%e3%82%ab%e3%83%90%e3%83%ac%e3%83%83%e3%82%b8%e3%82%92%e6%b1%82%e3%82%81%e3%82%8b%e3%80%8csimp","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2012\/12\/25\/rails%e3%83%a9%e3%82%a4%e3%83%96%e3%83%a9%e3%83%aa%e7%b4%b9%e4%bb%8b-%e3%83%86%e3%82%b9%e3%83%88%e3%81%ae%e3%82%ab%e3%83%90%e3%83%ac%e3%83%83%e3%82%b8%e3%82%92%e6%b1%82%e3%82%81%e3%82%8b%e3%80%8csimp\/","title":{"rendered":"Rails\u30e9\u30a4\u30d6\u30e9\u30ea\u7d39\u4ecb: \u30c6\u30b9\u30c8\u306e\u30ab\u30d0\u30ec\u30c3\u30b8\u3092\u6c42\u3081\u308b\u300cSimpleCov\u300d"},"content":{"rendered":"
\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n
\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u306e\u30ab\u30d0\u30ec\u30c3\u30b8\uff08\u7db2\u7f85\u7387\uff09\u3092\u6c42\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u30e9\u30a4\u30d6\u30e9\u30ea SimpleCov \u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n
<\/p>\n
<\/p>\n
Gemfile \u306b\u4ee5\u4e0b\u306e\u884c\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n
gem 'simplecov', :require => false, :group => :test<\/pre>\n\u30c6\u30b9\u30c8\u5b9f\u884c\u6642\u306e\u307f\u5fc5\u8981\u306a\u306e\u3067 :group => :test \u3092\u4ed8\u3051\u3066\u3044\u307e\u3059\u3002<\/p>\n
bundle install \u3057\u307e\u3059\u3002<\/p>\n
bundle install<\/pre>\nTestUnit \u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f test\/test_helper.rb\u3001RSpec \u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f spec_helper.rb \u306b\u4ee5\u4e0b\u306e\u5185\u5bb9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n
\u3053\u3053\u3067\u6ce8\u610f\u4e8b\u9805\u304c\u3042\u308a\u307e\u3059\u3002SimpleCov \u306f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b3\u30fc\u30c9\u3088\u308a\u3082\u5148\u306b\u30ed\u30fc\u30c9\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u3001test\/test_helper.rb \u306e\u5148\u982d\u306b\u8ffd\u52a0\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n
# \u6b21\u306e 2 \u884c\u3092\u8ffd\u52a0\u3057\u307e\u3059.\r\nrequire 'simplecov'\r\nSimpleCov.start 'rails'\r\n\r\n# \u5143\u3005\u66f8\u304b\u308c\u3066\u3044\u305f\u30b3\u30fc\u30c9.\r\nENV[\"RAILS_ENV\"] = \"test\"\r\nrequire File.expand_path('..\/..\/config\/environment', __FILE__)\r\nrequire 'rails\/test_help'\r\n...<\/pre>\n\u305d\u308c\u3067\u306f\u30c6\u30b9\u30c8\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n
rake test<\/pre>\n\u30c6\u30b9\u30c8\u306e\u5b9f\u884c\u304c\u7d42\u308f\u308b\u3068\u3001coverage \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u7d50\u679c\u304c HTML \u30d5\u30a1\u30a4\u30eb\u3067\u51fa\u529b\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u5206\u304b\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n
coverage\/index.html \u3092\u958b\u304f\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n
<\/a><\/p>\n
<\/p>\n
\u30ab\u30d0\u30ec\u30c3\u30b8\u306b\u95a2\u3059\u308b\u6ce8\u610f\u70b9<\/h2>\n
\u300c\u30c6\u30b9\u30c8\u30ab\u30d0\u30ec\u30c3\u30b8 100% \u9054\u6210\uff01\u300d\u3084\u300c\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3067\u306f\u30ab\u30d0\u30ec\u30c3\u30b8\u3092 100% \u306b\u3059\u308b\u3053\u3068\uff01\u300d\u3068\u8a00\u308f\u308c\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u30ab\u30d0\u30ec\u30c3\u30b8\u306b\u3082\u3044\u304f\u3064\u304b\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n
\u30db\u30ef\u30a4\u30c8\u30dc\u30c3\u30af\u30b9\u30c6\u30b9\u30c8\u3067\u306e\u30ab\u30d0\u30ec\u30c3\u30b8\u3067\u306f\u3001\u4ee5\u4e0b\u306b\u6319\u3052\u308b C0, C1, C2 \u3068\u3044\u3046\u57fa\u6e96\u304c\u4e00\u822c\u7684\u3067\u3059\u3002<\/p>\n
\n
- C0 \u547d\u4ee4\u7db2\u7f85<\/li>\n
- C1 \u5206\u5c90\u7db2\u7f85<\/li>\n
- C2 \u6761\u4ef6\u7db2\u7f85<\/li>\n<\/ul>\n
simplecov \u3067\u53d6\u5f97\u3067\u304d\u308b\u306e\u306f C0\u3001\u3064\u307e\u308a\u547d\u4ee4\u7db2\u7f85\uff08\u30e9\u30a4\u30f3\u30ab\u30d0\u30ec\u30c3\u30b8\uff09\u3068\u547c\u3070\u308c\u308b\u3082\u306e\u3067\u3059\u3002<\/p>\n
\u30ab\u30d0\u30ec\u30c3\u30b8\u306e\u53d6\u5f97\u306f\u30c4\u30fc\u30eb\u3067\u884c\u306a\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001\u4f55\u3092\u53d6\u5f97\u3059\u308b\u306e\u304b\u6c7a\u3081\u308b\u3053\u3068\u3084\u3001\u4f55\u3092\u53d6\u5f97\u3057\u3066\u3044\u308b\u306e\u304b\u77e5\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u30c4\u30fc\u30eb\u3092\u4f7f\u3046\u4eba\u306e\u5f79\u5272\u3067\u3059\u3002<\/p>\n
\u5358\u7d14\u306b\u30ab\u30d0\u30ec\u30c3\u30b8\u306e\u30d1\u30fc\u30bb\u30f3\u30c8\u3060\u3051\u898b\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u672c\u5f53\u306b\u610f\u5473\u306e\u3042\u308b\u30c6\u30b9\u30c8\u3092\u884c\u306a\u3048\u3066\u3044\u308b\u306e\u304b\u8003\u3048\u3064\u3065\u3051\u308b\u3053\u3068\u304c\u5927\u5207\u3067\u3059\u3002<\/p>\n
\u3042\u308a\u304c\u3061\u306a\u3053\u3068\u3068\u3057\u3066\u3001\u30e2\u30c7\u30eb\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u30c6\u30b9\u30c8\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n
\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u306e\u3067\u3001\u30af\u30e9\u30b9\u304c\u30ed\u30fc\u30c9\u3055\u308c\u308b\u3060\u3051\u3067\u300cvalidates ...\u300d\u306e\u90e8\u5206\u304c\u5168\u3066\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002\u3064\u307e\u308a\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092 1 \u884c\u3082\u66f8\u3044\u3066\u3044\u306a\u3044\u306b\u3082\u95a2\u308f\u3089\u305a C0 \u306e\u30ab\u30d0\u30ec\u30c3\u30b8\u306f 100% \u3068\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n
class User < ActiveRecord::Base\r\n\r\n validates :name, :presence => true, :length => {:maximum => 20}\r\n\r\n validates :birthday, :presence => true\r\n\r\n validates :email, :presence => true\r\n\r\n ...\r\n\r\nend<\/pre>\n\u30ab\u30d0\u30ec\u30c3\u30b8\u3092 100% \u306b\u3059\u308b\u3053\u3068\u304c\u5927\u5207\u306a\u306e\u3067\u306f\u306a\u304f\u3001\u610f\u5473\u306e\u3042\u308b\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u5927\u5207\u3067\u3059\u3002<\/p>\n
<\/p>\n
\u307e\u3068\u3081<\/h2>\n
SimpleCov \u306e\u7d39\u4ecb\u3068\u3001\u30ab\u30d0\u30ec\u30c3\u30b8\u306b\u95a2\u3059\u308b\u6ce8\u610f\u70b9\u306b\u3064\u3044\u3066\u304a\u8a71\u3057\u3057\u307e\u3057\u305f\u3002<\/p>\n
\u4eca\u56de\u306f\u7d39\u4ecb\u3057\u307e\u305b\u3093\u3067\u3057\u305f\u304c\u3001SimpleCov \u306b\u306f\u8a2d\u5b9a\u9805\u76ee\u304c\u3044\u304f\u3064\u3082\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u8208\u5473\u3092\u3082\u305f\u308c\u305f\u65b9\u306f SimpleCov \u306e\u30b5\u30a4\u30c8\u3082\u305c\u3072\u30c1\u30a7\u30c3\u30af\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n
<\/p>\n","protected":false},"excerpt":{"rendered":"
\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n
\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u306e\u30ab\u30d0\u30ec\u30c3\u30b8\uff08\u7db2\u7f85\u7387\uff09\u3092\u6c42\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u30e9\u30a4\u30d6\u30e9\u30ea SimpleCov \u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002
\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[91,18,84],"tags":[22,24,71,60,70],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/1325"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=1325"}],"version-history":[{"count":1,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/1325\/revisions"}],"predecessor-version":[{"id":17989,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/1325\/revisions\/17989"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=1325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=1325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=1325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}