[rspec-users] testing an action which requires picture

Mano ah lists at ruby-forum.com
Tue Nov 18 01:53:26 EST 2008


Nick Hoffman wrote:
> On 2008-11-14, at 06:29, Mano ah wrote:
>>      image = Image.new
>>
>>      image.blob= params[:image][:blob]
>>
>>      image.save_picture
>>
>>    end
>> --  
> 
> 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
>      end
> 
>      it 'should create a new Image'
>      it "should set the new image's 'blob' attribute"
>      it 'should save the new image'
>    end
> 
>    describe 'receives a non-POST request' do
>      # stuff here
>    end
> end
> 
> Obviously you have to fill in the contents of those #it blocks, but
> that's really all you need.
> -Nick


Thank you

 All the above specification passed. Now I want to test the return 
value. I mean


def scan
  #-------

    if request.post?

      image = Image.new

      image.blob= params[:image][:blob]

      if image.save_picture

         @code = returns a blog image value
      end

    end


What is the rspec code to test the return value and make it pass
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list