와 validate_uniqueness_of :RSpec에, 했어야, 내가 RSpec에 테스트 다음 한 범위와 잘못된 오류 메시지
describe Productlimit do
before(:each) do
@productlimit = Factory.create(:productlimit, :user => Factory.create(:user))
end
subject { @productlimit }
...
it { should validate_uniqueness_of(:price_cents).scoped_to(:direction_down, :currency, :market_id, :user_id) }
...
end
하지만 혼란 오류 다음 얻을 :
1) Productlimit
Failure/Error: it { should validate_uniqueness_of(:price_cents).scoped_to(:direction_down, :currency, :market_id, :user_id) }
Expected errors to include "has already been taken" when price_cents is set to 9530, got errors: ["direction_down has already been taken (false)"]
당신이 날 도와 줄 수 있습니까? 오류 메시지가 올바른 것 같아서 이것이 왜 작동하지 않는지 이해할 수 없습니까?
편집 :
이뿐만 아니라 다른 상황에서 너무 발생합니다
# product_spec.rb
...
it { should validate_numericality_of(:price).with_message("price_cents must be greater than 0 (0)") }
# rake spec:models
Failure/Error: it { should validate_numericality_of(:price).with_message("price_cents must be greater than 0 (0)") }
Expected errors to include "price_cents must be greater than 0 (0)" when price is set to "abcd", got errors: ["price_cents must be greater than 0 (0)"]
당신은 shoulda/rspec의 어떤 버전을 사용하고 있습니까? – nathanvda
나는 shoulda-matchers (1.0.0.beta2)를 가지고 있지만, 현재 'shoulda'보석으로도 시험해 보았습니다. – Lichtamberg
레일이 이미 시험하고있는 것을 시험하고있는 것처럼 보입니다. 모델에 validate_numericality가있는 경우 테스트에서 호출하는 이유는 무엇입니까? 그것은 불필요한 중복입니다. – corroded