Rspec设置问题

时间:2014-03-23 08:55:09

标签: 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/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所以在这个启动并运行之前无法真正开始,请提供帮助!

修改

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

1 个答案:

答案 0 :(得分:5)

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

group :test do
  gem 'shoulda-matchers'
end