{"id":7745,"date":"2019-12-01T12:46:53","date_gmt":"2019-12-01T03:46:53","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=7745"},"modified":"2023-05-27T22:30:22","modified_gmt":"2023-05-27T13:30:22","slug":"%e3%80%90rspec%e3%80%91%e5%9f%ba%e6%9c%ac%e7%9a%84%e3%81%aa%e6%9b%b8%e3%81%8d%e6%96%b9","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=7745","title":{"rendered":"\u3010Rspec\u3011\u57fa\u672c\u7684\u306a\u66f8\u304d\u65b9\u3001\u30bf\u30b0\u306a\u3069"},"content":{"rendered":"<h2>Rspec\u30b3\u30fc\u30c9\u306e\u57fa\u672c\u5f62<\/h2>\n<p>Rspec\u306e\u57fa\u672c\u5f62\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">describe [\u30c6\u30b9\u30c8\u5bfe\u8c61],type:[spec\u306e\u7a2e\u985e] do\r\n  context [\u72b6\u614b] do\r\n    before do\r\n      [\u4e8b\u524d\u6e96\u5099]\r\n    end\r\n\r\n    it [\u4ed5\u69d8] do\r\n      [\u671f\u5f85\u52d5\u4f5c]\r\n    end\r\n  end\r\nend<\/pre>\n<p>Rspec\u306b\u306fSystem Spec\u3084Model Spec\u7b49\u69d8\u3005\u306aSpec\u306e\u7a2e\u985e\u304c\u5b58\u5728\u3057\u307e\u3059\u304c\u57fa\u672c\u7684\u306b<span style=\"color: #ff0000;\"><strong>\u3069\u306eSpec\u3092\u4f7f\u3046\u5834\u5408\u3067\u3082\u540c\u3058\u611f\u3058\u3067\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/strong><\/span><\/p>\n<h2>\u69cb\u6587\u306e\u5f79\u5272<\/h2>\n<p>Rspec\u306e\u69cb\u6587\u306b\u306f\u305d\u308c\u305e\u308c\u5f79\u5272\u304c\u3042\u308b\u306e\u3067\u628a\u63e1\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>describe<\/h3>\n<p>\u30c6\u30b9\u30c8\u5bfe\u8c61\u306e\u6a5f\u80fd\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<h4>System Spec\u3067\u306f<\/h4>\n<p>\u4e00\u9023\u306e\u64cd\u4f5c\u306b\u3088\u308a\u52d5\u4f5c\u78ba\u8a8d\u3092\u3057\u305f\u3044\u6a5f\u80fd\u3084\u51e6\u7406\u306e\u540d\u524d\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<h4>Model Spec\u3067\u306f<\/h4>\n<p>\u30e2\u30c7\u30eb\u30af\u30e9\u30b9\u540d\u3084\u30e1\u30bd\u30c3\u30c9\u540d\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<h4>\u4f8b<\/h4>\n<pre class=\"lang:default decode:true \">\u6587\u5b57\u5217\u306b\u4e00\u81f4\u3059\u308b\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u691c\u7d22\u3059\u308b<\/pre>\n<h3>context<\/h3>\n<p>\u30c6\u30b9\u30c8\u306e\u69d8\u3005\u306a\u6761\u4ef6\u306e\u6982\u8981\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002Rspec\u3067\u306fcontext\u306fdescribe\u306e\u30a8\u30a4\u30ea\u30a2\u30b9\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067describe\u306e\u4ee3\u308f\u308a\u306bcontext\u3092\u4f7f\u3063\u305f\u3068\u3057\u3066\u3082\u52d5\u4f5c\u306f\u3057\u307e\u3059\u3002<\/p>\n<h4>\u4f8b<\/h4>\n<pre class=\"lang:default decode:true \">\u4e00\u81f4\u3059\u308b\u30c7\u30fc\u30bf\u304c\u898b\u3064\u304b\u308b\u6642\r\n\u4e00\u81f4\u3059\u308b\u30c7\u30fc\u30bf\u304c\u898b\u3064\u304b\u3089\u306a\u3044\u6642<\/pre>\n<h3>before<\/h3>\n<p>\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u524d\u306b\u3053\u3061\u3089\u306b\u8a18\u8ff0\u3055\u308c\u305f\u5185\u5bb9\u3092\u5b9f\u884c\u3057\u3066\u304f\u308c\u308b\u306e\u3067\u30c6\u30b9\u30c8\u306e<span style=\"color: #ff0000;\"><strong>\u300c\u524d\u63d0\u6761\u4ef6\u300d<\/strong><\/span>\u3092\u8a18\u8ff0\u3059\u308b\u305f\u3081\u306b\u4f7f\u3044\u307e\u3059\u3002describe\u306e\u4e2d\u306b\u8907\u6570\u306e\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u3092\u8a18\u8ff0\u3059\u308b\u5834\u5408\u306f\u3053\u3061\u3089\u306b\u4e8b\u524d\u51e6\u7406\u3092\u307e\u3068\u3081\u3066\u8a18\u8ff0\u3059\u308c\u3070\u5171\u901a\u5316\u306b\u3082\u306a\u308a\u307e\u3059\u3002\u306a\u304a\u3001before\u306e\u51e6\u7406\u306f\u5f8c\u7d9a\u306eit\u306e\u51e6\u7406\u304c\u5b9f\u884c\u3055\u308c\u308b\u305f\u3073\u306b\u5b9f\u884c\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001before\u30d6\u30ed\u30c3\u30af\u306e\u4e2d\u3067\u5909\u6570\u3092\u4f7f\u3046\u5834\u5408\u306f<span style=\"color: #ff0000;\"><strong>\u30c6\u30b9\u30c8\u5168\u4f53\u3067\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u5fc5\u8981\u304c\u3042\u308b\u305f\u3081\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u3067\u306f\u306a\u304f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5909\u6570\uff08@\u4ed8\u304d\u306e\u5909\u6570\uff09\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/strong><\/span><\/p>\n<h3>after<\/h3>\n<p>\u30c6\u30b9\u30c8\u306e\u5f8c\u51e6\u7406\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<span style=\"color: #ff0000;\"><strong>Rspec\u3067\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u5f8c\u7247\u4ed8\u3051\u3092\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u3084\u3063\u3066\u304f\u308c\u308b\u306e\u3067\u3053\u306e\u30d5\u30c3\u30af\u3092\u4f7f\u3046\u3053\u3068\u306f\u307b\u3068\u3093\u3069\u3042\u308a\u307e\u305b\u3093\u3002<\/strong><\/span><\/p>\n<h3>it<\/h3>\n<p>\u671f\u5f85\u3059\u308b\u52d5\u4f5c\u306e\u8a73\u7d30\u3084\u6761\u4ef6\u3092\u8a18\u8f09\u3057\u307e\u3059\u3002\u5b9f\u969b\u306b\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3068\u3057\u3066\u5177\u4f53\u7684\u306b\u8a18\u8ff0\u3059\u308b\u306e\u306f\u3053\u306e\u30d6\u30ed\u30c3\u30af\u5185\u306b\u306a\u308a\u307e\u3059\u3002\u3053\u3061\u3089\u304c\u671f\u5f85\u901a\u308a\u52d5\u4f5c\u3059\u308c\u3070\u30c6\u30b9\u30c8\u6210\u529f\u306e\u96c6\u8a08\u304c1\u4ef6\u5897\u52a0\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306f\u30a8\u30e9\u30fc\uff08Error\uff09\u3001\u4f8b\u5916\u306f\u8d77\u304d\u3066\u3044\u306a\u3044\u304c\u60f3\u5b9a\u5916\u306e\u5834\u5408\u306f\u5931\u6557\uff08Failure\uff09\u306b\u30ab\u30a6\u30f3\u30c8\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001<span style=\"color: #ff0000;\"><strong>DB\u306e\u72b6\u614b\u306f\u6b21\u306eit\u304c\u5b9f\u884c\u3055\u308c\u308b\u5834\u5408\u306f\u5143\u306b\u623b\u3055\u308c\u308b<\/strong><\/span>\u305f\u3081\u3001\u3042\u308b\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u306e\u7d50\u679c\u306b\u3088\u3063\u3066\u5225\u306e\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u304c\u5f71\u97ff\u3092\u53d7\u3051\u308b\u3068\u3044\u3046\u3053\u3068\u304c\u7121\u3044\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\uff08\u9006\u306b\u8a00\u3048\u3070\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u306f\u4ed6\u306e\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u306e\u5f71\u97ff\u3092\u53d7\u3051\u306a\u3044\u3053\u3068\u524d\u63d0\u3067\u4f5c\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\uff09<\/p>\n<h4>it\u306e\u4e2d\u306b\u8a18\u8ff0\u3059\u308b\u30c1\u30a7\u30c3\u30af\u5185\u5bb9<\/h4>\n<p>\u4e00\u4f8b\u3067\u3059\u304c\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3092\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">expect(page).to have_content '\u5185\u5bb9'<\/pre>\n<h5>expect(page)<\/h5>\n<p>\u3068\u3044\u3046\u306e\u304cpage\u304c\u753b\u9762\u306e\u3053\u3068\u3092\u8868\u3057\u3066\u3044\u3066page\u306b\u671f\u5f85\u3059\u308b\u3068\u3044\u3046\u610f\u5473\u306b\u306a\u308a\u307e\u3059\u3002<span style=\"color: #ff0000;\"><strong>RSpec2.10\u4ee5\u524d\u306fshould\u3092\u4f7f\u3063\u3066\u3044\u307e\u3057\u305f<\/strong><\/span>\u304c\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u4f7f\u3063\u3066\u304a\u308a\u30d0\u30b0\u304c\u767a\u751f\u3057\u305f\u305f\u3081expect\u306b\u7f6e\u304d\u63db\u308f\u308a\u307e\u3057\u305f\u3002<\/p>\n<h5>to_have_content '\u5185\u5bb9'<\/h5>\n<p>\u300c\u5185\u5bb9\u300d\u3068\u3044\u3046\u5185\u5bb9\u304c\u30da\u30fc\u30b8\u5185\u306b\u3042\u308b\u306f\u305a\u3060\u3068\u3044\u3046\u3053\u3068\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u3053\u308c\u3092Rspec\u3067\u306f<span style=\"color: #ff0000;\"><strong>\u300c\u30de\u30c3\u30c1\u30e3\uff08Matcher)\u300d<\/strong><\/span>\u3068\u3044\u3044\u307e\u3059\u3002<\/p>\n<h3>it\u306e\u547d\u540d\u898f\u5247<\/h3>\n<p>\u82f1\u8a9e\u3067\u8a18\u8ff0\u3059\u308b\u5834\u5408\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u52d5\u8a5e\u304b\u3089\u59cb\u3081\u308b\u306e\u304c\u901a\u5e38\u306e\u3088\u3046\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">is invalid without a name(\u540d\u524d\u304c\u306a\u3051\u308c\u3070\u7121\u52b9\u306a\u72b6\u614b\u3067\u3042\u308b\u3002\uff09<\/pre>\n<h2>\u30cd\u30b9\u30c8\u3055\u305b\u308b\u3002<\/h2>\n<p>\u57fa\u672c\u7684\u306b\u696d\u52d9\u3067\u306fdescribe\u6587\u3092\u30cd\u30b9\u30c8\u3055\u305b\u3066\u4e0b\u8a18\u306e\u3088\u3046\u306b<span style=\"color: #ff0000;\"><strong>\u968e\u5c64\u69cb\u9020\u3067\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092\u8a18\u8ff0\u3059\u308b<\/strong><\/span>\u3053\u3068\u304c\u4e00\u822c\u7684\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">describe '\u25cb\u25cb\u30a2\u30d7\u30ea',type:system do\r\n  describe '\u691c\u7d22' do\r\n  end\r\n\r\n  describe '\u767b\u9332' do\r\n  end\r\nend<\/pre>\n<h3>\u4e00\u756a\u5916\u5074\u306edescribe<\/h3>\n<p>Spec\u30d5\u30a1\u30a4\u30eb\u306e\u30c6\u30fc\u30de\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002\uff08\u4f8b\u3067\u8a00\u3048\u3070\u25cb\u25cb\u30a2\u30d7\u30ea\uff09<\/p>\n<h3>\u5185\u5074\u306edescribe<\/h3>\n<p>\u7d30\u304b\u3044\u6a5f\u80fd\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<h2>\u30bf\u30b0\u3068\u306f\uff1f<\/h2>\n<p>\u3044\u304f\u3064\u304b\u3042\u308b\u30c6\u30b9\u30c8\u306e\u3046\u3061\u7279\u5b9a\u306e\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u306e\u307f\u30bf\u30b0\u4ed8\u3051\u3057\u3066\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n<h3>\u30bf\u30b0\u306e\u66f8\u304d\u65b9<\/h3>\n<p>\u30bf\u30b0\u540d\u306b\u306f<span style=\"color: #ff0000;\"><strong>focus<\/strong><\/span>\u3068\u3044\u3046\u30bf\u30b0\u540d\u304c\u3088\u304f\u4f7f\u308f\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">it \"\u4ed5\u69d8\",\u30bf\u30b0\u540d:\r\ntrue do\r\n  #\u4ed5\u69d8\r\nend<\/pre>\n<p>\u306a\u304a\u3001\u30bf\u30b0\u306fit\u3060\u3051\u3067\u306a\u304f\u300cdescribe\u30d6\u30ed\u30c3\u30af\u300d\u3084\u300ccontext\u30d6\u30ed\u30c3\u30af\u300d\u306b\u3082\u4ed8\u3051\u308b\u3053\u3068\u306f\u53ef\u80fd\u3067\u3059\u3002<span style=\"color: #ff0000;\"><strong>\u305d\u306e\u5834\u5408\u306f\u30d6\u30ed\u30c3\u30af\u5185\u306e\u5168\u30c6\u30b9\u30c8\u306b\u305d\u306e\u30bf\u30b0\u304c\u9069\u7528\u3055\u308c\u307e\u3059\u3002<\/strong><\/span><\/p>\n<h3>\u5b9f\u884c\u65b9\u6cd5<\/h3>\n<h4>\u7279\u5b9a\u306e\u30bf\u30b0\u3092\u5b9f\u884c\u3059\u308b<\/h4>\n<pre class=\"lang:default decode:true \">rspec --tag \u30bf\u30b0\u540d<\/pre>\n<h4>\u7279\u5b9a\u306e\u30bf\u30b0\u3092\u30b9\u30ad\u30c3\u30d7\u3059\u308b<\/h4>\n<p>\u30bf\u30b0\u540d\u306e\u6700\u521d\u306b\u30c1\u30eb\u30c0\u3092\u4ed8\u3051\u308b\u3068\u305d\u306e\u30bf\u30b0\u306e\u5b9f\u884c\u3060\u3051\u3092\u9006\u306b\u30b9\u30ad\u30c3\u30d7\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">rspec --tag ~\u30bf\u30b0\u540d<\/pre>\n","protected":false},"excerpt":{"rendered":"Rspec\u30b3\u30fc\u30c9\u306e\u57fa\u672c\u5f62 Rspec\u306e\u57fa\u672c\u5f62\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002 describe [\u30c6\u30b9\u30c8\u5bfe\u8c61],type:[spec\u306e\u7a2e\u985e] do context [\u72b6\u614b] do before do [\u4e8b\u524d\u6e96\u5099] end it  [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[82,48,36],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/7745"}],"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=7745"}],"version-history":[{"count":18,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/7745\/revisions"}],"predecessor-version":[{"id":20466,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/7745\/revisions\/20466"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7745"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7745"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}