Ruby On Rails (25) 썸네일형 리스트형 guard 특징 1. guard 란? 파일이 변경되었을 때, 그것을 감지하여 자동으로 테스트 명령어를 실행시켜주는 gem입니다. 2. Guardfile controller path, view path, model, service 등의 Path가 실제 패스와 매칭이 되어서 그 값을 자동적으로 테스트를 진행시켜줍니다. 만약 매칭이 잘 안된다면 직접 추가를 해주면 됩니다. spring 특징 1. spring 이란? preload all libraries reload all files 2. spring 장점 a default part of rails, so you know it’s well supported, and bugs will be fixed fast. slightly simpler to install and use than Zeus 3. spring 단점 Spring lacks support for parallel tests a bit opaque in terms of errors given there’s no console window 4. spring 서버에 문제가 생긴다면? bundle exec spring stop rspec으로 test를 하면 자동으로 재시작해준다. bund.. System vs Feature vs Request spec 통합 테스트로 어떤 spec을 선택할지 고민하려고 이 내용을 정리하였다. 내가 선택한 spec은 feature spec이고, 선택한 가장 큰 이유는 안정성이다. 1. System spec 가장 핵심은 Third Party Extension 이 필요 없다. 즉, 설정을 최소화할 수 있다는 것을 거듭 강조함. 공식적으로 RSpec 팀이 추천하는 통합 테스트 내부적으로 다 settings이 되어있으므로, selenium driver 와 chrome browser 가 디폴트이다. 2017년 10월쯤에 나와서 얼마안됨. 쌓인 데이터가 얼마 없음 2. Feature spec capybara, databaseCleaner settings를 해줘야만 한다. 오랫동안 rspec 통합 테스트 많이 사용되어왔음, 즉, 기술.. Rails 서버 종료 1. 일반적인 방법 1) control + c 2. 강제 종료 1) control + z 2) lsof -wni tcp:3000 3) kill -9 PID 문자열 예외처리 API 작업을 하다 보면 숫자만 입력받아야 하는 상황들이 있다. 문자열에 대해서 입력을 받으면 안 되는 상황들에서 예외처리를 어떻게 해야 하는지 알아보자. 1. 처리 1 cnt = parmas[:cnt].to_i cnt == 0 '' '0' 'string' 즉, 공백, 0, 문자열을 모두 0으로 처리해준다. 그래서 정확한 예외처리를 해줄 수 없다. 2. 처리 2 def count cnt = params[:cnt] cnt_list = params[:cnt].bytes raise ApiExceptions::CustomException.new(:status, 'error message')) if cnt.to_i == 0 && cnt_list.size > 0 && (cnt_list.map { |v| v < 48.. rspec reference 정리 1. better specs, rspec-expectations, rspec-mocks, rspec-core, rspec-rails www.betterspecs.org/ Better Specs. Testing Guidelines for Developers. Better Specs is a collection of best practices developers learned while testing apps that you can use to improve your coding skills, or simply for inspiration. Better Specs came to life at Lelylan (open source IoT cloud platform) and checking out its tes.. 나머지 스펙과 디버그에 대한 이야기 안녕하세요. 다루지 않은 나머지 스펙들과 디버그에 대해 설명하겠습니다. 1. request spec, view spec,, etc 1) service spec을 제외한 spec(model spec 포함)에서는 복잡한 로직을 다루지 않기 때문에 let()을 활용해서 사용하려는 가장 객체를 생성해 그 값을 저장하고 테스트를 진행하시면 되겠습니다. 2) request spec a. request spec은 controller spec이라고 생각하셔도 무방합니다. b. status code, redirection, text in the response body 등을 확인할 때 쓰입니다. c. 테스트하고자 하는 경로의 상태코드를 확인하는데 유용합니다. 2. debug 1) byebug 2) feature spec.. model spec 작성방법 안녕하세요. 이번에는 model spec에 대해 알아보겠습니다. 1. model spec 이란? 1) RSpec reference 뿐만 아니라 shoulda-matchers reference도 참고를 해서 작성을 해주시면 됩니다. 2) associations 에 대한 테스트 코드는 작성할 필요가 없다고 합니다. a. 왜냐하면 association에 대한 테스트는 model 안에서 작은 테스트가 아니라 통합 테스트 단계에서 테스트가 될 것이기 때문에 가치가 없다고 합니다. 3) 인스턴스 변수에 대한 validation은 아래와 같이 작성을 해주시면 되겠습니다. 2. 작성방법 RSpec.describe RetailStore, type: :model do let(:retail_store) { build(:re.. 이전 1 2 3 4 다음