In Rails 2.x, using Mocha, I was trying a pretty simple excercise,
mocking an activerecord model, and an association.
I wrote something like this:
test "setting the home_phone works" do
a_phone = mock()
a_card = Card.new(:name => "Joe Winston")
a_card.home_phone = a_phone
assert_equal a_phone, a_card.home_phone
end
Card is specified to has_one :home_phone.
I got the error below the dashed line, which to me says that
ActiveRecord is not recognizing the mocked variable a_phone as a proper
object to add to the association. I did a bunch of digging but could not
figure out how to get the mock to work with Active Record.
Does anyone have a tip, it would be greatly appreciated! (p.s. I
couldn''t find a mocha specific list, which is why I posted here.)
Thanks!
Pito
---------
Exception: Phone(#2156481640) expected, got Mocha::Mock(#2149160840)
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_proxy.rb:262:in
`raise_on_type_mismatch''
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/belongs_to_association.rb:22:in
`replace''
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations.rb:1281:in
`home_phone=''
./test/unit/card_test_with_mock.rb:14:in
`test_setting_the_home_phone_works''
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/testing/setup_and_teardown.rb:62:in
`__send__''
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/testing/setup_and_teardown.rb:62:in
`run''
/opt/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run''
/opt/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each''
/opt/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run''
/opt/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run''
/opt/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each''
/opt/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run''
/opt/local/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in
`run_suite''
/mydev/.metadata/.plugins/org.rubypeople.rdt.testunit/ruby/RemoteTestRunner.rb:117:in
`start_mediator''
/mydev/.metadata/.plugins/org.rubypeople.rdt.testunit/ruby/RemoteTestRunner.rb:62:in
`start''
/mydev/.metadata/.plugins/org.rubypeople.rdt.testunit/ruby/RemoteTestRunner.rb:332
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.