ruby on rails - Testing two different expectations with mocking -


I just added my first rails in 3 apps, and I'm having trouble with controller tests.

I am testing user control class, which is the same model that uses the developer. Therefore, at the beginning of my imagery, I have this:

 Before  (: each) sign_in @user = factory.create (user) end  

now I can test the exam without using jokes or gossip like this:

  Describe "edit GET" "This provides the requested user as user" user = Factory (user :) get: edit: id = & gt; Assigns to User.id (user :). The end of the eql (user)  

But for academic purposes, I would like to know how to work with joke and stirring, generally to be fully straight forward, but It seems that the device is calling User.find before the controller's action, and the test is failing.

  Describe "edit GET" "Provides requested user as a user" user = factory (user: user) Exchange:. Together (: first,: conditions => {: id => 37}). Get Returns (Users): Edit: id = & gt; Assign '37' (user).  end  

Also, by adding twice> to the expected will also fail because first call

Also insight will be appreciated.

You can either stubs or than You can specify several return values ​​with:

  'test / unit' is required 'MOCHA' Class Foo and Class FooTest & lt; Test :: Unit :: Tests # It passes! Return ('c') assert_equal ('a', foo.find ('z')) assert_equal ('b') returns ('b') returns ('a'). , Foo.find ('y')) assert_equal ('c', Foo.find ('x')) end # also passes it! Diff test_multiple_return_with_expects Find Foo.expects () Times (1..3) Return ('A'). Returns ('B'). Return '(' c ')' assert_equal '(' c '),' foo.find '(' z '),' apparently difference ',' assert_equal '(' b ', foo.find (' y ')) assert_equal (' c ' , Foo.find ('x')) end-end  

difference, that is expected to know how often it is being called If you do not specify anything then it considers once and will complain later on the call.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -