Best Vcr_ruby code snippet using context.body_hash
me_spec.rb
Source:me_spec.rb
...15 headers = {16 'Authorization': "Bearer #{@activate_token}"17 }18 put '/api/v1/users/me/activate', headers: headers19 body_hash = JSON.parse(response.body)20 aggregate_failures do21 # ã¬ã¹ãã³ã¹ãã§ãã¯22 expect(response.status).to eq 20023 expect(body_hash["success"]).to eq true24 expect(body_hash).to include("token")25 expect(body_hash).to include("expires")26 expect(body_hash).to include("user")27 # ãªãã¬ãã·ã¥ãã¼ã¯ã³åå¨ãã§ãã¯28 expect(cookies).to include("refresh_token")29 # ç»é²ã¦ã¼ã¶ã¢ã¯ãã£ãåãã§ãã¯30 expect( User.find(@user.id).activated ).to eq true31 end32 end33 end34 context 'ã¢ã¯ãã£ãã¤ããã¼ã¯ã³ãä¸æ£ãªå ´å' do35 it 'ããã¼ã¯ã³æéåã[1æéå¾]ãã¨ã©ã¼ã¬ã¹ãã³ã¹ãã¤ãç»é²ã¦ã¼ã¶ã¼ãã¢ã¯ãã£ããã¦ããªããã¨' do36 headers = {37 'Authorization': "Bearer #{@activate_token}"38 }39 travel_to (1.hour.from_now) do40 put '/api/v1/users/me/activate', headers: headers41 body_hash = JSON.parse(response.body)42 aggregate_failures do43 expect(response.status).to eq 40144 expect(body_hash["success"]).to eq false45 expect(body_hash["code"]).to eq "activate_token_expired"46 expect(body_hash["messages"]).to match(["ActivateToken ã®æå¹æéåãã§ã"])47 # ç»é²ã¦ã¼ã¶ãã¢ã¯ãã£ãåãã¦ããªãããã§ãã¯48 expect( User.find(@user.id).activated ).to eq false49 end50 end51 end52 end53 end54 #################################################55 ### ã¦ã¼ã¶ã¼æ
å ±è©³ç´° åç
§56 #################################################57 describe "ã¦ã¼ã¶ã¼æ
å ±è©³ç´° åç
§ 'GET /api/v1/users/me'" do58 before do59 @user = FactoryBot.build(:user)60 @user.activated = true61 @user.save62 # ãã°ã¤ã³63 headers = {64 'Content-Type': 'application/json'65 }66 json_params = ({67 "auth": {68 "email": "aaa@abc.com",69 "password": "password"70 }71 }).to_json72 post '/api/v1/users/sessions/login', headers: headers, params: json_params73 @access_token = JSON.parse(response.body)["token"]74 end75 context 'ã¢ã¯ã»ã¹ãã¼ã¯ã³ã妥å½ãªå ´å' do76 it 'ã¬ã¹ãã³ã¹ãæ£å¸¸ãã¤ããªãã¬ãã·ã¥ãã¼ã¯ã³ã空ã§ãããã¨' do77 headers = {78 'Authorization': "Bearer #{@access_token}"79 }80 get '/api/v1/users/me', headers: headers81 body_hash = JSON.parse(response.body)82 aggregate_failures do83 # ã¬ã¹ãã³ã¹ãã§ãã¯84 expect(response.status).to eq 20085 expect(body_hash["success"]).to eq true86 # ã¦ã¼ã¶ã¼è©³ç´°æ
å ± åå¨ãã§ãã¯87 expect(body_hash).to include("user")88 end89 end90 end91 context 'ã¢ã¯ã»ã¹ãã¼ã¯ã³ãä¸æ£ãªå ´å' do92 it 'ããã¼ã¯ã³æéåã[30åå¾]ãã¨ã©ã¼ã¬ã¹ãã³ã¹ãè¿çããããã¨' do93 headers = {94 'Authorization': "Bearer #{@access_token}"95 }96 travel_to (30.minute.from_now) do97 get '/api/v1/users/me', headers: headers98 body_hash = JSON.parse(response.body)99 aggregate_failures do100 # ã¬ã¹ãã³ã¹ãã§ãã¯101 expect(response.status).to eq 401102 expect(body_hash["success"]).to eq false103 expect(body_hash["code"]).to eq "access_token_expired"104 expect(body_hash["messages"]).to match(["AccessToken ã®æå¹æéåãã§ã"])105 # ã¦ã¼ã¶ã¼è©³ç´°æ
å ± åå¨ãã§ãã¯(å«ã¾ãã¦ããªããã¨)106 expect(body_hash).not_to include("user")107 end108 end109 end110 end111 end112 #################################################113 ### ãã¹ã¯ã¼ã ãªã»ãã114 #################################################115 describe "ãã¹ã¯ã¼ã ãªã»ãã 'PUT /api/v1/users/me/password'" do116 before do117 @user = FactoryBot.build(:user)118 @user.activated = true119 @user.save120 @password_reset_token = UserAuth::PasswordResetToken.encode(@user.id).token121 end122 context 'ãã©ã¡ã¼ã¿ã¼ã妥å½ãªå ´å' do123 it 'æ£å¸¸ã¬ã¹ãã³ã¹ãè¿çããããã¨' do124 headers = {125 'Authorization': "Bearer #{@password_reset_token}",126 'Content-Type': 'application/json'127 }128 json_params = ({129 "user": {130 "password": "changed_password",131 "password_confirmation": "changed_password"132 }133 }).to_json134 put '/api/v1/users/me/password', headers: headers, params: json_params135 body_hash = JSON.parse(response.body)136 aggregate_failures do137 # ã¬ã¹ãã³ã¹ãã§ãã¯138 expect(response.status).to eq 200139 expect(body_hash["success"]).to eq true140 end141 end142 end143 context 'ãã©ã¡ã¼ã¿ã¼ãä¸æ£ãªå ´å' do144 it 'ãããã¹ã¯ã¼ã確èªããããã¹ã¯ã¼ããã¨ç¸éãã¨ã©ã¼ã¬ã¹ãã³ã¹ãè¿çããããã¨' do145 headers = {146 'Authorization': "Bearer #{@password_reset_token}",147 'Content-Type': 'application/json'148 }149 json_params = ({150 "user": {151 "password": "changed_password",152 "password_confirmation": "changed_password_bbbb" # ãã¹ã¯ã¼ãç¸é153 }154 }).to_json155 put '/api/v1/users/me/password', headers: headers, params: json_params156 body_hash = JSON.parse(response.body)157 aggregate_failures do158 # ã¬ã¹ãã³ã¹ãã§ãã¯159 expect(response.status).to eq 422160 expect(body_hash["success"]).to eq false161 body_hash["messages"].each{ |message|162 expect(message).to be_kind_of(String)163 }164 end165 end166 it 'ããã¼ã¯ã³æéåã[30åå¾]ãã¨ã©ã¼ã¬ã¹ãã³ã¹ãè¿çããããã¨' do167 headers = {168 'Authorization': "Bearer #{@password_reset_token}",169 'Content-Type': 'application/json'170 }171 json_params = ({172 "user": {173 "password": "changed_password",174 "password_confirmation": "changed_password"175 }176 }).to_json177 travel_to (30.minute.from_now) do178 put '/api/v1/users/me/password', headers: headers, params: json_params179 body_hash = JSON.parse(response.body)180 aggregate_failures do181 expect(response.status).to eq 401182 expect(body_hash["success"]).to eq false183 expect(body_hash["code"]).to eq "password_reset_token_expired"184 expect(body_hash["messages"]).to match(["PasswordResetToken ã®æå¹æéåãã§ã"])185 end186 end187 end188 end189 end190 #################################################191 ### ã¡ã¼ã«ã¢ãã¬ã¹å¤æ´ ã¨ã³ããªã¼192 #################################################193 describe "ã¡ã¼ã«ã¢ãã¬ã¹å¤æ´ ã¨ã³ããªã¼ 'POST /api/v1/users/me/email_change_entry'" do194 before do195 @user = FactoryBot.build(:user)196 @user.activated = true197 @user.save198 # ãã°ã¤ã³199 headers = {200 'Content-Type': 'application/json'201 }202 json_params = ({203 "auth": {204 "email": "aaa@abc.com",205 "password": "password"206 }207 }).to_json208 post '/api/v1/users/sessions/login', headers: headers, params: json_params209 @access_token = JSON.parse(response.body)["token"]210 end211 context 'ãã©ã¡ã¼ã¿ã¼ã妥å½ãªå ´å' do212 it 'æ£å¸¸ã¬ã¹ãã³ã¹ãè¿çããããã¨' do213 headers = {214 'Authorization': "Bearer #{@access_token}",215 'Content-Type': 'application/json'216 }217 json_params = ({218 "user": {219 "email": "aaa_change@abc.com"220 }221 }).to_json222 post '/api/v1/users/me/email_change_entry', headers: headers, params: json_params223 body_hash = JSON.parse(response.body)224 aggregate_failures do225 # ã¬ã¹ãã³ã¹ãã§ãã¯226 expect(response.status).to eq 200227 expect(body_hash["success"]).to eq true228 end229 end230 end231 context 'ãã©ã¡ã¼ã¿ã¼ãä¸æ£ãªå ´å' do232 it 'ã¨ã©ã¼ã¬ã¹ãã³ã¹ãè¿çããããã¨' do233 #å¥ã¦ã¼ã¶ã¼ç»é²234 other_user = FactoryBot.build(:user)235 other_user.email = "another@abc.com"236 other_user.activated = true237 other_user.save238 headers = {239 'Authorization': "Bearer #{@access_token}",240 'Content-Type': 'application/json'241 }242 json_params = ({243 "user": {244 "email": other_user.email # å¥ã¦ã¼ã¶ã¼ã®ã¡ã«ã¢ãæå®245 }246 }).to_json247 post '/api/v1/users/me/email_change_entry', headers: headers, params: json_params248 body_hash = JSON.parse(response.body)249 aggregate_failures do250 # ã¬ã¹ãã³ã¹ãã§ãã¯251 expect(response.status).to eq 422252 expect(body_hash["success"]).to eq false253 body_hash["messages"].each{ |message|254 expect(message).to be_kind_of(String)255 }256 end257 end258 end259 end260 #################################################261 ### ã¡ã¼ã«ã¢ãã¬ã¹å¤æ´262 #################################################263 describe "ã¡ã¼ã«ã¢ãã¬ã¹å¤æ´ 'PUT /api/v1/users/me/email'" do264 before do265 @user = FactoryBot.build(:user)266 @user.activated = true267 @user.save268 # ã¡ã«ã¢ãå¤æ´ ã¨ã³ããªã¼269 @changed_email = "changed_email@abc.com"270 @email_change_token = UserAuth::EmailChangeToken.encode(@user.id, @changed_email).token271 end272 context 'Eã¡ã¼ã«å¤æ´ãã¼ã¯ã³ã¨ãã©ã¡ã¼ã¿ã¼ï¼ãã¹ã¯ã¼ãï¼ã妥å½ãªå ´å' do273 it 'æ£å¸¸ã¬ã¹ãã³ã¹ãè¿çãããã㨠ãã¤ãå¤æ´å¯¾è±¡ã¡ã«ã¢ããåæ ããã¦ãããã¨' do274 headers = {275 'Authorization': "Bearer #{@email_change_token}",276 'Content-Type': 'application/json'277 }278 json_params = ({279 "user": {280 "password": 'password'281 }282 }).to_json283 put '/api/v1/users/me/email', headers: headers, params: json_params284 body_hash = JSON.parse(response.body)285 aggregate_failures do286 # ã¬ã¹ãã³ã¹ãã§ãã¯287 expect(response.status).to eq 200288 expect(body_hash["success"]).to eq true289 expect(body_hash).to include("token")290 expect(body_hash).to include("expires")291 expect(body_hash).to include("user")292 # ãªãã¬ãã·ã¥ãã¼ã¯ã³åå¨ãã§ãã¯293 expect(cookies).to include("refresh_token")294 # å¤æ´å¯¾è±¡ã¡ã«ã¢ããåæ ããã¦ãããã¨295 expect(User.find(@user.id).email).to eq @changed_email296 end297 end298 end299 context 'ãã©ã¡ã¼ã¿ã¼ãä¸æ£ãªå ´å' do300 it 'ããã¹ã¯ã¼ãç¸éãã¨ã©ã¼ã¬ã¹ãã³ã¹ãè¿çãããã㨠ãã¤ãå¤æ´å¯¾è±¡ã¡ã«ã¢ããåæ ããã¦ããªããã¨' do301 headers = {302 'Authorization': "Bearer #{@email_change_token}",303 'Content-Type': 'application/json'304 }305 json_params = ({306 "user": {307 "password": 'wrong_password' # ä¸æ£ãã¹ã¯ã¼ã308 }309 }).to_json310 put '/api/v1/users/me/email', headers: headers, params: json_params311 body_hash = JSON.parse(response.body)312 aggregate_failures do313 # ã¬ã¹ãã³ã¹ãã§ãã¯314 expect(response.status).to eq 401315 expect(body_hash["success"]).to eq false316 expect(body_hash["code"]).to eq "password_error"317 expect(body_hash["messages"]).to include("ãã¹ã¯ã¼ããç¸éãã¦ãã¾ã")318 # å¤æ´å¯¾è±¡ã¡ã«ã¢ããåæ ããã¦ããªããã¨319 expect(User.find(@user.id).email).to eq @user.email320 end321 end322 it 'ãå¤æ´ã¡ã«ã¢ãä¸æ£ï¼æ¢ã«åå¨ï¼ãã¨ã©ã¼ã¬ã¹ãã³ã¹ãè¿çãããã㨠ãã¤ãå¤æ´å¯¾è±¡ã¡ã«ã¢ããåæ ããã¦ããªããã¨' do323 # å¤æ´äºå®ã®ã¡ã«ã¢ãã§å¥ã¦ã¼ã¶ã¼ãæ°è¦ç»é²324 other_user = FactoryBot.build(:user)325 other_user.email = @changed_email326 other_user.activated = true327 other_user.save328 headers = {329 'Authorization': "Bearer #{@email_change_token}",330 'Content-Type': 'application/json'331 }332 json_params = ({333 "user": {334 "password": 'password'335 }336 }).to_json337 put '/api/v1/users/me/email', headers: headers, params: json_params338 body_hash = JSON.parse(response.body)339 aggregate_failures do340 # ã¬ã¹ãã³ã¹ãã§ãã¯341 expect(response.status).to eq 422342 expect(body_hash["success"]).to eq false343 expect(body_hash["code"]).to eq "unprocessable"344 expect(body_hash["messages"]).to match(["ã¡ã¼ã«ã¢ãã¬ã¹ã¯ãã§ã«åå¨ãã¾ã"])345 # å¤æ´å¯¾è±¡ã¡ã«ã¢ããåæ ããã¦ããªããã¨346 expect(User.find(@user.id).email).to eq @user.email347 end348 end349 end350 context 'Eã¡ã¼ã«å¤æ´ãã¼ã¯ã³ãä¸æ£ãªå ´å' do351 it 'ããã¼ã¯ã³æéåã[30åå¾]ãã¨ã©ã¼ã¬ã¹ãã³ã¹ãè¿çãããã㨠ãã¤ãå¤æ´å¯¾è±¡ã¡ã«ã¢ããåæ ããã¦ããªããã¨' do352 headers = {353 'Authorization': "Bearer #{@email_change_token}",354 'Content-Type': 'application/json'355 }356 json_params = ({357 "user": {358 "password": 'password'359 }360 }).to_json361 travel_to (30.minute.from_now) do362 put '/api/v1/users/me/email', headers: headers, params: json_params363 body_hash = JSON.parse(response.body)364 aggregate_failures do365 expect(response.status).to eq 401366 expect(body_hash["success"]).to eq false367 expect(body_hash["code"]).to eq "email_change_token_expired"368 expect(body_hash["messages"]).to match(["EmailChangeToken ã®æå¹æéåãã§ã"])369 # å¤æ´å¯¾è±¡ã¡ã«ã¢ããåæ ããã¦ããªããã¨370 expect(User.find(@user.id).email).to eq @user.email371 end372 end373 end374 end375 end376end...
sessions_spec.rb
Source:sessions_spec.rb
...20 "password": "password"21 }22 }).to_json23 post '/api/v1/users/sessions/login', headers: headers, params: json_params24 body_hash = JSON.parse(response.body)25 aggregate_failures do26 # ã¬ã¹ãã³ã¹ãã§ãã¯27 expect(response.status).to eq 20028 expect(body_hash["success"]).to eq true29 expect(body_hash).to include("token")30 expect(body_hash).to include("expires")31 expect(body_hash).to include("user")32 # ãªãã¬ãã·ã¥ãã¼ã¯ã³åå¨ãã§ãã¯33 expect(cookies).to include("refresh_token")34 end35 end36 end37 context 'ãã©ã¡ã¼ã¿ãä¸æ£ãªå ´å' do38 it 'ããã¹ã¯ã¼ãç¸éãã¨ã©ã¼ã¬ã¹ãã³ã¹ã®è¿çãã¤ããªãã¬ãã·ã¥ãã¼ã¯ã³ãä»ä¸ããã¦ããªããã¨' do39 headers = {40 'Content-Type': 'application/json'41 }42 json_params = ({43 "auth": {44 "email": "aaa@abc.com",45 "password": "password_bbbb" # passwordç¸é46 }47 }).to_json48 post '/api/v1/users/sessions/login', headers: headers, params: json_params49 body_hash = JSON.parse(response.body)50 aggregate_failures do51 # ã¨ã©ã¼ã¬ã¹ãã³ã¹52 expect(response.status).to eq 40153 expect(body_hash["success"]).to eq false54 expect(body_hash["code"]).to eq "authenticate_fail"55 expect(body_hash["messages"]).to match(["èªè¨¼ã«å¤±æãã¾ãã"])56 # ãªãã¬ãã·ã¥ãã¼ã¯ã³ãä»ä¸ããã¦ããªãããã§ãã¯57 expect(cookies).to_not include("refresh_token")58 end59 end60 it 'ãã¡ã«ã¢ãç¸éãã¨ã©ã¼ã¬ã¹ãã³ã¹ã®è¿çãã¤ããªãã¬ãã·ã¥ãã¼ã¯ã³ãä»ä¸ããã¦ããªããã¨' do61 headers = {62 'Content-Type': 'application/json'63 }64 json_params = ({65 "auth": {66 "email": "aaa@abc.com_bbbb", # ã¡ã«ã¢ãç¸é67 "password": "password"68 }69 }).to_json70 post '/api/v1/users/sessions/login', headers: headers, params: json_params71 body_hash = JSON.parse(response.body)72 aggregate_failures do73 # ã¨ã©ã¼ã¬ã¹ãã³ã¹74 expect(response.status).to eq 40175 expect(body_hash["success"]).to eq false76 expect(body_hash["code"]).to eq "authenticate_fail"77 expect(body_hash["messages"]).to match(["èªè¨¼ã«å¤±æãã¾ãã"])78 # ãªãã¬ãã·ã¥ãã¼ã¯ã³ãä»ä¸ããã¦ããªãããã§ãã¯79 expect(cookies).to_not include("refresh_token")80 end81 end82 end83 end84 #################################################85 ### ãã¼ã¯ã³ãªãã¬ãã·ã¥86 #################################################87 describe "ãã¼ã¯ã³ãªãã¬ãã·ã¥ 'POST /api/v1/sessions/refresh'" do88 before do89 @user = FactoryBot.build(:user)90 @user.activated = true91 @user.save92 # ãã°ã¤ã³93 headers = {94 'Content-Type': 'application/json'95 }96 json_params = ({97 "auth": {98 "email": "aaa@abc.com",99 "password": "password"100 }101 }).to_json102 post '/api/v1/users/sessions/login', headers: headers, params: json_params103 @access_token = JSON.parse(response.body)["token"]104 @refresh_token = cookies["refresh_token"]105 @before_refresh_jti = User.find(@user.id).refresh_jti106 end107 context 'ãªãã¬ãã·ã¥ãã¼ã¯ã³ã妥å½ãªå ´å' do108 it 'ã¬ã¹ãã³ã¹ãæ£å¸¸ï¼ã¢ã¯ã»ã¹ãã¼ã¯ã³ã»ãªãã¬ãã·ã¥ãã¼ã¯ã³ã®ä»ä¸ï¼ãã¤ããrefresh_jtiããæ´æ°ããããã¨' do109 headers = {110 'Cookie': "refresh_token=#{@refresh_token}"111 }112 post '/api/v1/users/sessions/refresh', headers: headers113 body_hash = JSON.parse(response.body)114 aggregate_failures do115 # ã¬ã¹ãã³ã¹ãã§ãã¯116 expect(response.status).to eq 200117 expect(body_hash["success"]).to eq true118 expect(body_hash).to include("token")119 expect(body_hash).to include("expires")120 expect(body_hash).to include("user")121 # ãªãã¬ãã·ã¥ãã¼ã¯ã³åå¨ãã§ãã¯122 expect(cookies["refresh_token"]).not_to be_empty123 # refresh_jtiã®æ´æ°ãã§ãã¯124 after_refresh_jti = User.find(@user.id).refresh_jti125 expect(after_refresh_jti).not_to eq @before_refresh_jti126 end127 end128 end129 context 'ãªãã¬ãã·ã¥ãã¼ã¯ã³ãä¸æ£ãªå ´å' do130 it 'ããã¼ã¯ã³æéåã[24æéå¾]ããªãã¬ãã·ã¥ãã¼ã¯ã³ãä»ä¸ããã¦ããªããã¨ãããã³ãrefresh_jtiããæ´æ°ãããªããã¨' do131 headers = {132 'Cookie': "refresh_token=#{@refresh_token}"133 }134 travel_to (24.hour.from_now) do135 post '/api/v1/users/sessions/refresh', headers: headers136 body_hash = JSON.parse(response.body)137 aggregate_failures do138 # ã¬ã¹ãã³ã¹ãã§ãã¯139 expect(response.status).to eq 401140 expect(body_hash["success"]).to eq false141 expect(body_hash["code"]).to eq "refresh_token_expired"142 expect(body_hash["messages"]).to match(["RefreshToken ã®æå¹æéåãã§ã"])143 # ãªãã¬ãã·ã¥ãã¼ã¯ã³ã空ã¨ãªã£ã¦ããããã§ãã¯144 expect(cookies["refresh_token"]).to be_empty145 # refresh_jtiã®æ´æ°ãã§ãã¯146 after_refresh_jti = User.find(@user.id).refresh_jti147 expect(after_refresh_jti).to eq @before_refresh_jti148 end149 end150 end151 end152 end153 #################################################154 ### ãã°ã¢ã¦ã155 #################################################156 describe "ãã°ã¢ã¦ã 'DELETE /api/v1/sessions/logout'" do157 before do158 @user = FactoryBot.build(:user)159 @user.activated = true160 @user.save161 # ãã°ã¤ã³162 headers = {163 'Content-Type': 'application/json'164 }165 json_params = ({166 "auth": {167 "email": "aaa@abc.com",168 "password": "password"169 }170 }).to_json171 post '/api/v1/users/sessions/login', headers: headers, params: json_params172 @access_token = JSON.parse(response.body)["token"]173 @refresh_token = cookies["refresh_token"]174 @before_refresh_jti = User.find(@user.id).refresh_jti175 end176 context 'ãªãã¬ãã·ã¥ãã¼ã¯ã³ã妥å½ãªå ´å' do177 it 'ã¬ã¹ãã³ã¹ãæ£å¸¸ãã¤ããªãã¬ãã·ã¥ãã¼ã¯ã³ã空ã§ãããã¨' do178 headers = {179 'Cookie': "refresh_token=#{@refresh_token}"180 }181 delete '/api/v1/users/sessions/logout', headers: headers182 body_hash = JSON.parse(response.body)183 aggregate_failures do184 # ã¬ã¹ãã³ã¹ãã§ãã¯185 expect(response.status).to eq 200186 expect(body_hash["success"]).to eq true187 # ãªãã¬ãã·ã¥ãã¼ã¯ã³åå¨ãã§ãã¯188 expect(cookies["refresh_token"]).to be_empty189 # refresh_jtiã®åé¤ãã§ãã¯190 after_refresh_jti = User.find(@user.id).refresh_jti191 empty_hash = {}192 expect(after_refresh_jti).to eq empty_hash193 end194 end195 end196 context 'ãªãã¬ãã·ã¥ãã¼ã¯ã³ãä¸æ£ãªå ´å' do197 it 'ããã¼ã¯ã³æéåã[24æéå¾]ãã¨ã©ã¼ã¬ã¹ãã³ã¹ã®è¿çãã¤ããªãã¬ãã·ã¥ãã¼ã¯ã³ã空ã§ãããã¨' do198 headers = {199 'Cookie': "refresh_token=#{@refresh_token}"200 }201 travel_to (24.hour.from_now) do202 post '/api/v1/users/sessions/refresh', headers: headers203 body_hash = JSON.parse(response.body)204 aggregate_failures do205 # ã¬ã¹ãã³ã¹ãã§ãã¯206 expect(response.status).to eq 401207 expect(body_hash["success"]).to eq false208 expect(body_hash["code"]).to eq "refresh_token_expired"209 expect(body_hash["messages"]).to match(["RefreshToken ã®æå¹æéåãã§ã"])210 # ãªãã¬ãã·ã¥ãã¼ã¯ã³ã空ã¨ãªã£ã¦ããããã§ãã¯211 expect(cookies["refresh_token"]).to be_empty212 # refresh_jtiãåé¤ããã¦ããªãããã§ãã¯ï¼ååã¨åãrefresh_jtiï¼213 after_refresh_jti = User.find(@user.id).refresh_jti214 expect(after_refresh_jti).to eq @before_refresh_jti215 end216 end217 end218 end219 end220end...
product_api_spec.rb
Source:product_api_spec.rb
...4 def app5 ProductApi6 end7 context 'get product information successful' do8 let(:body_hash) { JSON.parse(last_response.body, symbolize_names: true) }9 let(:products) do10 [11 { id: 1, name: 'Docker In Action', price: '59.00', _links: { self: { href: 'http://example.org/products/1' } } },12 { id: 2, name: 'Agile In Action', price: '55.00', _links: { self: { href: 'http://example.org/products/2' } } }13 ]14 end15 describe 'all products' do16 subject { get '/products' }17 it 'returns a link for itself' do18 subject19 expect(body_hash[:_links][:self][:href]).to eq 'http://example.org/products'20 end21 it 'should return product list' do22 subject23 expect(body_hash[:_embedded][:products]).to eq products24 end25 end26 describe 'one product' do27 subject { get '/products/1' }28 it 'should return Docker In Action product' do29 subject30 expect(body_hash[:id]).to eq 131 expect(body_hash[:name]).to eq 'Docker In Action'32 expect(body_hash[:price]).to eq '59.00'33 end34 end35 end36 context 'get product information unsuccessful' do37 let(:body_hash) { JSON.parse(last_response.body, symbolize_names: true) }38 describe 'have some exceptions' do39 before do40 allow(ProductRepository).to receive(:find).and_raise(StandardError, 'there is some error.')41 end42 subject { get '/products/1' }43 it 'logs error and info' do44 subject45 expect(body_hash[:title]).to eq('there is some error.')46 expect(last_response.headers['Content-Type']).to eq('application/problem+json')47 end48 end49 end50end...
body_hash
Using AI Code Generation
1 JSON.parse(self.body)2response = RestClient.get(url)3 JSON.parse(self.body)4response = RestClient.get(url)5 JSON.parse(self.body)
body_hash
Using AI Code Generation
1curl -X POST -d "{\"post\": \"post\"}" http://localhost:4567/post2curl -X PUT -d "{\"put\": \"put\"}" http://localhost:4567/put3curl -X DELETE -d "{\"delete\": \"delete\"}" http://localhost:4567/delete4curl -X PATCH -d "{\"patch\": \"patch\"}" http://localhost:4567/patch5{"post":"post"}6{"put":"put"}7{"delete":"delete"}8{"patch":"patch"}
body_hash
Using AI Code Generation
1uri = URI('http://localhost:8080/body_hash')2http = Net::HTTP.new(uri.host, uri.port)3request = Net::HTTP::Post.new(uri.request_uri)4request.body = {5}.to_json6response = http.request(request)7{"name":"John","age":20}8uri = URI('http://localhost:8080/body')9http = Net::HTTP.new(uri.host, uri.port)10request = Net::HTTP::Post.new(uri.request_uri)11request.body = {12}.to_json13response = http.request(request)14{"name":"John","age":20}
body_hash
Using AI Code Generation
1context = Open.open("http://localhost:4567/context", :body_hash => {:method => "get", :params => {:id => "Cytoscape"}})2context = Open.open("http://localhost:4567/context", :body_hash => {:method => "get", :params => {:id => "Cytoscape", :key => "Cytoscape"}})3context = Open.open("http://localhost:4567/context", :body_hash => {:method => "get", :params => {:id => "Cytoscape", :key => "Cytoscape", :value => "Cytoscape"}})4context = Open.open("http://localhost:4567/context", :body_hash => {:method => "get", :params => {:id => "Cytoscape", :key => "Cytoscape", :value => "Cytoscape", :extra => "Cytoscape"}})5context = Open.open("http://localhost:4567/context", :body_hash => {:method => "get", :params => {:id => "Cytoscape", :key => "Cytoscape", :value => "Cytoscape", :extra => "Cytoscape", :extra2 => "Cytoscape"}})6context = Open.open("http://localhost:4567/context", :body_hash => {:method => "get", :params => {:id => "Cytoscape", :key => "Cytoscape", :value => "Cytoscape", :extra => "Cytoscape", :extra2 => "Cytoscape", :extra3 => "Cytoscape"}})7context = Open.open("http://localhost:4567/context", :body_hash => {:method => "get", :params => {:id => "Cytoscape", :key => "Cytoscape", :value => "Cytoscape", :extra => "Cytoscape", :extra2 => "Cytoscape", :extra3
body_hash
Using AI Code Generation
1 JSON.parse(response.body)2 response = RestClient.get('https://api.github.com/users/username')3 response = RestClient.get('https://api.github.com/users/username')4 expect(context.body_hash['login']).to eq 'username'5 response = RestClient.get('https://api.github.com/users/username')6 expect(context.body_hash['login']).to eq 'username'7 expect(context.body_hash['id']).to eq 1234567898 response = RestClient.get('https://api.github.com/users/username')9 expect(context.body_hash['login']).to eq 'username'10 expect(context.body_hash['id']).to eq 12345678911 expect(context.body_hash['node_id']).to eq 'MDQ6VXNlcjEyMzQ1Njc4OQ=='12 response = RestClient.get('https://
body_hash
Using AI Code Generation
1{"post":"post"}2{"put":"put"}3{"delete":"delete"}4{"patch":"patch"}
body_hash
Using AI Code Generation
1uri = URI('http://localhost:8080/body_hash')2http = Net::HTTP.new(uri.host, uri.port)3request = Net::HTTP::Post.new(uri.request_uri)4request.body = {5}.to_json6response = http.request(request)7{"name":"John","age":20}8uri = URI('http://localhost:8080/body')9http = Net::HTTP.new(uri.host, uri.port)10request = Net::HTTP::Post.new(uri.request_uri)11request.body = {12}.to_json13response = http.request(request)14{"name":"John","age":20}
body_hash
Using AI Code Generation
1 JSON.parse(response.body)2 response = RestClient.get('https://api.github.com/users/username')3 response = RestClient.get('https://api.github.com/users/username')4 expect(context.body_hash['login']).to eq 'username'5 response = RestClient.get('https://api.github.com/users/username')6 expect(context.body_hash['login']).to eq 'username'7 expect(context.body_hash['id']).to eq 1234567898 response = RestClient.get('https://api.github.com/users/username')9 expect(context.body_hash['login']).to eq 'username'10 expect(context.body_hash['id']).to eq 12345678911 expect(context.body_hash['node_id']).to eq 'MDQ6VXNlcjEyMzQ1Njc4OQ=='12 response = RestClient.get('https://
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!