Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rspec设置问题_Ruby On Rails_Ruby_Rspec_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails Rspec设置问题

Ruby on rails Rspec设置问题,ruby-on-rails,ruby,rspec,ruby-on-rails-4,Ruby On Rails,Ruby,Rspec,Ruby On Rails 4,我的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/

我的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)>'
13)事件关联应该有多个:作业
失败/错误:它{应该有_许多:作业}
命名错误:
未定义的方法'has_many'#
#./spec/models/event_spec.rb:14:in'block(3层)in'
8) 事件验证
失败/错误:它{应该验证是否存在:开始日期}
命名错误:
未定义的方法“验证是否存在”#
#./spec/models/event_spec.rb:7:in'block(3层)in'

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

编辑

Event.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
class事件
您需要在
测试
组中添加
shoulda matchers

group :test do
  gem 'shoulda-matchers'
end

如果您显示导致错误的代码,这将更有帮助。i、 e.事件规格。rb@Dty补充!看一看,谢谢你在用Shoulda吗?如果是,请将此gem包含在所需匹配器中: