gpt4 book ai didi

ruby-on-rails - Rspec 设置问题

转载 作者:数据小太阳 更新时间:2023-10-29 07:52:49 25 4
gpt4 key购买 nike

我的 rspec 设置有问题,但我不确定是什么,所有规范都按正常方式编写,但没有按预期运行。

例如,

13) Event associations should have many :jobs
Failure/Error: it { should have_many :jobs }
NoMethodError:
undefined method `has_many?' for #<Event:0x007ffdb0140978>
# ./spec/models/event_spec.rb:14:in `block (3 levels) in <top (required)>'


8) Event validations
Failure/Error: it { should validate_presence_of :start_date }
NoMethodError:
undefined method `validate_presence_of' for #<RSpec::ExampleGroups::Event_2::Validations:0x007ffdb02a1268>
# ./spec/models/event_spec.rb:7:in `block (3 levels) in <top (required)>'

Gist for Gemfile

Pastie for Spec Helper

我正在做 TDD,所以在启动并运行之前无法真正开始,请有人提供帮助!

编辑

事件.rb

class Event < ActiveRecord::Base
validates_presence_of :start_date, :end_date, :description, :title

has_many :jobs
has_many :applications, through: :jobs
has_many :users, through: :applications
has_many :companies, through: :jobs
end

require 'spec_helper'

describe Event do
context "validations" do
it { should validate_presence_of :title }
it { should validate_presence_of :description }
it { should validate_presence_of :start_date }
it { should validate_presence_of :end_date }
end

context "associations" do
it { should have_many :companies }

it { should have_many :jobs }
it { should have_many(:applications).through(:jobs) }
it { should have_many(:users).through(:applications) }
end

context "custom methods" do

end
end

最佳答案

您需要在test 组中添加shoulda-matchers

group :test do
gem 'shoulda-matchers'
end

关于ruby-on-rails - Rspec 设置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22588805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com