RSpec을 사용하여 모델 간의 내 관계를 테스트하려고합니다. 클래스를 통해와RSpec 3.1.0에 문제가 있고 has_many with Ruby-on-Rails 4.1
class User < ActiveRecord::Base
has_many :user_roles
has_many :roles, through: :user_roles
end
및
class Role < ActiveRecord::Base
has_many :user_roles
has_many :users, through: :user_roles
end
: 나는 두 가지 모델이
class UserRole < ActiveRecord::Base
belongs_to :user
belongs_to :role
end
내 RSpec에 코드 것은 이러한 던져 오류의
describe User do
it { is_expected.to have_many(:user_roles) }
it { is_expected.to have_many(:roles).through(:user_roles) }
end
모두 :
user_roles 장애/오류 :1) 사용자가 많은 있어야한다 {have_many (is_expected.to : user_roles)}이 예상 #이 has_many?
#의 ./spec/models/user_spec.rb:49:in`에 응답 블록 (2 단계) '
2) 사용자 장애/오류 : 그것은 {have_many (is_expected.to : 역할) .through (: user_roles)} NoMethodError : 정의되지 않은 메서드 through' for #<RSpec::Matchers::BuiltIn::Has:0x007fe1cd003ac8> # ./spec/models/user_spec.rb:50:in
블록 (2 단계)에서'
내가 무엇을 시도하든 상관없이 나는 이들을 작동시키지 못하는 것 같습니다. 누구든지 내가 뭘 잘못하고 있는지 알아?
도움 주셔서 감사합니다.