{"id":9747,"date":"2020-03-20T06:46:23","date_gmt":"2020-03-19T21:46:23","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=9747"},"modified":"2023-05-27T22:27:56","modified_gmt":"2023-05-27T13:27:56","slug":"%e3%80%90rspec%e3%80%91%e3%80%8c%e3%83%aa%e3%82%af%e3%82%a8%e3%82%b9%e3%83%88%e3%82%b9%e3%83%9a%e3%83%83%e3%82%af%e3%80%8d%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=9747","title":{"rendered":"\u3010Rspec\u3011\u300c\u30ea\u30af\u30a8\u30b9\u30c8\u30b9\u30da\u30c3\u30af\u300d\u306b\u3064\u3044\u3066"},"content":{"rendered":"<h2>\u30ea\u30af\u30a8\u30b9\u30c8\u30b9\u30da\u30c3\u30af\u304c\u5fc5\u8981\u306a\u80cc\u666f<\/h2>\n<p>\u6700\u8fd1\u306eRails\u30a2\u30d7\u30ea\u3067\u306f\u5916\u90e8API\u3092\u6301\u3064\u3053\u3068\u304c\u5897\u3048\u3066\u304d\u3066\u3044\u307e\u3059\u3002\u5805\u7262\u306aAPI\u306b\u3059\u308b\u305f\u3081\u306b\u30c6\u30b9\u30c8\u3082\u3057\u3063\u304b\u308a\u3059\u308b\u3053\u3068\u304c\u6c42\u3081\u3089\u308c\u307e\u3059\u3002<\/p>\n<p>\u30e2\u30c7\u30eb\u306e\u30c6\u30b9\u30c8\uff08\u30e2\u30c7\u30eb\u30b9\u30da\u30c3\u30af\uff09\u3068\u30b7\u30b9\u30c6\u30e0\u30c6\u30b9\u30c8\uff08\u30b7\u30b9\u30c6\u30e0\u30b9\u30da\u30c3\u30af\uff09\u306e\u9593\u3092\u57cb\u3081\u308b\u30c6\u30b9\u30c8\u306b\u306a\u308a\u307e\u3059\u3002UI\u304b\u3089\u78ba\u8a8d\u3059\u308b\u307b\u3069\u306e\u3082\u306e\u3067\u306f\u306a\u3044\u304c\u3001\u30e2\u30c7\u30eb\u306e\u5358\u4f53\u30c6\u30b9\u30c8\u3067\u306f\u78ba\u8a8d\u3057\u306b\u304f\u3044\u3082\u306e\u3092\u30c6\u30b9\u30c8\u5bfe\u8c61\u306b\u3057\u307e\u3059\u3002<\/p>\n<h2>\u30ea\u30af\u30a8\u30b9\u30c8\u30b9\u30da\u30c3\u30af\u3092\u4f7f\u3046\u306b\u306f\uff1f<\/h2>\n<p>\u30d5\u30a3\u30fc\u30c1\u30e3\u30fc\u30b9\u30da\u30c3\u30af\u306e\u3088\u3046\u306b\u30d6\u30e9\u30a6\u30b6\u3092\u30b7\u30df\u30e5\u30ec\u30fc\u30c8\u3059\u308b\u5fc5\u8981\u306f\u306a\u3044\u306e\u3067Capybara\u306f\u4f7f\u3044\u307e\u305b\u3093\u3002\u4ee3\u308f\u308a\u306b<span style=\"color: #ff0000;\"><strong>HTTP\u30e1\u30bd\u30c3\u30c9(get,post,delete,patch\u7b49\uff09<\/strong><\/span>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p>Capybara\u306f\u72ec\u81ea\u306eDSL\u306b\u306a\u308b\u306e\u3067\u5168\u304f\u66f8\u3044\u305f\u3053\u3068\u304c\u306a\u3044\u4eba\u306b\u3068\u3063\u3066\u306f\u5b66\u7fd2\u30b3\u30b9\u30c8\u304c\u304b\u304b\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u3042\u307e\u308a\u5b66\u7fd2\u30b3\u30b9\u30c8\u3092\u304b\u3051\u305f\u304f\u306a\u3044\u3068\u3044\u3046\u610f\u5473\u3067\u3082\u30ea\u30af\u30a8\u30b9\u30c8\u30b9\u30da\u30c3\u30af\u3067\u66f8\u3044\u3066\u3057\u307e\u3046\u3068\u3044\u3046\u3088\u3046\u306a\u8003\u3048\u65b9\u3067\u3082\u3067\u304d\u305d\u3046\u3067\u3059\u3002<\/p>\n<h2>\u30ea\u30af\u30a8\u30b9\u30c8\u30b9\u30da\u30c3\u30af\u306e\u30b9\u30da\u30c3\u30af\u30d5\u30a1\u30a4\u30eb\u306e\u751f\u6210<\/h2>\n<pre class=\"lang:default decode:true\">rails g rspec:request \u30b9\u30da\u30c3\u30af\u30d5\u30a1\u30a4\u30eb\u540d\uff08\u4f8b\uff1ausers_api)<\/pre>\n<p>\u3059\u308b\u3068\u4e0b\u8a18\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002API\u304c\u8907\u6570\u306b\u306a\u308b\uff08apis)\u3068\u3044\u3046\u306e\u306f\u9055\u548c\u611f\u304c\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3001\u300capi\u300d\u306b\u5909\u66f4\u3057\u3066\u3082\u826f\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<pre class=\"lang:default decode:true\">spec\/requests\/users_apis_spec.rb<\/pre>\n<h2>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30b9\u30da\u30c3\u30af\u3068\u306e\u9055\u3044<\/h2>\n<p>\u30ea\u30af\u30a8\u30b9\u30c8\u30b9\u30da\u30c3\u30af\u3067\u3067\u304d\u308b\u3053\u3068\u306f\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30b9\u30da\u30c3\u30af\u3067\u3067\u304d\u308b\u3053\u3068\u3068\u4f3c\u3066\u3044\u307e\u3059\u3002\u4f8b\u3048\u3070POST\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3059\u308b\u306e\u3067\u3042\u308c\u3070\u4e0b\u8a18\u306e\u3088\u3046\u306b\u304b\u304d\u5206\u3051\u307e\u3059\u3002<span style=\"color: #ff0000;\"><strong>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30b9\u30da\u30c3\u30af\u306fcreate\u3068\u3044\u3046\u30a2\u30af\u30b7\u30e7\u30f3\u306b\u4f9d\u5b58\u3057\u3066\u5c45\u307e\u3059\u304c\u3001\u30ea\u30af\u30a8\u30b9\u30c8\u30b9\u30da\u30c3\u30af\u306f\u5177\u4f53\u7684\u306a\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u540d\u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/strong><\/span><\/p>\n<h3>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30b9\u30da\u30c3\u30af<\/h3>\n<pre class=\"lang:default decode:true\">post :create, params: { user: user_params }<\/pre>\n<h3>\u30ea\u30af\u30a8\u30b9\u30c8\u30b9\u30da\u30c3\u30af<\/h3>\n<pre class=\"lang:default decode:true\">post users_path, params: { user: user_params }<\/pre>\n<p>\u73fe\u5728\u306f\u300c\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u30b9\u30da\u30c3\u30af\u300d\u3092\u4f7f\u3046\u3088\u308a\u3082\u300c\u30ea\u30af\u30a8\u30b9\u30c8\u30b9\u30da\u30c3\u30af\u300d\u3092\u4f7f\u3046\u3053\u3068\u304c\u63a8\u5968\u3055\u308c\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<h4>get\u306e\u5834\u5408<\/h4>\n<pre class=\"lang:default decode:true\">    it \"GET\u30ea\u30af\u30a8\u30b9\u30c8\" do\r\n      get users_path\r\n      expect(response).to have_http_status(200)\r\n    end<\/pre>\n<p>\u4e0a\u306e\u4f8b\u3067\u306fpost\u3067\u3059\u304c\u3001get\u306e\u5834\u5408\u306f\u4e0a\u8a18\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u30ec\u30b9\u30dd\u30f3\u30b9\u30b9\u30c6\u30fc\u30bf\u30b9\u3067\u6b63\u5e38\u6027\u78ba\u8a8d\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u30ea\u30af\u30a8\u30b9\u30c8\u30b9\u30da\u30c3\u30af\u304c\u5fc5\u8981\u306a\u80cc\u666f \u6700\u8fd1\u306eRails\u30a2\u30d7\u30ea\u3067\u306f\u5916\u90e8API\u3092\u6301\u3064\u3053\u3068\u304c\u5897\u3048\u3066\u304d\u3066\u3044\u307e\u3059\u3002\u5805\u7262\u306aAPI\u306b\u3059\u308b\u305f\u3081\u306b\u30c6\u30b9\u30c8\u3082\u3057\u3063\u304b\u308a\u3059\u308b\u3053\u3068\u304c\u6c42\u3081\u3089\u308c\u307e\u3059\u3002 \u30e2\u30c7\u30eb\u306e\u30c6\u30b9\u30c8\uff08\u30e2\u30c7\u30eb\u30b9\u30da\u30c3\u30af\uff09\u3068\u30b7\u30b9\u30c6\u30e0\u30c6\u30b9\u30c8\uff08\u30b7\u30b9\u30c6 [&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\/9747"}],"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=9747"}],"version-history":[{"count":8,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/9747\/revisions"}],"predecessor-version":[{"id":20457,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/9747\/revisions\/20457"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9747"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}