require 'pain_in_the_ass'
disclaimer: I might be doing something wrong, hence the experience.
Using Stubs in Rails has been one hell-of-an-experience.
The concept of using mocks/stubs in Rails is very simple (just open a class and add stuff to it). But in practise, this has never been the experience. Whenever I have tried to use mocks, trying to require the original file has been very painful.
For example I have this file called song_search.rb under app/controllers
Tried writing a mock under /test/mock
require File.dirname(__FILE__) + '/../../../app/controllers/song_search'
class SongSearch
def page
end
end
But the tests indicated that this file was not being picked up !! Tried all combinations to get the require right. To no avail. Im sure Im doing something wrong. It cant be that difficult.
Anyways in the end, I just added this to the test class
require 'song_search'
class SongSearch; def page() @page end; end
That worked. But gotto find a better way to do this. :-(
Using Stubs in Rails has been one hell-of-an-experience.
The concept of using mocks/stubs in Rails is very simple (just open a class and add stuff to it). But in practise, this has never been the experience. Whenever I have tried to use mocks, trying to require the original file has been very painful.
For example I have this file called song_search.rb under app/controllers
Tried writing a mock under /test/mock
require File.dirname(__FILE__) + '/../../../app/controllers/song_search'
class SongSearch
def page
end
end
But the tests indicated that this file was not being picked up !! Tried all combinations to get the require right. To no avail. Im sure Im doing something wrong. It cant be that difficult.
Anyways in the end, I just added this to the test class
require 'song_search'
class SongSearch; def page() @page end; end
That worked. But gotto find a better way to do this. :-(
0 Comments:
Post a Comment
<< Home