[rspec-users] How do we test a Rails Model which does not have an equivalent table in the backend using RSpec

Mohnish J. lists at ruby-forum.com
Mon Nov 21 06:28:58 EST 2011


I have a **Moderator** model which basically queries web site related
stat results from other models.

An e.g. of displayed stats could be the total number of users belonging
to a particular area out of many areas in a city. Limiting the number of
such records to a fixed number. For this, the body defined within the
Moderator model makes use of an **Area** model.

Since the queries are not using anything from the same model, but
actually from other models, there wasn't a need for me to have a table
migration wrt this model.

I basically am now trying to test the defined methods in the Moderator
model using Rspec.
What I am basically trying to test is that a call to the method should
return success, this I am doing through:-

    subject.send(:method_name)
    response.should be_success

I'm getting a common error for all such defined methods saying that
`database_name.table_name does not exist`. Well , this is true but how
should is it really making a difference?, and how to get a work around
for this to just test a simple use case of calling a method successfully
in the above context.

Thanks.

-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list