Showing posts with label rspec. Show all posts
Showing posts with label rspec. Show all posts

Tuesday, 15 January 2013

Testing paperclip with rspec

This post cover the basic testing of paper clip gem in the controller. Since I am new to rspec so I may not be able to cover it in detail with many test cases now but for beginners, I hope its useful.

Suppose you are testing the new function of your controller then the steps will be like this:

  1.  Add a describe in your decorations_controller_rspec.rb.
    Note: Decoration here is the name of my controller, which creates a decoration with a name, year of that decoration and expense.Expense here is an excel sheet which is getting uploaded through paperclip gem.

    describe "#new" do
        it "must take 4 parameter and returns a decoration object" do
         get "new"
            @decorations=Decoration.new(:name=>'decoration',:year=>'2012',:zone_id=>'1',:expense=> File.new(Rails.root + 'spec/fixtures/test.xls'))
           @decorations.should be_an_instance_of Decoration
        end
    end
  2. Create a folder fixtures inside spec directory of your application and add any xls file suppose test.xls. 
  3. Its done. You rspec will pass the test case.