Martin Hawkins
2010-Dec-03 17:07 UTC
[rspec-users] Speccing a model class method in Rails produces nil
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!
David Chelimsky
2010-Dec-04 02:25 UTC
[rspec-users] Speccing a model class method in Rails produces nil
On Dec 3, 2010, at 11:07 AM, Martin Hawkins wrote:> 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" > endDo you actually have 3 identical factories or was that just a copy/paste error?> 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_recordThe fact that this example ^^ sends SeasonDate the find_start_record message makes the previous example unnecessary.> 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!Can''t really tell from what you''ve posted. Please post the implementation of SeasonDate.season_date.
Martin Hawkins
2010-Dec-04 14:34 UTC
[rspec-users] Speccing a model class method in Rails produces nil
I can''t believe I did that... No, there is only one Factory; copy and paste error. The SeasonDate class is: class SeasonDate < ActiveRecord::Base def self.find_start_record where(["date_type = ?", "start_date"]).first end end Agreed regarding the redundant test - I just put that in when things went wrong. Thanks for responding On Dec 4, 2:25?am, David Chelimsky <dchelim... at gmail.com> wrote:> On Dec 3, 2010, at 11:07 AM, Martin Hawkins wrote: > > > > > > > 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 > > Do you actually have 3 identical factories or was that just a copy/paste error? > > > 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 > > The fact that this example ^^ sends SeasonDate the find_start_record message makes the previous example unnecessary. > > > > > > > ?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! > > Can''t really tell from what you''ve posted. Please post the implementation of SeasonDate.season_date. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
Martin Hawkins
2010-Dec-04 14:58 UTC
[rspec-users] Speccing a model class method in Rails produces nil
Apologies if this is a repeat post but google seemed to ignore my last effort. There is only one Factory - copy, paste and editing error. I can''t believe that I didn''t include the code being tested... class SeasonDate < ActiveRecord::Base def self.find_start_record where(["date_type = ?", "start_date"]).first end end Agreed re redundant test - I put that in when the ''real'' test failed. On Dec 4, 2:25?am, David Chelimsky <dchelim... at gmail.com> wrote:> On Dec 3, 2010, at 11:07 AM, Martin Hawkins wrote: > > > > > > > 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 > > Do you actually have 3 identical factories or was that just a copy/paste error? > > > 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 > > The fact that this example ^^ sends SeasonDate the find_start_record message makes the previous example unnecessary. > > > > > > > ?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! > > Can''t really tell from what you''ve posted. Please post the implementation of SeasonDate.season_date. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
David Chelimsky
2010-Dec-04 16:04 UTC
[rspec-users] Speccing a model class method in Rails produces nil
On Sat, Dec 4, 2010 at 8:34 AM, Martin Hawkins <martin.hawkins at gmail.com> wrote:> I can''t believe I did that... > No, there is only one Factory; copy and paste error. The SeasonDate > class is: > class SeasonDate < ActiveRecord::Base > ?def self.find_start_record > ? ?where(["date_type = ?", "start_date"]).firstI think the problem is "start_date" vs "season_start". The factory says: Factory.define :season_date do |f| f.season_date Date.new(2011,9,24) f.date_type "season_start" end date_type == "start_date" # in the implementation date_type == "season_start" # in the factory HTH, David> ?end > end > Agreed regarding the redundant test - I just put that in when things > went wrong. > Thanks for responding > > On Dec 4, 2:25?am, David Chelimsky <dchelim... at gmail.com> wrote: >> On Dec 3, 2010, at 11:07 AM, Martin Hawkins wrote: >> >> >> >> >> >> > 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 >> >> Do you actually have 3 identical factories or was that just a copy/paste error? >> >> > 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 >> >> The fact that this example ^^ sends SeasonDate the find_start_record message makes the previous example unnecessary. >> >> >> >> >> >> > ?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! >> >> Can''t really tell from what you''ve posted. Please post the implementation of SeasonDate.season_date. >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Martin Hawkins
2010-Dec-04 18:33 UTC
[rspec-users] Speccing a model class method in Rails produces nil
I can''t believe I did that either... Doh! On Dec 4, 4:04?pm, David Chelimsky <dchelim... at gmail.com> wrote:> On Sat, Dec 4, 2010 at 8:34 AM, Martin Hawkins <martin.hawk... at gmail.com> wrote: > > I can''t believe I did that... > > No, there is only one Factory; copy and paste error. The SeasonDate > > class is: > > class SeasonDate < ActiveRecord::Base > > ?def self.find_start_record > > ? ?where(["date_type = ?", "start_date"]).first > > I think the problem is "start_date" vs "season_start". The factory says: > > Factory.define :season_date do |f| > ?f.season_date Date.new(2011,9,24) > ?f.date_type "season_start" > end > > date_type == "start_date" # in the implementation > date_type == "season_start" # in the factory > > HTH, > David > > > > > > > ?end > > end > > Agreed regarding the redundant test - I just put that in when things > > went wrong. > > Thanks for responding > > > On Dec 4, 2:25?am, David Chelimsky <dchelim... at gmail.com> wrote: > >> On Dec 3, 2010, at 11:07 AM, Martin Hawkins wrote: > > >> > 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 > > >> Do you actually have 3 identical factories or was that just a copy/paste error? > > >> > 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 > > >> The fact that this example ^^ sends SeasonDate the find_start_record message makes the previous example unnecessary. > > >> > ?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! > > >> Can''t really tell from what you''ve posted. Please post the implementation of SeasonDate.season_date. > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users