[rspec-users] RSpec and acts_as_attachment

David Rice davidjrice at gmail.com
Sat Aug 18 15:22:08 EDT 2007


Hey guys,

I'm getting a weird error when trying to test something like the  
following. It's a model that is using acts_as_attachment but the  
weird thing is the equivalent Test::Unit case passes. Does anyone  
have any ideas?

Best,
Dave

   # it was a Test::Unit case first
   def test_should_be_invalid_without_file
     UserFile.any_instance.expects(:with_image).never
     assert_no_difference UserFile, :count do
     user_file = create_user_file :uploaded_data => nil
       assert user_file.errors.on(:filename)
       assert user_file.errors.on(:size)
       assert user_file.errors.on(:content_type)
     end
   end

   # Converting the above to the following spec
   it 'should be invalid without file' do
     @user_file = create_user_file :uploaded_data => nil
     @user_file.should have(1).error_on(:filename)
     @user_file.should have(1).error_on(:size)
     @user_file.should have(1).error_on(:content_type)
   end

# The spec fails with the following error
# ============

should be invalid without file
wrong number of arguments (0 for 1)
vendor/plugins/acts_as_attachment/lib/technoweenie/acts_as_attachment/ 
instance_methods.rb:154 :in `content_type'
vendor/plugins/acts_as_attachment/lib/technoweenie/acts_as_attachment/ 
instance_methods.rb:154 :in `send'
vendor/plugins/acts_as_attachment/lib/technoweenie/acts_as_attachment/ 
instance_methods.rb:154 :in `attachment_attributes_valid?'
vendor/plugins/acts_as_attachment/lib/technoweenie/acts_as_attachment/ 
instance_methods.rb:152 :in `each'
vendor/plugins/acts_as_attachment/lib/technoweenie/acts_as_attachment/ 
instance_methods.rb:152 :in `attachment_attributes_valid?'
./spec/models/../spec_helper.rb:635 :in `create_user_file'
./spec/models/user_file_spec.rb:11
152          [:size, :content_type].each do |attr_name|
153            enum = attachment_options[attr_name]
154            errors.add attr_name,  
ActiveRecord::Errors.default_error_messages[:inclusion] unless  
enum.nil? || enum.include?(send(attr_name))
155          end
156        end

---
David Rice
http://www.davidjrice.co.uk




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070818/72cee8c1/attachment.html 


More information about the rspec-users mailing list