简体   繁体   中英

Mock a Active Record abstract class and how to stub a nil object in rails test::unit/mocha?

i have two question

1.How do i stub a nil object in rails test cases.

2.Mock an Active Record Abstract class

  1. I have a application X with a test database X_test, Now i need to stub an database y_test which doesn't exist and which implements Active Record object and is a abstract class

for example

Y::table.find_by_email("hello@gmail.com").selected_lan["iden"]

      module Y
        class table <Base
          belongs_to:selected_lan, :class =>lan
          def self.find_by_email(iden)
           find_by_email(license_iden)
          end
        end
     end

    module Y
       class Base <ActiveRecord::Base
         self.abstract_class = true
       end
    end
Y::table.expects(:find_by_email).with('some@email.com').returns(nil)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM