I don't really care about testing file uploads, but since I have validates_attachment_presence
, etc.. in my model, rspec is complaining.
So now I'm creating my model with these attributes in the spec to try and shut it up:
@attr = {
:name => "value for name",
:title => "value for title",
:content => "value for content",
:pic_file_name => "example.jpg",
:pic_content_type => "image/jpg",
:pic_file_size => "8192",
:pic_updated_at => nil
}
This doesn't work, though.
I found this: http://fr.ivolo.us/posts/mocking-paperclip-with-rspec So I tried something like this:
Post.should_receive(:save_attached_files).and_return(true)
Which doesn't work either. How do I appease RSpec?
To run a single Rspec test file, you can do: rspec spec/models/your_spec. rb to run the tests in the your_spec. rb file.
RSpec is a unit test framework for the Ruby programming language. RSpec is different than traditional xUnit frameworks like JUnit because RSpec is a Behavior driven development tool.
RSpec is a testing tool for Ruby, created for behavior-driven development (BDD). It is the most frequently used testing library for Ruby in production applications. Even though it has a very rich and powerful DSL (domain-specific language), at its core it is a simple tool which you can start using rather quickly.
Setting Up PaperclipTo set up Paperclip, first we need to install the ImageMagick dependency. Paperclip uses ImageMagick to resize images after upload. If you are using another system, you can get download and install instructions from the ImageMagick website. Run bundle install to finish it up.
If the model has_attached_file :pic
, you should be able to just point the pic
attribute at some file and all should be dandy.
Meaning something like @attr = { :pic => File.open(File.join(Rails.root, 'spec', 'fixtures', 'file.png')) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With