위의 짧은 질문, 아래의 자세한 내용 (대부분 불필요하지만 유용한 것으로 생각됩니다). 나는 새로운 것을 지키고 상대적으로 레일스에 익숙하지 않지만, (rspec을 사용하여) 가드가 올바르게 작동하는 잘 작동하는 레일 프로젝트를 설정했다. 가장 중요한 점은 가드와 커스텀 로거가 완벽하게 작동하고 예상대로 작동하지만 로거가 활성화되면 로거가 깨지기 때문입니다.가드 테스트를 깨지 않고 커스텀 로거를 정의하는 방법은 무엇입니까?
세부 사항은 다음과 같습니다 나는 사용자 지정과 같이 로거 정의하는 경우 : 내 설정이 필요한 경우 등 "/lib/assets/my_logger.rb"
로 파일에
logfile = File.open("#{Rails.root}/log/my.log", 'a')
logfile.sync=true
MY_LOGGER = Logger.new(logfile)
를/그래서 같은 development.rb 파일 : 나는 거기에 그것을 넣어
require "assets/my_logger"
가 나는 그러나 곧, 내 컨트롤러의에서이 로거를 사용할 수 있습니다, 예를 들어,
class SessionsController < ApplicationController
def new
end
def create
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_back_or user
else
flash.now[:error] = 'Invalid email/password combination'
render 'new'
MY_LOGGER.info "this will break guard tests"
end
end
def destroy
sign_out
redirect_to root_url
end
end
그런 다음 컨트롤러에서이 조치에 따라 내 가드 테스트는 중단됩니다 (MY_LOGGER 라인 위의 주석으로)
:
16:56:33 - INFO - Running: spec/requests/authentication_pages_spec.rb
Running tests with args ["--drb", "-f", "progress", "-r", "/Users/crashandburn4/.rvm/gems/ruby-2.0.0-p0/gems/guard-rspec-2.5.0/lib/guard/rspec/formatter.rb", "-f", "Guard::RSpec::Formatter", "--failure-exit-code", "2", "spec/requests/authentication_pages_spec.rb"]...
..................
Finished in 1.61 seconds
18 examples, 0 failures
(장소에 라인)
16:56:19 - INFO - Running: spec/requests/authentication_pages_spec.rb
Running tests with args ["--drb", "-f", "progress", "-r", "/Users/crashandburn4/.rvm/gems/ruby-2.0.0-p0/gems/guard-rspec-2.5.0/lib/guard/rspec/formatter.rb", "-f", "Guard::RSpec::Formatter", "--failure-exit-code", "2", "spec/requests/authentication_pages_spec.rb"]...
..FFF.............
Failures:
1) Authentication signin with invalid information
Failure/Error: it { should have_title('Sign in') }
expected #has_title?("Sign in") to return true, got false
# ./spec/requests/authentication_pages_spec.rb:20:in `block (4 levels) in <top (required)>'
2) Authentication signin with invalid information
Failure/Error: it { should have_selector('div.alert.alert-error', text: 'Invalid') }
expected #has_selector?("div.alert.alert-error", {:text=>"Invalid"}) to return true, got false
# ./spec/requests/authentication_pages_spec.rb:21:in `block (4 levels) in <top (required)>'
3) Authentication signin with invalid information after visiting another page
Failure/Error: before { click_link "Home" }
Capybara::ElementNotFound:
Unable to find link "Home"
# ./spec/requests/authentication_pages_spec.rb:23:in `block (5 levels) in <top (required)>'
Finished in 1.62 seconds
18 examples, 3 failures
Failed examples:
rspec ./spec/requests/authentication_pages_spec.rb:20 # Authentication signin with invalid information
rspec ./spec/requests/authentication_pages_spec.rb:21 # Authentication signin with invalid information
rspec ./spec/requests/authentication_pages_spec.rb:24 # Authentication signin with invalid information after visiting another page
(불필요한 스택 트레이스에 대한 사과)
이제 guard github 페이지를 둘러 보았지만 사용자 정의 로거를 사용하도록 설정하는 방법에 대해서는 아무 것도 찾을 수 없으므로 가드에 의해 무시됩니다.이를 수행하는 방법을 알고 있습니까?
Perfect. 도와 주셔서 감사합니다! –