[rspec-users] Speccing a model class method in Rails produces nil

Martin Hawkins martin.hawkins at gmail.com
Fri Dec 3 12:07:19 EST 2010


Ruby 1.9.2, Rails 3.0.3, Rspec-rails 2.2.0

I have:

Factory.define :season_date do |f|
  f.season_date Date.new(2011,9,24)
  f.date_type "season_start"
end

RSpec.configure do |config|
  config.mock_with :rspec
end

Factory.define :season_date do |f|
  f.season_date Date.new(2011,9,24)
  f.date_type "season_start"
end

Factory.define :season_date do |f|
  f.season_date Date.new(2011,9,24)
  f.date_type "season_start"
end

require 'spec_helper'
describe SeasonDate do
  before(:each) do
    @start_date_record = Factory.create(:season_date)
    @no_play_date_record = Factory.create(:season_date, season_date:
Date.today, date_type: "no_play")
  end
  it "responds to the find_start_record method call" do
    SeasonDate.should respond_to(:find_start_record)
  end
  it "returns the record with the season start date" do
    SeasonDate.find_start_record.should == @start_date_record
  end
end

and I get

rspec -f d -b spec/models/season_date_spec.rb
SeasonDate
  responds to the find_start_record method call
  returns the record with the season start date (FAILED - 1)

Failures:

  1) SeasonDate returns the record with the season start date
     Failure/Error: SeasonDate.find_start_record.should ==
@start_date_record
     expected: #<SeasonDate id: 66, season_date: "2011-09-24",
date_type: "season_start", created_at: "2010-12-03 17:03:58",
updated_at: "2010-12-03 17:03:58">,
          got: nil (using ==)

I'm doing something dumb, but I don't know what. Any assistance much
appreciated!



More information about the rspec-users mailing list