[rspec-users] testing an action which requires picture
nick at deadorange.com
Fri Nov 14 11:53:32 EST 2008
On 2008-11-14, at 06:29, Mano ah wrote:
> can i know how to test a picture upload which dosent interact with db
> my code is
> def scan
> if request.post?
> image = Image.new
> image.blob= params[:image][:blob]
Hi Mano. It doesn't really matter whether or not your "picture" model
interacts with a database. Simply use mocks and stubs when speccing
#scan , and you'll be good. For example:
describe '#scan' do
describe 'receives a POST request' do
before :each do
# mock an Image instance
# stub Image#new
it 'should create a new Image'
it "should set the new image's 'blob' attribute"
it 'should save the new image'
describe 'receives a non-POST request' do
# stuff here
Obviously you have to fill in the contents of those #it blocks, but
that's really all you need.
More information about the rspec-users