{"id":9754,"date":"2020-03-20T11:23:44","date_gmt":"2020-03-20T02:23:44","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=9754"},"modified":"2023-05-27T22:27:40","modified_gmt":"2023-05-27T13:27:40","slug":"%e3%80%90rspec%e3%80%91%e3%80%8c%e3%82%b5%e3%83%9d%e3%83%bc%e3%83%88%e3%83%a2%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab%e3%80%8d%e3%81%a7%e3%81%ae%e5%85%b1%e9%80%9a%e5%8c%96","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=9754","title":{"rendered":"\u3010Rspec\u3011\u300c\u30b5\u30dd\u30fc\u30c8\u30e2\u30b8\u30e5\u30fc\u30eb\u300d\u3067\u306e\u5171\u901a\u5316\u3001DRY\u539f\u5247"},"content":{"rendered":"<p>\u30b3\u30fc\u30c9\u306e\u91cd\u8907\u3092\u306a\u304f\u3059\u30b7\u30f3\u30d7\u30eb\u306a\u65b9\u6cd5\u306e\u4e00\u3064\u3068\u3057\u3066\u30b5\u30dd\u30fc\u30c8\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u3042\u308a\u307e\u3059\u3002\u7279\u306b\u30d5\u30a3\u30fc\u30c1\u30e3\u30fc\u30b9\u30da\u30c3\u30af\u3084\u30b7\u30b9\u30c6\u30e0\u30b9\u30da\u30c3\u30af\u3067\u3088\u304f\u4f7f\u3048\u308b\u624b\u6cd5\uff08\u30ed\u30b0\u30a4\u30f3\u51e6\u7406\u306e\u5171\u901a\u5316\u7b49\uff09\u3067\u3059\u3002<\/p>\n<h2>\u524d\u63d0<\/h2>\n<p>\u4e8b\u524d\u306b\u4e0b\u8a18\u30d5\u30a1\u30a4\u30eb\u304c\u7de8\u96c6\u3055\u308c\u3066\u3044\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">rspec\/rails_helper.rb<\/pre>\n<p>\u4e0b\u8a18\u306e\u51e6\u7406\u306e\u30b3\u30e1\u30f3\u30c8\u3092\u524a\u9664\u3057\u3066\u6709\u52b9\u5316\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"lang:default decode:true\">Dir[Rails.root.join('spec\/support\/**\/*.rb')].each { |f| require f }<\/pre>\n<h2>\u30b5\u30dd\u30fc\u30c8\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u4f5c\u308a\u65b9<\/h2>\n<h3>\u30e2\u30b8\u30e5\u30fc\u30eb\u5074<\/h3>\n<p>spec\u30d5\u30a9\u30eb\u30c0\u306bsupport\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u3066\u51e6\u7406\u3092\u8a18\u8ff0\u3059\u308b\u4efb\u610f\u306e\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"lang:default decode:true\">spec\/support\/(\u4efb\u610f\u306e\u51e6\u7406)_support.rb<\/pre>\n<p><span style=\"color: #ff0000;\"><strong>\u51e6\u7406\u306e\u540d\u524d\u306f\u30b3\u30fc\u30c9\u3092\u8aad\u3093\u3060\u969b\u306b\u7528\u9014\u304c\u3059\u3050\u306b\u308f\u304b\u308b\u540d\u524d\u306b\u3059\u308b<\/strong><\/span>\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u30b5\u30dd\u30fc\u30c8\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u5177\u4f53\u7684\u306a\u51e6\u7406\u5185\u5bb9\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">module [\u4efb\u610f\u306e\u51e6\u7406\u540d]Support\r\n  def \u30e1\u30bd\u30c3\u30c9\u540d(\u5f15\u6570)\r\n  end\r\nend\r\n\r\nRSpec.configure do |config|\r\n  config.include [\u4efb\u610f\u306e\u51e6\u7406\u540d]Support\r\nend<\/pre>\n<h3>\u547c\u3073\u51fa\u3059\u5074<\/h3>\n<pre class=\"lang:default decode:true \">RSpec.\u30b9\u30da\u30c3\u30af\u540d \"XXX\", type: :\u30b9\u30da\u30c3\u30af\u540d do\r\n  include \u30b5\u30dd\u30fc\u30c8\u30e2\u30b8\u30e5\u30fc\u30eb\u540d\r\n\r\n  \u30e1\u30bd\u30c3\u30c9\u540d \u5f15\u6570\r\nend<\/pre>\n<h2>\u53c2\u8003\uff1aDRY\u539f\u5247\u3068\u306f\uff1f<\/h2>\n<p><span style=\"color: #ff0000;\"><strong>\u300cDon't repeat yourself\u300d<\/strong><\/span>\u306e\u7565\u3067\u300c\u91cd\u8907\u3055\u305b\u308b\u306a\u300d\u3068\u3044\u3046\u610f\u5473\u3067\u3059\u3002\u4f8b\u3048\u3070\u4e0b\u8a18\u306e\u3088\u3046\u306a\u3082\u306e\u3092\u91cd\u8907\u3057\u3066\u7ba1\u7406\u305b\u305a\u306b\u4e00\u5143\u7ba1\u7406\u305b\u3088\u3068\u3044\u3046\u610f\u5473\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/li>\n<li>\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb<\/li>\n<li>\u8a2d\u5b9a\u5024<\/li>\n<li>\u30b9\u30ad\u30fc\u30de\u30d5\u30a1\u30a4\u30eb<\/li>\n<li>\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/li>\n<\/ul>\n<p>\u3053\u306e\u539f\u5247\u3092\u5b88\u3063\u3066\u3044\u306a\u3044\u3068<span style=\"color: #ff0000;\"><strong>\u5f8c\u3067\u4fee\u6b63\u3059\u308b\u969b\u306b\u8907\u6570\u7b87\u6240\u3092\u4fee\u6b63\u3059\u308b\u3053\u3068\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u304b\u306a\u308a\u306e\u78ba\u7387\u3067\u4fee\u6b63\u6f0f\u308c\u304c\u767a\u751f\u3057\u3066\u4e0d\u5177\u5408\u306b\u7e4b\u304c\u308b\u53ef\u80fd\u6027\u304c\u9ad8\u307e\u308a\u307e\u3059\u3002<\/strong><span style=\"color: #000000;\">\u3053\u306e\u539f\u5247\u3092\u5b88\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u4fdd\u5b88\u6027\u3082\u4e0a\u304c\u308a\u307e\u3059\u3002<\/span><\/span><\/p>\n<h3>\u5fc5\u305a\u3057\u3082\u3053\u306e\u539f\u5247\u3092\u5b88\u308c\u3070\u826f\u3044\u3068\u3044\u3046\u308f\u3051\u3067\u306f\u306a\u3044<\/h3>\n<h4>\u5f8c\u3005\u6539\u4fee\u306b\u3088\u3063\u3066\u5fae\u5999\u306b\u9055\u3046\u30b3\u30fc\u30c9\u304c\u767a\u751f\u3059\u308b\u5834\u5408\u304c\u3042\u308b\u3002<\/h4>\n<p>\u904e\u5ea6\u306e\u5171\u901a\u5316\u306f\u5404\u6a5f\u80fd\u306e\u4f9d\u5b58\u5ea6\u304c\u9ad8\u307e\u308a\u5bc6\u7d50\u5408\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u3002<\/p>\n<h4>\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u306e\u767b\u5834<\/h4>\n<p>\u30e2\u30ce\u30ea\u30b7\u30c3\u30af\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u5834\u5408\u306f\u78ba\u5b9f\u306bDRY\u539f\u5247\u3092\u5b88\u3063\u3066\u3044\u3051\u3070\u3088\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u6628\u4eca\u4eba\u6c17\u306e\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3092\u53d6\u308a\u5165\u308c\u305f\u5834\u5408\u306f\u3069\u3046\u3057\u3066\u3082\u91cd\u8907\u3057\u305f\u30b3\u30fc\u30c9\u304c\u767a\u751f\u305b\u3056\u308b\u304a\u3048\u306a\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<h4>\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3067\u306f\u5fc5\u305a\u3057\u3082DRY\u304c\u6b63\u7fa9\u3068\u3044\u3046\u308f\u3051\u3067\u306f\u306a\u3044\u3002<\/h4>\n<p>\u901a\u5e38\u306e\u30bd\u30fc\u30b9\u306e\u5834\u5408\u306f\u57fa\u672c\u7684\u306bDRY\u3092\u5b88\u3063\u3066\u3044\u306a\u3044\u30b3\u30fc\u30c9\u306f\u4fee\u6b63\u3057\u305f\u65b9\u304c\u826f\u3044\u3067\u3059\u304c<span style=\"color: #ff0000;\"><strong>\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u306b\u95a2\u3057\u3066\u306f\u5fc5\u305a\u3057\u3082\u60aa\u3044\u3053\u3068\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/strong><\/span><\/p>\n<p>\u4f8b\u3048\u3070\u3001\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u306f\u57fa\u672c\u7684\u306b\u306f\u9577\u304f\u306a\u308b\u306e\u3067\u3059\u304c\u4f8b\u3048\u3070Rspec\u306ebefore\u30d5\u30c3\u30af\u7b49\u3067\u51e6\u7406\u3092\u5171\u901a\u5316\u3057\u305f\u5834\u5408\u306b<span style=\"color: #ff0000;\"><strong>\u4e0a\u4e0b\u306b\u5927\u304d\u304f\u30b9\u30af\u30ed\u30fc\u30eb\u3057\u306a\u3051\u308c\u3070\u8aad\u3081\u306a\u3044\u3088\u3046\u306a\u5834\u5408\u306f\u53ef\u8aad\u6027\u304c\u9ad8\u3044\u3068\u306f\u8a00\u3048\u306a\u3044\u5834\u5408\u304c\u3042\u308b\u305f\u3081<\/strong><\/span>\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u30b3\u30fc\u30c9\u306e\u91cd\u8907\u3092\u306a\u304f\u3059\u30b7\u30f3\u30d7\u30eb\u306a\u65b9\u6cd5\u306e\u4e00\u3064\u3068\u3057\u3066\u30b5\u30dd\u30fc\u30c8\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u3042\u308a\u307e\u3059\u3002\u7279\u306b\u30d5\u30a3\u30fc\u30c1\u30e3\u30fc\u30b9\u30da\u30c3\u30af\u3084\u30b7\u30b9\u30c6\u30e0\u30b9\u30da\u30c3\u30af\u3067\u3088\u304f\u4f7f\u3048\u308b\u624b\u6cd5\uff08\u30ed\u30b0\u30a4\u30f3\u51e6\u7406\u306e\u5171\u901a\u5316\u7b49\uff09\u3067\u3059\u3002 \u524d\u63d0 \u4e8b\u524d\u306b\u4e0b\u8a18\u30d5\u30a1\u30a4\u30eb\u304c\u7de8\u96c6\u3055\u308c\u3066\u3044\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[82],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/9754"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9754"}],"version-history":[{"count":7,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/9754\/revisions"}],"predecessor-version":[{"id":20456,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/9754\/revisions\/20456"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9754"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9754"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9754"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}