2014-10-08 8 views
1

위와 아래 득표를 확인하기 위해 스펙을 만들었지 만, 전체 파일을 테스트했을 때 마지막 메소드 (down_votes)에서는 실패하지만, 하나씩 점검 할 때는 모두 통과합니다. before 메서드를 사용하여 @user, @ post를 인스턴스화하고 사용자를 서명하고 요청 환경을 설정합니다.#down_votes methods

여기 내 사양 아래에있다 :

require 'rails_helper' 

describe VotesController do 

include TestFactories 
include Devise::TestHelpers 

before do 
    request.env["HTTP_REFERER"] = '/' 
    @user = authenticated_user 
    @post = associated_post 
    sign_in @user 
end 

describe '#up_vote' do 
    it "adds an up-vote to the post" do 

    expect { 
     post(:up_vote, post_id: @post.id) 
    }.to change{ @post.up_votes }.by 1 
    end 
end 

describe '#down_vote' do 
    it "adds an down-vote to the post" do 

    expect { 
     post(:down_vote, post_id: @post.id) 
    }.to change{ @post.down_votes }.by -1 
    end 
end 

end 

답변

0
}.to change{ @post.down_votes }.by -1 

은 양의 정수 사용하는 그 라인을 개정 해보십시오 :

}.to change{ @post.down_votes }.by 1 

합니다 (down_votes 방법을 가정 모두의 총 수 있어야하는데 다운 득표).

+0

좋습니다 ... 알았어요. 나는 부정적인 가치를 전달하는 것에 대해 생각해 보았습니다. –