Louise Rains
2008-Jul-09 22:24 UTC
Unit test patterned after AWDR p. 186 doesn''t work as expect
I have the following Ruby migration: class CreateSimulations < ActiveRecord::Migration def self.up create_table :simulations do |t| t.string :name, :desc, :time_units t.column :run_length, :float t.timestamps end end def self.down drop_table :simulations end end My class has the following validations: class Simulation < ActiveRecord::Base validates_uniqueness_of :name validates_numericality_of :run_length validates_inclusion_of :time_units, :in => %w{sec min hr days}, :message => "should be ''sec'', ''min'', ''hr'', ''days''" validates_presence_of :name, :time_units, :run_length end My unit test looks like this: def test_unique_name sim1 = Simulation.new( :name => "base", :run_length => 84600, :time_units =>"sec") assert sim1.save sim2 = Simulation.new sim2.name ="base" sim2.run_length = 8 sim2.time_units = "hr" assert !sim2.save, sim2.errors.on(:name) assert_equal ActiveRecord::Errors.default_error_messages[:taken],sim2.errors.on(:name) end It fails on the assert_equal line with the following info: 1) Failure: test_unique_name(SimulationTest) [test/unit/simulation_test.rb:61:in `test_unique_name'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/testi ng/setup_and_teardown.rb:33:in `__send__'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/testi ng/setup_and_teardown.rb:33:in `run'']: already taken. <"has already been taken"> expected but was <["has already been taken", "has already been taken"]>. 4 tests, 17 assertions, 1 failures, 0 errors Why are there 2 copies of the "has already been taken" error message? A similar test with a different object works just fine. Thanks, Louise -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jul-09 22:28 UTC
Re: Unit test patterned after AWDR p. 186 doesn''t work as expect
> > Why are there 2 copies of the "has already been taken" error message? A > similar test with a different object works just fine.Random guess: somewhere in your app or in its tests you''ve got a "require ''simulation''" that is loading simulation.rb a second time. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Louise Rains
2008-Jul-09 23:04 UTC
Re: Unit test patterned after AWDR p. 186 doesn''t work as ex
Frederick Cheung wrote:>> >> Why are there 2 copies of the "has already been taken" error message? �A >> similar test with a different object works just fine. > > Random guess: somewhere in your app or in its tests you''ve got a > "require ''simulation''" that is loading simulation.rb a second time. > > FredGood guess, that was exactly the problem. Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---