Я пытаюсь рельсы развить отдых api. Я использую rspec и shoulda-matchers. Проблема в том, что один из моих тестов всегда терпит неудачу.Как пройти тест Rspec has_many? [Shoulda-matchers]
Как я могу исправить свой код, поэтому тест проходит (ЗЕЛЕНЫЙ).
user.rb
class User < ActiveRecord::Base
has_many :cards
end
card.rb
class Card < ActiveRecord::Base
belongs_to :user
end
user_spec.rb
require 'rails_helper'
RSpec.describe User, type: :model do
before { @user = FactoryGirl.create(:user) }
subject{ @user }
# Columns
it { should respond_to :name }
# Associations
it { should have_many :cards }
end
Gemfile
source 'https://rubygems.org'
gem 'rails', '4.2.0'
gem 'rails-api'
gem 'spring', :group => :development
gem 'sqlite3'
group :development, :test do
gem 'factory_girl_rails'
gem 'rspec-rails', '~> 3.0'
gem 'shoulda-matchers', '~> 3.0'
end
Терминал
➜ my_api rspec spec/models/user_spec.rb
.F
Failures:
1) User should have many :cards
Failure/Error: it { should have_many :cards }
expected #<User:0x007f897ce0c0d8> to respond to `has_many?`
# ./spec/models/user_spec.rb:12:in `block (2 levels) in <top (required)>'
Finished in 0.04623 seconds (files took 2.45 seconds to load)
2 examples, 1 failure
Failed examples:
rspec ./spec/models/user_spec.rb:12 # User should have many :cards